]> iEval git - gruntmaster-data.git/blame_incremental - tools.t
Bump version and update Changes
[gruntmaster-data.git] / tools.t
... / ...
CommitLineData
1#!/usr/bin/perl -w
2use v5.14;
3
4use Test::More;
5use Gruntmaster::App;
6use Gruntmaster::Data;
7use App::Cmd::Tester;
8
9BEGIN {
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
16sub fakein {
17 open my $fakein, '<', \$_[0];
18 *STDIN = $fakein;
19}
20
21sub 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
29fakein <<EOF;
30My cool contest
31MGV
322014-01-01 00:00Z
332014-01-01 05:00Z
34EOF
35
36ta [qw/-c add ct/];
37
38subtest '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
52ta [qw/-c get ct owner/], 'MGV';
53ta [qw/-c set ct owner nobody/];
54ta [qw/-c get ct owner/], 'nobody';
55ta [qw/-c list/], join "\n", sort qw/fc rc pc ct/;
56ta [qw/-c rm ct/];
57ok !defined contest_entry('ct'), 'gm -c rm ct';
58
59fakein <<EOF;
60Test problem
61y
62pc
63Marius Gavrilescu
64Smaranda Ciubotaru
65MGV
66b
67gm
68c
69a
70a
713
721
73100
74Ok
75Ok
76Ok
77EOF
78
79ta [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
86subtest '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
101ta [qw/-p get pb author/], 'Marius Gavrilescu';
102ta [qw/-p set pb owner nobody/];
103ta [qw/-p get pb owner/], 'nobody';
104ta [qw/-p set --file pb statement README/];
105like problem_entry('pb')->{statement}, qr/Gruntmaster-Data/, 'gm -p set --file pb statement README';
106ta [qw/-p list/], join "\n", sort qw/arc pca rca fca prv pb/;
107ta [qw/-p rm pb/];
108ok !defined problem_entry ('pb'), 'gm -p rm pb';
109
110my $id = create_job extension => '.cpp', format => 'CPP', problem => 'arc', source => '...', owner => 'MGV';
111ok abs (time - user_entry('MGV')->{lastjob}) < 2, 'create_job - lastjob looks sane';
112ta [rerun => $id];
113is job_entry($id)->{result}, -2, "gm rerun $id";
114ta [qw/rm -j/, $id];
115
116sub 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
123terr [qw/add/], 'No table selected';
124terr [qw/-j add/], 'Don\'t know how to add to this table';
125terr [qw/-c add/], 'Wrong number of arguments';
126terr [qw/get/], 'No table selected';
127terr [qw/-c get/], 'Wrong number of arguments';
128terr [qw/list/], 'No table selected';
129terr [qw/-p rerun/], 'This command only works on jobs';
130terr [qw/-j rerun/], 'Wrong number of arguments';
131terr [qw/rm/], 'No table selected';
132terr [qw/-j rm/], 'Wrong number of arguments';
133terr [qw/set/], 'No table selected';
134terr [qw/-j set 1 owner/], 'Not enough arguments';
135terr [qw/-j set 1 owner x name/], 'The number of arguments must be odd';
136terr [qw/show/], 'No table selected';
137terr [qw/-c show/], 'Wrong number of arguments';
This page took 0.023773 seconds and 5 git commands to generate.