File: outputs_with_time.t

package info (click to toggle)
libtap-harness-junit-perl 0.42-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 856 kB
  • sloc: xml: 10,187; perl: 413; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,404 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl

use TAP::Harness::JUnit;
use Test::More;
use XML::Simple;
use Test::Deep;
use File::Temp;
use File::Basename;
use Encode;

my %tests = (
	resultcode  => 'Successful test with good plan and a bad return code',
	badplan     => 'Has a plan, successful tests, just too small amount of them',
	funkyindent => 'Indentation of comments',
	uniquename  => 'Multiple tests with identical names',
	nonutf8log  => 'Special characters in log',
	earlyterm   => 'Bad plan and non-zero return value',
	empty       => 'Zero-length output',
	skips       => 'Tests with skips',
);

plan tests => int (keys %tests);

my $our_cat  = [$^X, qw/-ne print/];

foreach my $test (keys %tests) {
	my $model = dirname($0)."/tests/$test.xml";
	my $outfile = File::Temp->new (UNLINK => 1)->filename;

	$harness = new TAP::Harness::JUnit ({
		xmlfile     => $outfile,
		verbosity   => -1,
		merge       => 1,
		exec        => $our_cat,
	});

	$harness->runtests ([dirname($0)."/tests/$test.txt" => $tests{$test}]);

	my $expected = XMLin ($model);
	my $testcase = $expected->{testsuite}{testcase};

	# Each time key must be replaced with a regex match
	foreach my $test (
		$expected->{testsuite}, $testcase,
		map { $testcase->{$_} } keys %$testcase
	) {
		next unless defined $test->{'time'};
		$test->{'time'} = re ('^\d+(:?\.\d+)?');
	}

	cmp_deeply(XMLin ($outfile), $expected, "Output of $test matches model");
}