]>
Commit | Line | Data |
---|---|---|
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 | plan tests => 30; | |
14 | } | |
15 | ||
16 | sub fakein { | |
17 | open my $fakein, '<', \$_[0]; | |
18 | *STDIN = $fakein; | |
19 | } | |
20 | ||
21 | sub ta { | |
22 | my ($args, $out, $err) = @_; | |
23 | my $ret = test_app 'Gruntmaster::App' => $args; | |
24 | diag 'Error: ', $ret->error if defined $ret->error; | |
25 | is $ret->output, "$out\n", join ' ', gm => @$args if defined $out; | |
26 | $ret | |
27 | } | |
28 | ||
29 | fakein <<EOF; | |
30 | My cool contest | |
31 | MGV | |
32 | 2014-01-01 00:00Z | |
33 | 2014-01-01 05:00Z | |
34 | EOF | |
35 | ||
36 | ta [qw/-c add ct/]; | |
37 | ||
38 | subtest 'gm -c add ct' => sub { | |
39 | plan tests => 4; | |
40 | my $ct = contest_entry 'ct'; | |
41 | is $ct->{name}, 'My cool contest', 'contest name'; | |
42 | is $ct->{owner}, 'MGV', 'contest owner'; | |
43 | is $ct->{start}, 1388534400, 'contest start'; | |
44 | is $ct->{stop}, 1388534400 + 5 * 60 * 60, 'contest stop'; | |
45 | }; | |
46 | ||
47 | { | |
48 | my $out = ta([qw/-c show ct/])->output; | |
49 | like $out, qr/Name: My cool contest/, 'gm -c show ct contains Name' | |
50 | } | |
51 | ||
52 | ta [qw/-c get ct owner/], 'MGV'; | |
53 | ta [qw/-c set ct owner nobody/]; | |
54 | ta [qw/-c get ct owner/], 'nobody'; | |
55 | ta [qw/-c list/], join "\n", sort qw/fc rc pc ct/; | |
56 | ta [qw/-c rm ct/]; | |
57 | ok !defined contest_entry('ct'), 'gm -c rm ct'; | |
58 | ||
59 | fakein <<EOF; | |
60 | Test problem | |
61 | y | |
62 | pc | |
63 | Marius Gavrilescu | |
64 | Smaranda Ciubotaru | |
65 | MGV | |
66 | b | |
67 | gm | |
68 | c | |
69 | a | |
70 | a | |
71 | 3 | |
72 | 1 | |
73 | 100 | |
74 | Ok | |
75 | Ok | |
76 | Ok | |
77 | EOF | |
78 | ||
79 | ta [qw/-p add pb/]; | |
80 | ||
81 | { | |
82 | my $out = ta([qw/-p show pb/])->output; | |
83 | like $out, qr/Value \(points\): 250/, 'gm -p show pb contains Value' | |
84 | } | |
85 | ||
86 | subtest 'gruntmaster-problem add' => sub { | |
87 | plan tests => 10; | |
88 | my $pb = problem_entry 'pb'; | |
89 | ok $pb, 'problem exists'; | |
90 | is $pb->{name}, 'Test problem', 'name'; | |
91 | ok $pb->{private}, 'private'; | |
92 | is $pb->{author}, 'Marius Gavrilescu', 'author'; | |
93 | is $pb->{writer}, 'Smaranda Ciubotaru', 'statement writer'; | |
94 | is $pb->{owner}, 'MGV', 'owner'; | |
95 | is $pb->{level}, 'easy', 'level'; | |
96 | is $pb->{timeout}, 1, 'time limit'; | |
97 | is $pb->{olimit}, 100, 'output limit'; | |
98 | ok contest_has_problem('ct', 'pb'), 'is in contest'; | |
99 | }; | |
100 | ||
101 | ta [qw/-p get pb author/], 'Marius Gavrilescu'; | |
102 | ta [qw/-p set pb owner nobody/]; | |
103 | ta [qw/-p get pb owner/], 'nobody'; | |
104 | ta [qw/-p set --file pb statement README/]; | |
105 | like problem_entry('pb')->{statement}, qr/Gruntmaster-Data/, 'gm -p set --file pb statement README'; | |
106 | ta [qw/-p list/], join "\n", sort qw/arc pca rca fca prv pb/; | |
107 | ta [qw/-p rm pb/]; | |
108 | ok !defined problem_entry ('pb'), 'gm -p rm pb'; | |
109 | ||
110 | my $id = create_job extension => '.cpp', format => 'CPP', problem => 'arc', source => '...', owner => 'MGV'; | |
111 | ok abs (time - user_entry('MGV')->{lastjob}) < 2, 'create_job - lastjob looks sane'; | |
112 | ta [rerun => $id]; | |
113 | is job_entry($id)->{result}, -2, "gm rerun $id"; | |
114 | ta [qw/rm -j/, $id]; | |
115 | ||
116 | sub terr { | |
117 | my ($args, $err) = @_; | |
118 | my $ret = test_app 'Gruntmaster::App' => $args; | |
119 | like $ret->error, qr/$err/, join ' ', 'invalid:', gm => @$args; | |
120 | $ret | |
121 | } | |
122 | ||
123 | terr [qw/add/], 'No table selected'; | |
124 | terr [qw/-j add/], 'Don\'t know how to add to this table'; | |
125 | terr [qw/-c add/], 'Wrong number of arguments'; | |
126 | terr [qw/get/], 'No table selected'; | |
127 | terr [qw/-c get/], 'Wrong number of arguments'; | |
128 | terr [qw/list/], 'No table selected'; | |
129 | terr [qw/-p rerun/], 'This command only works on jobs'; | |
130 | terr [qw/-j rerun/], 'Wrong number of arguments'; | |
131 | terr [qw/rm/], 'No table selected'; | |
132 | terr [qw/-j rm/], 'Wrong number of arguments'; | |
133 | terr [qw/set/], 'No table selected'; | |
134 | terr [qw/-j set 1 owner/], 'Not enough arguments'; | |
135 | terr [qw/-j set 1 owner x name/], 'The number of arguments must be odd'; | |
136 | terr [qw/show/], 'No table selected'; | |
137 | terr [qw/-c show/], 'Wrong number of arguments'; |