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