| 4762 |
rpuchmay |
1 |
#!/usr/bin/env perl -w
|
|
|
2 |
|
|
|
3 |
use diagnostics;
|
|
|
4 |
use warnings;
|
|
|
5 |
use strict;
|
|
|
6 |
use Switch;
|
|
|
7 |
|
|
|
8 |
use Test::More;
|
|
|
9 |
use File::Path;
|
|
|
10 |
|
|
|
11 |
use FindBin;
|
| 4785 |
rpuchmay |
12 |
use lib "$FindBin::Bin/../Lib";
|
| 4762 |
rpuchmay |
13 |
|
| 4799 |
rpuchmay |
14 |
plan( tests => 1474 );
|
| 4762 |
rpuchmay |
15 |
# Using require as the file to be tested is not a module
|
|
|
16 |
# Imports all subroutines into the current namespace
|
| 4786 |
rpuchmay |
17 |
require_ok('UtfFilter_ant');
|
| 4762 |
rpuchmay |
18 |
|
| 4799 |
rpuchmay |
19 |
ok (UtfFilter_ant::containsClosingTag("/>"), "Detected default closing tag");
|
|
|
20 |
ok (UtfFilter_ant::containsClosingTag("</testcase>"), "Detected closing tag");
|
| 4768 |
rpuchmay |
21 |
|
| 4799 |
rpuchmay |
22 |
my @filename = UtfFilter_ant::findAntResultsFile();
|
|
|
23 |
my $ant_results_file1 = File::Spec->rel2abs("$FindBin::Bin/Test-one.xml");
|
|
|
24 |
my $ant_results_file0 = File::Spec->rel2abs("$FindBin::Bin/TEST-com.erggroup.buildtool.utf.AllTests.xml");
|
|
|
25 |
is( $#filename, 1, "Correct number of files found");
|
|
|
26 |
# Sorted in alphabetical order
|
|
|
27 |
is( $filename[0], $ant_results_file0, "First file is correct");
|
|
|
28 |
is( $filename[1], $ant_results_file1, "Second file is correct");
|
| 4762 |
rpuchmay |
29 |
|
|
|
30 |
$ENV{GBE_RM_LOCATION}='jdbc:oracle:thin:@auperaprm01:1521:RELEASEM';
|
|
|
31 |
$ENV{GBE_RM_USERNAME}='RM_READONLY';
|
|
|
32 |
$ENV{GBE_RM_PASSWORD}='RM_READONLY';
|
|
|
33 |
|
| 4799 |
rpuchmay |
34 |
my ($name, $duration, $outcome) = UtfFilter_ant::getDetails('<testcase classname="junit.framework.JUnit4TestCaseFacade" name="unknown" time="0.01"></testcase>');
|
| 4762 |
rpuchmay |
35 |
is($name, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
36 |
is($duration, 0.01, 'Test duration is ok');
|
|
|
37 |
is($outcome, 'PASS', 'Test passed');
|
|
|
38 |
|
| 4799 |
rpuchmay |
39 |
($name, $duration, $outcome) = UtfFilter_ant::getDetails('<testcase classname="junit.framework.JUnit4TestCaseFacade" name="unknown" time="0.01">');
|
| 4762 |
rpuchmay |
40 |
is($name, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
41 |
is($duration, 0.01, 'Test duration is ok');
|
|
|
42 |
ok(!defined($outcome), 'Test outcome unknown');
|
|
|
43 |
|
|
|
44 |
my $message;
|
| 4799 |
rpuchmay |
45 |
($message) = UtfFilter_ant::parseMessage( qw/error/,
|
| 4762 |
rpuchmay |
46 |
'<error message="Unexpected exception, expected<com.erggroup.sls.card.InvalidDateRangeException> but was<java.lang.NullPointerException>" type="java.lang.Exception">My error message',
|
|
|
47 |
( 'My second line', 'My third line', '</error>' ));
|
|
|
48 |
|
|
|
49 |
is($message, 'My error messageMy second lineMy third line', 'Message correct');
|
|
|
50 |
|
| 4799 |
rpuchmay |
51 |
($message) = UtfFilter_ant::parseMessage( qw/failure/,
|
| 4762 |
rpuchmay |
52 |
'<failure message="Unexpected exception, expected<com.erggroup.sls.card.InvalidDateRangeException> but was<java.lang.NullPointerException>" type="java.lang.Exception">My error message',
|
|
|
53 |
( 'My second line', 'My third line', '</failure>' ));
|
|
|
54 |
|
|
|
55 |
is($message, 'My error messageMy second lineMy third line', 'Message correct');
|
|
|
56 |
|
|
|
57 |
my %test;
|
| 4799 |
rpuchmay |
58 |
%test = UtfFilter_ant::parseTestCase('qwerty', (
|
| 4762 |
rpuchmay |
59 |
'<testcase classname="junit.framework.JUnit4TestCaseFacade" name="unknown" time="0.01"></testcase>'
|
|
|
60 |
));
|
|
|
61 |
|
|
|
62 |
is($test{NAME}, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
63 |
is($test{DURATION}, 0.01, 'Test duration is ok');
|
|
|
64 |
is($test{OUTCOME}, 'PASS', 'Test passed');
|
| 4768 |
rpuchmay |
65 |
ok(!defined($test{MESSAGE}), 'Message undefined');
|
| 4799 |
rpuchmay |
66 |
is($test{TARGET_PLATFORM}, 'qwerty', 'Correct target for qwerty');
|
| 4762 |
rpuchmay |
67 |
|
| 4799 |
rpuchmay |
68 |
%test = UtfFilter_ant::parseTestCase('wertyu', (
|
| 4762 |
rpuchmay |
69 |
'<testcase classname="junit.framework.JUnit4TestCaseFacade" name="unknown" time="0.01">',
|
|
|
70 |
'<error message="Unexpected exception, expected<com.erggroup.sls.card.InvalidDateRangeException> but was<java.lang.NullPointerException>" type="java.lang.Exception">My error message',
|
|
|
71 |
'</error>',
|
|
|
72 |
'</testcase>'
|
|
|
73 |
));
|
|
|
74 |
|
|
|
75 |
is($test{NAME}, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
76 |
is($test{DURATION}, 0.01, 'Test duration is ok');
|
|
|
77 |
is($test{OUTCOME}, 'ERROR', 'Test errored');
|
|
|
78 |
is($test{MESSAGE}, 'My error message', 'Message correct');
|
| 4799 |
rpuchmay |
79 |
is($test{TARGET_PLATFORM}, 'wertyu', 'Correct target for wertyu');
|
| 4762 |
rpuchmay |
80 |
|
| 4799 |
rpuchmay |
81 |
%test = UtfFilter_ant::parseTestCase('ertyu', (
|
| 4762 |
rpuchmay |
82 |
'<testcase classname="junit.framework.JUnit4TestCaseFacade" name="unknown" time="0.01">',
|
|
|
83 |
'<failure message="Unexpected exception, expected<com.erggroup.sls.card.InvalidDateRangeException> but was<java.lang.NullPointerException>" type="java.lang.Exception">My error message',
|
|
|
84 |
'</failure>',
|
|
|
85 |
'</testcase>'
|
|
|
86 |
));
|
|
|
87 |
|
|
|
88 |
is($test{NAME}, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
89 |
is($test{DURATION}, 0.01, 'Test duration is ok');
|
|
|
90 |
is($test{OUTCOME}, 'FAILURE', 'Test failed');
|
|
|
91 |
is($test{MESSAGE}, 'My error message', 'Message correct');
|
| 4799 |
rpuchmay |
92 |
is($test{TARGET_PLATFORM}, 'ertyu', 'Correct target for ertyu');
|
| 4762 |
rpuchmay |
93 |
|
| 4799 |
rpuchmay |
94 |
my ($passed, @instance) = UtfFilter_ant::createBuildInstance('dummyTarget');
|
| 4768 |
rpuchmay |
95 |
is ($passed, 0, "Some tests failed at ".__LINE__);
|
| 4799 |
rpuchmay |
96 |
is (@instance, 248, "Has correct number of results") || BAIL_OUT('Incorrect number of tests');
|
| 4762 |
rpuchmay |
97 |
|
|
|
98 |
rmtree('reports') if -d 'reports';
|
| 4768 |
rpuchmay |
99 |
ok(! -d 'reports', "Deleted reports folder");
|
| 4762 |
rpuchmay |
100 |
mkdir 'reports' if ! -d 'reports';
|
| 4768 |
rpuchmay |
101 |
ok(-d 'reports', "Created reports folder");
|
|
|
102 |
my $out_filename = "reports/Win32-1.xml";
|
| 4799 |
rpuchmay |
103 |
UtfFilter_ant::outputJatsXmlFile($out_filename, @instance);
|
| 4762 |
rpuchmay |
104 |
ok(-e $out_filename, "File exists");
|
| 4799 |
rpuchmay |
105 |
is(-s $out_filename, 52430, "File is correct size"); # this is very brittle
|
| 4762 |
rpuchmay |
106 |
|
| 4784 |
rpuchmay |
107 |
my %params = ( OUTDIR => 'reports', OUTFILE => 'filename', TARGET => 'Ubuntu12' );
|
| 4805 |
dpurdie |
108 |
$passed = UtfFilter_ant->processUtf(\%params);
|
| 4768 |
rpuchmay |
109 |
is ($passed, 0, "Some tests failed at ".__LINE__);
|
| 4762 |
rpuchmay |
110 |
|
|
|
111 |
my @test_results;
|
| 4799 |
rpuchmay |
112 |
($passed, @test_results) = UtfFilter_ant::parseTestRun('dummy2Target', ($ant_results_file1, $ant_results_file0));
|
| 4762 |
rpuchmay |
113 |
is($passed, 0, "Some tests failed");
|
|
|
114 |
|
| 4799 |
rpuchmay |
115 |
is (@test_results, 248, 'Found results') || BAIL_OUT('Incorrect number of tests');
|
| 4762 |
rpuchmay |
116 |
|
|
|
117 |
SKIP: {
|
|
|
118 |
skip "Don't want output if failed", 1176 if anyTestsFailed();
|
|
|
119 |
my $count = 0;
|
|
|
120 |
# $test is a ref to a hash
|
|
|
121 |
foreach my $test (@test_results) {
|
|
|
122 |
# print "-$count-\n";
|
|
|
123 |
ok (defined $test, "Test found");
|
| 4799 |
rpuchmay |
124 |
if ($count < 196) {
|
|
|
125 |
# tests above this number have unique test names
|
|
|
126 |
is($test->{NAME}, 'junit.framework.JUnit4TestCaseFacade::unknown', 'Test name ok');
|
|
|
127 |
}
|
|
|
128 |
is ($test->{TARGET_PLATFORM}, 'dummy2Target', 'Build target is \'dummy2Target\'');
|
| 4762 |
rpuchmay |
129 |
isnt($test->{DURATION}, 0, 'Test duration is ok');
|
|
|
130 |
switch ($count) {
|
|
|
131 |
case [8..16,152] {
|
|
|
132 |
is($test->{OUTCOME}, 'ERROR', "Found a failed test");
|
|
|
133 |
ok(length($test->{MESSAGE}) > 0, "Message exists");
|
|
|
134 |
}
|
|
|
135 |
else {
|
|
|
136 |
is($test->{OUTCOME}, 'PASS', "Found a passed test");
|
|
|
137 |
isnt(defined($test->{MESSAGE}), 0, "Message exists");
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
$count++;
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
sub anyTestsFailed {
|
|
|
145 |
my $builder = Test::More->builder;
|
|
|
146 |
for my $detail ($builder->details) {
|
|
|
147 |
if (!$detail->{ok}) {
|
|
|
148 |
return 1;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
return 0;
|
|
|
152 |
}
|