]> iEval git - gruntmaster-data.git/blob - t/tools.t
077185d99944ba06d910baef43ce437ea75cc97d
[gruntmaster-data.git] / t / tools.t
1 #!/usr/bin/perl -w
2 use v5.14;
3
4 use Test::More;
5 use Gruntmaster::App;
6 use Gruntmaster::Data;
7 use App::Cmd::Tester;
8
9 BEGIN {
10 eval {
11 dbinit 'dbi:Pg:dbname=gmtest'; 1;
12 } or plan skip_all => 'Cannot connect to test database. Create it by running make_test_db.sh before running this test. '. "Error: $@";
13 no warnings 'redefine';
14 *Gruntmaster::App::dbinit = sub {}; # Prevent reinit in Gruntmaster::App->run
15 plan tests => 30;
16 }
17
18 sub fakein {
19 open my $fakein, '<', \$_[0];
20 *STDIN = $fakein;
21 }
22
23 sub ta {
24 my ($args, $out, $err) = @_;
25 my $ret = test_app 'Gruntmaster::App' => $args;
26 diag 'Error: ', $ret->error if defined $ret->error;
27 is $ret->output, "$out\n", join ' ', gm => @$args if defined $out;
28 $ret
29 }
30
31 fakein <<EOF;
32 My cool contest
33 MGV
34 2014-01-01 00:00Z
35 2014-01-01 05:00Z
36 EOF
37
38 ta [qw/-c add ct/];
39
40 subtest 'gm -c add ct' => sub {
41 plan tests => 4;
42 my $ct = contest_entry 'ct';
43 is $ct->{name}, 'My cool contest', 'contest name';
44 is $ct->{owner}, 'MGV', 'contest owner';
45 is $ct->{start}, 1388534400, 'contest start';
46 is $ct->{stop}, 1388534400 + 5 * 60 * 60, 'contest stop';
47 };
48
49 {
50 my $out = ta([qw/-c show ct/])->output;
51 like $out, qr/Name: My cool contest/, 'gm -c show ct contains Name'
52 }
53
54 ta [qw/-c get ct owner/], 'MGV';
55 ta [qw/-c set ct owner nobody/];
56 ta [qw/-c get ct owner/], 'nobody';
57 ta [qw/-c list/], join "\n", sort qw/fc rc pc ct/;
58 ta [qw/-c rm ct/];
59 ok !defined contest_entry('ct'), 'gm -c rm ct';
60
61 fakein <<EOF;
62 Test problem
63 y
64 pc
65 Marius Gavrilescu
66 Smaranda Ciubotaru
67 MGV
68 b
69 gm
70 c
71 a
72 a
73 3
74 1
75 100
76 Ok
77 Ok
78 Ok
79 EOF
80
81 ta [qw/-p add pb/];
82
83 {
84 my $out = ta([qw/-p show pb/])->output;
85 like $out, qr/Value \(points\): 250/, 'gm -p show pb contains Value'
86 }
87
88 subtest 'gruntmaster-problem add' => sub {
89 plan tests => 10;
90 my $pb = problem_entry 'pb';
91 ok $pb, 'problem exists';
92 is $pb->{name}, 'Test problem', 'name';
93 ok $pb->{private}, 'private';
94 is $pb->{author}, 'Marius Gavrilescu', 'author';
95 is $pb->{writer}, 'Smaranda Ciubotaru', 'statement writer';
96 is $pb->{owner}, 'MGV', 'owner';
97 is $pb->{level}, 'easy', 'level';
98 is $pb->{timeout}, 1, 'time limit';
99 is $pb->{olimit}, 100, 'output limit';
100 ok contest_has_problem('ct', 'pb'), 'is in contest';
101 };
102
103 ta [qw/-p get pb author/], 'Marius Gavrilescu';
104 ta [qw/-p set pb owner nobody/];
105 ta [qw/-p get pb owner/], 'nobody';
106 ta [qw/-p set --file pb statement README/];
107 like problem_entry('pb')->{statement}, qr/Gruntmaster-Data/, 'gm -p set --file pb statement README';
108 ta [qw/-p list/], join "\n", sort qw/arc pca rca fca prv pb/;
109 ta [qw/-p rm pb/];
110 ok !defined problem_entry ('pb'), 'gm -p rm pb';
111
112 my $id = create_job extension => '.cpp', format => 'CPP', problem => 'arc', source => '...', owner => 'MGV';
113 ok abs (time - user_entry('MGV')->{lastjob}) < 2, 'create_job - lastjob looks sane';
114 ta [rerun => $id];
115 is job_entry($id)->{result}, -2, "gm rerun $id";
116 ta [qw/rm -j/, $id];
117
118 ta [rerun => 'fca'];
119 my @fca_jobs = grep { $_->{problem} eq 'fca' } @{job_list()};
120 ok ((!grep { $_->{result} != -2 } @fca_jobs), "gm rerun fca");
121
122 sub terr {
123 my ($args, $err) = @_;
124 my $ret = test_app 'Gruntmaster::App' => $args;
125 like $ret->error, qr/$err/, join ' ', 'invalid:', gm => @$args;
126 $ret
127 }
128
129 terr [qw/add/], 'No table selected';
130 terr [qw/-j add/], 'Don\'t know how to add to this table';
131 terr [qw/-c add/], 'Wrong number of arguments';
132 terr [qw/get/], 'No table selected';
133 terr [qw/-c get/], 'Wrong number of arguments';
134 terr [qw/list/], 'No table selected';
135 terr [qw/-j rerun/], 'Not enough arguments';
136 terr [qw/rm/], 'No table selected';
137 terr [qw/-j rm/], 'Wrong number of arguments';
138 terr [qw/set/], 'No table selected';
139 terr [qw/-j set 1 owner/], 'Not enough arguments';
140 terr [qw/-j set 1 owner x name/], 'The number of arguments must be odd';
141 terr [qw/show/], 'No table selected';
142 terr [qw/-c show/], 'Wrong number of arguments';
This page took 0.055423 seconds and 4 git commands to generate.