2735593b2c97a793edf2bb010c712dcb8d95fdc8
[gruntmaster-data.git] / t / tools.t
1 #!/usr/bin/perl -w
2 use v5.14;
3
4 use Test::More tests => 13;
5 use File::Temp qw/tempdir/;
6
7 use Gruntmaster::Data;
8
9 my $dir = tempdir CLEANUP => 1;
10 $ENV{GRUNTMASTER_DSN} = "dbi:SQLite:dbname=$dir/testdb";
11
12 our $db;
13
14 sub withdb (&) {
15 local $db = Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN});
16 shift->()
17 }
18
19 withdb { $db->deploy };
20
21 my $pipe;
22
23 open $pipe, '|./gruntmaster-contest add ct';
24 print $pipe <<'';
25 My cool contest
26 MGV
27 2014-01-01 00:00Z
28 2014-01-01 05:00Z
29
30 close $pipe;
31
32 withdb {
33 subtest 'gruntmaster-contest add' => sub {
34 plan tests => 5;
35 my $ct = $db->contest('ct');
36 ok $ct, 'contest exists';
37 is $ct->name, 'My cool contest', 'contest name';
38 is $ct->owner->id, 'MGV', 'contest owner';
39 is $ct->start, 1388534400, 'contest start';
40 is $ct->stop, 1388534400 + 5 * 60 * 60, 'contest stop';
41 }
42 };
43
44 is `./gruntmaster-contest get ct owner`, "MGV\n", 'gruntmaster-contest get';
45 system './gruntmaster-contest', 'set', 'ct', 'owner', 'nobody';
46 withdb { is $db->contest('ct')->owner->id, 'nobody', 'gruntmaster-contest set' };
47
48 withdb { $db->contests->create({id => 'dummy', name => 'Dummy contest', owner => 'MGV', start => 0, stop => 1}) };
49 my @list = sort `./gruntmaster-contest list`;
50 chomp @list;
51 my @list2 = withdb { map { $_->id } $db->contests->all };
52 is_deeply \@list, [ sort @list2 ], 'gruntmaster-contest list';
53
54 system './gruntmaster-contest', 'rm', 'dummy';
55 withdb { ok !$db->contest('dummy'), 'gruntmaster-contest rm' };
56
57 open $pipe, '|./gruntmaster-problem add pb';
58 print $pipe <<'';
59 Test problem
60 n
61 ct
62 Marius Gavrilescu
63 Smaranda Ciubotaru
64 MGV
65 b
66 gruntmaster-problem
67 c
68 a
69 a
70 3
71 1
72 100
73 Ok
74 Ok
75 Ok
76
77 close $pipe;
78
79 withdb {
80 subtest 'gruntmaster-problem add' => sub {
81 plan tests => 13;
82 my $pb = $db->problem('pb');
83 ok $pb, 'problem exists';
84 is $pb->name, 'Test problem', 'name';
85 is $pb->author, 'Marius Gavrilescu', 'author';
86 is $pb->writer, 'Smaranda Ciubotaru', 'statement writer';
87 is $pb->owner->id, 'MGV', 'owner';
88 is $pb->level, 'easy', 'level';
89 is $pb->generator, 'Undef', 'generator';
90 is $pb->runner, 'File', 'runner';
91 is $pb->judge, 'Absolute', 'judge';
92 is $pb->testcnt, 3, 'test count';
93 is $pb->timeout, 1, 'time limit';
94 is $pb->olimit, 100, 'output limit';
95 ok $db->contest_problems->find('ct', 'pb'), 'is in contest';
96 }
97 };
98
99 is `./gruntmaster-problem get pb author`, "Marius Gavrilescu\n", 'gruntmaster-problem get';
100 system './gruntmaster-problem set pb owner nobody';
101 withdb { is $db->problem('pb')->owner->id, 'nobody', 'gruntmaster-problem set' };
102
103 withdb { $db->problems->create({id => 'dummy', name => 'Dummy', generator => 'Undef', runner => 'File', judge => 'Absolute', level => 'beginner', owner => 'MGV', statement => '...', testcnt => 1, timeout => 1}) };
104
105 @list = sort `./gruntmaster-problem list`;
106 chomp @list;
107 @list2 = withdb { map { $_->id } $db->problems->all };
108 is_deeply \@list, [ sort @list2 ], 'gruntmaster-problem list';
109
110 system './gruntmaster-problem', 'rm', 'dummy';
111 withdb { ok !$db->problem('dummy'), 'gruntmaster-problem rm' };
112
113 withdb { $db->jobs->create({id => 1, date => 1, extension => '.ext', format => 'CPP', problem => 'pb', source => '...', owner => 'MGV'}) };
114
115 is `./gruntmaster-job get 1 format`, "CPP\n", 'gruntmaster-job get';
116 system './gruntmaster-job', 'set', 1, 'format', 'PERL';
117 withdb { is $db->job(1)->format, 'PERL', 'gruntmaster-job set' };
118
119 system './gruntmaster-job', 'rm', 1;
120 withdb { ok !$db->job(1), 'gruntmaster-job rm' };
This page took 0.032935 seconds and 3 git commands to generate.