Add tests
[gruntmaster-data.git] / t / tools.t
CommitLineData
acb202c6
MG
1#!/usr/bin/perl -w
2use v5.14;
3
4use Test::More tests => 13;
5use File::Temp qw/tempdir/;
6
7use Gruntmaster::Data;
8
9my $dir = tempdir CLEANUP => 1;
10$ENV{GRUNTMASTER_DSN} = "dbi:SQLite:dbname=$dir/testdb";
11
12our $db;
13
14sub withdb (&) {
15 local $db = Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN});
16 shift->()
17}
18
19withdb { $db->deploy };
20
21my $pipe;
22
23open $pipe, '|./gruntmaster-contest add ct';
24print $pipe <<'';
25My cool contest
26MGV
272014-01-01 00:00Z
282014-01-01 05:00Z
29
30close $pipe;
31
32withdb {
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
44is `./gruntmaster-contest get ct owner`, "MGV\n", 'gruntmaster-contest get';
45system './gruntmaster-contest', 'set', 'ct', 'owner', 'nobody';
46withdb { is $db->contest('ct')->owner->id, 'nobody', 'gruntmaster-contest set' };
47
48withdb { $db->contests->create({id => 'dummy', name => 'Dummy contest', owner => 'MGV', start => 0, stop => 1}) };
49my @list = sort `./gruntmaster-contest list`;
50chomp @list;
51my @list2 = withdb { map { $_->id } $db->contests->all };
52is_deeply \@list, [ sort @list2 ], 'gruntmaster-contest list';
53
54system './gruntmaster-contest', 'rm', 'dummy';
55withdb { ok !$db->contest('dummy'), 'gruntmaster-contest rm' };
56
57open $pipe, '|./gruntmaster-problem add pb';
58print $pipe <<'';
59Test problem
60n
61ct
62Marius Gavrilescu
63Smaranda Ciubotaru
64MGV
65b
66gruntmaster-problem
67c
68a
69a
703
711
72100
73Ok
74Ok
75Ok
76
77close $pipe;
78
79withdb {
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
99is `./gruntmaster-problem get pb author`, "Marius Gavrilescu\n", 'gruntmaster-problem get';
100system './gruntmaster-problem set pb owner nobody';
101withdb { is $db->problem('pb')->owner->id, 'nobody', 'gruntmaster-problem set' };
102
103withdb { $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`;
106chomp @list;
107@list2 = withdb { map { $_->id } $db->problems->all };
108is_deeply \@list, [ sort @list2 ], 'gruntmaster-problem list';
109
110system './gruntmaster-problem', 'rm', 'dummy';
111withdb { ok !$db->problem('dummy'), 'gruntmaster-problem rm' };
112
113withdb { $db->jobs->create({id => 1, date => 1, extension => '.ext', format => 'CPP', problem => 'pb', source => '...', owner => 'MGV'}) };
114
115is `./gruntmaster-job get 1 format`, "CPP\n", 'gruntmaster-job get';
116system './gruntmaster-job', 'set', 1, 'format', 'PERL';
117withdb { is $db->job(1)->format, 'PERL', 'gruntmaster-job set' };
118
119system './gruntmaster-job', 'rm', 1;
120withdb { ok !$db->job(1), 'gruntmaster-job rm' };
This page took 0.014903 seconds and 4 git commands to generate.