5 use Gruntmaster::Daemon;
8 use File::Basename qw/fileparse/;
9 use File::Slurp qw/read_file/;
10 use File::Temp qw/tempdir/;
11 use File::Which qw/which/;
13 use Hash::Merge qw/merge/;
14 use List::Util qw/sum/;
17 use YAML::Tiny qw/LoadFile/;
19 ##################################################
21 use constant COMPILER => {
44 my %needs_fork = map { $_ => 1 } qw/GOLANG GOLFSCRIPT GCCGO JAVA JAVASCRIPT JULIA RUBY SBCL/;
46 my $loglevel = $ENV{TEST_LOG_LEVEL} // ($ENV{TEST_VERBOSE} ? 'TRACE' : 'OFF');
47 my $log_conf = <<CONF;
48 log4perl.category.Gruntmaster.Daemon = $loglevel, stderr
50 log4perl.appender.stderr = Log::Log4perl::Appender::Screen
51 log4perl.appender.stderr.layout = Log::Log4perl::Layout::PatternLayout
52 log4perl.appender.stderr.layout.ConversionPattern = [\%d] [\%F{1}:\%M{1}:\%L] [\%p] \%m\%n
54 Log::Log4perl->init(\$log_conf);
56 $ENV{PATH} = getcwd . ':' . $ENV{PATH};
57 $ENV{PATH} = "$FindBin::Bin/../blib/script:" . $ENV{PATH};
62 if (defined $meta->{results}) {
63 delete $meta->{results}[$_]{time} for keys @{$meta->{results}};
65 my $desc = $meta->{name} . ': ' . $meta->{test_name};
66 is $meta->{result}, $meta->{expected_result}, "Result is correct ($desc)";
67 is $meta->{result_text}, $meta->{expected_result_text}, "Result text is correct ($desc)";
68 is_deeply $meta->{results}, $meta->{expected_results}, "Results are correct ($desc)";
71 my @problems = exists $ENV{TEST_PROBLEMS} ? map {"t/problems/$_"} split ' ', $ENV{TEST_PROBLEMS} : <t/problems/*>;
72 @problems = grep { $_ !~ /hello/ } @problems unless $ENV{RELEASE_TESTING} || $ENV{TEST_PROBLEMS};
74 plan tests => 3 * sum map { my @temp = <$_/tests/*>; scalar @temp } @problems;
75 note "Problems to be tested: " . join ', ', @problems;
77 my $tempdir = tempdir "gruntmasterd-testingXXXX", TMPDIR => 1, CLEANUP => 1;
82 for my $problem (@problems) {
83 my $pbmeta = LoadFile "$problem/meta.yml";
84 for (1 .. $pbmeta->{testcnt}) {
85 $pbmeta->{infile}[$_ - 1] = read_file "$problem/$_.in" if $pbmeta->{generator} eq 'File';
86 $pbmeta->{okfile}[$_ - 1] = read_file "$problem/$_.ok" if $pbmeta->{runner} && $pbmeta->{runner} eq 'File';
88 if (exists $pbmeta->{files}) {
89 $_->{content} = read_file "$problem/$_->{name}" for values %{$pbmeta->{files}}
93 note "Now testing problem $pbmeta->{name} ($pbmeta->{description})";
95 for my $source (<$problem/tests/*>) {
97 my $meta = LoadFile "$source/meta.yml";
98 if ($meta->{files}{prog}) {
99 my $format = $meta->{files}{prog}{format};
100 my $compiler = COMPILER->{$format};
101 # skip "$compiler not found in path", 3 unless $ENV{GRUNTMASTER_VM} || which $compiler;
102 # skip "$format requires multiple processes. Set GRUNTMASTER_KILL_USER and GRUNTMASTER_SUDO to allow multiple processes.", 3 if !$ENV{GRUNTMASTER_KILL_USER} && $needs_fork{$format};
103 $meta->{files}{prog}{content} = read_file "$source/$meta->{files}{prog}{name}";
105 $meta = merge $meta, $pbmeta;
106 local $TODO = $meta->{todo} if exists $meta->{todo};
107 note "Running $meta->{test_name} ($meta->{test_description})...";
108 my $savedcwd = getcwd;
110 Gruntmaster::Daemon::process $meta;