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