Skip to content

Commit 8abc8ef

Browse files
committed
PerforceTests: Don't stop test on the first error
Don't return on the first test failure in a suite, count the failures Don't exit 1 on the first PerforceIntegrationTests() failure, add the failures Count the number of tests passed, ignored/filtered ones Display progresse with prefixes for the test suite and the test in it: [5-7][2/13] Running test 'xxx.txt' [5-7] Success: 13 of 13 tests passed. Add extra empty lines for readability of the logs
1 parent f644928 commit 8abc8ef

File tree

3 files changed

+90
-66
lines changed

3 files changed

+90
-66
lines changed

Test/Perforce/PerforceTest.pm

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ BEGIN {
1212

1313
sub PerforceIntegrationTests
1414
{
15-
$dir = $_[0];
16-
$p4port = $_[1];
17-
$option = $_[2];
18-
$filter = $_[3];
15+
$suite = $_[0];
16+
$dir = $_[1];
17+
$p4port = $_[2];
18+
$option = $_[3];
19+
$filter = $_[4];
1920
$mfa = index($dir, "MultiFactorAuthentication") > -1;
2021
$devnull = "> /dev/null 2>&1";
2122

@@ -25,11 +26,11 @@ sub PerforceIntegrationTests
2526
if ($filter ne ""
2627
&& index($filter, $dir) == -1)
2728
{
28-
print "Not Running Perforce Integration Tests in dir:'",$dir,"' p4port:'",$p4port,"' (Not included in filter).\n";
29-
return 0;
29+
print "\n[$suite] '",$dir,"' Perforce Integration Tests Ignored (p4port:'",$p4port,"') (Not included in filter).\n";
30+
return 0;
3031
}
3132

32-
print "Running Perforce Integration Tests in dir:'",$dir,"' p4port:'",$p4port,"'\n";
33+
print "\n\n[$suite] '",$dir,"' Perforce Integration Tests Running (p4port:'",$p4port,"')\n";
3334

3435
rmtree("Test/tmp");
3536
mkdir "Test/tmp";
@@ -44,7 +45,7 @@ sub PerforceIntegrationTests
4445
$ENV{'P4CHARSET'} = 'utf8';
4546
$ENV{'VCS_P4PASSWD'} = 'Secret';
4647
$ENV{'P4EXECABS'} = getcwd() . "/" . $ENV{'P4EXEC'};
47-
48+
4849
if ($ENV{'TARGET'} eq "win32")
4950
{
5051
$ENV{'VCS_P4ROOT'} =~ s/\//\\/g;
@@ -73,7 +74,7 @@ sub PerforceIntegrationTests
7374
# print "Press ENTER to continue...";
7475
# <STDIN>;
7576

76-
$exitCode = RunTests($dir, $option, $filter);
77+
$exitCode = RunTests($suite, $dir, $option, $filter);
7778

7879
# print "Press ENTER to continue...";
7980
# <STDIN>;
@@ -85,14 +86,18 @@ sub PerforceIntegrationTests
8586

8687
sub RunTests()
8788
{
88-
$dir = $_[0];
89-
$option = $_[1];
90-
$filter = $_[2];
89+
$suite = $_[0];
90+
$dir = $_[1];
91+
$option = $_[2];
92+
$filter = $_[3];
9193

9294
@files = <Test/$dir/*.txt>;
9395

94-
$total = 0;
96+
$total = @files;
97+
$count = 0;
9598
$success = 0;
99+
$failed = 0;
100+
$ignored = 0;
96101

97102
$pluginexec = abs_path($ENV{'P4PLUGIN'});
98103
$testserver = abs_path($ENV{'TESTSERVER'});
@@ -106,13 +111,15 @@ sub RunTests()
106111

107112
$cwd = getcwd();
108113
foreach $i (@files) {
109-
if ($filter ne ""
114+
$count++;
115+
if ($filter ne ""
110116
&& index($i, $filter) == -1)
111117
{
112-
print "Not running Perforce Integration Tests in file:'",$i,"' p4port:'",$p4port,"'\n";
118+
$ignored++;
119+
print "\n[$suite][$count/$total] '",$i,"' Ignored (p4port:'",$p4port,"')\n";
113120
next;
114121
}
115-
print "Running Perforce Integration Tests in file:'",$i,"' p4port:'",$p4port,"'\n";
122+
print "\n[$suite][$count/$total] '",$i,"' Running (p4port:'",$p4port,"')\n";
116123
chdir $cwd;
117124
rmtree( $clientroot, {keep_root => 1} );
118125
print "Changing working directory to: '", $clientroot,"'\n";
@@ -129,21 +136,29 @@ sub RunTests()
129136
}
130137
elsif ($? == -1)
131138
{
132-
print "Error running test '$i' : $!\n";
139+
print "\n[$suite][$count/$total] '",$i,"' Error running test: $!\n\n";
133140
chdir $cwd;
134141
return 1;
135142
}
136143
else
137144
{
138-
print "Test failed -> stopping all tests\n";
139-
chdir $cwd;
140-
return 1;
145+
print "\n[$suite][$count/$total] '",$i,"' Failed (p4port:'",$p4port,"')\n\n";
146+
$failed++;
141147
}
142-
$total++;
143148
RemoveExclusiveFile();
144149
}
145-
print "Done: $success of $total tests passed.\n";
146150
chdir $cwd;
151+
if ($ignored > 0)
152+
{
153+
print "[$suite] $ignored of $total tests ignored.\n";
154+
}
155+
if ($failed > 0)
156+
{
157+
print "[$suite] Failed: $failed of $total tests failed.\n";
158+
print "[$suite] $success of $total tests passed.\n";
159+
return $failed;
160+
}
161+
print "[$suite] Success: $success of $total tests passed.\n";
147162
return 0;
148163
}
149164

@@ -160,7 +175,7 @@ sub AddExclusiveFile
160175
open(FH, '>', 'Assets/exclusivefile.txt') or die $!;
161176
print(FH 'File with exclusive open file type modifier.');
162177
close(FH) or die $1;
163-
178+
164179
RunCommand('add -t text+l Assets/exclusivefile.txt');
165180
RunCommand('submit -d "Add Assets/exclusivefile.txt." Assets/exclusivefile.txt');
166181
}
@@ -173,7 +188,7 @@ sub RemoveExclusiveFile
173188

174189
sub SetupServer
175190
{
176-
$root = $ENV{'VCS_P4ROOT'};
191+
$root = $ENV{'VCS_P4ROOT'};
177192
my $p4port = $ENV{'VCS_P4PORT'};
178193
print "Setting server in '$root' listening on port '$p4port'\n";
179194
rmtree($root);
@@ -190,6 +205,7 @@ sub SetupServer
190205
}
191206

192207
my $p4d = $ENV{'P4DEXEC'};
208+
print "Starting server '$p4d'\n";
193209
system("$p4d -xi -r \"$root\"");
194210
my $pidfile = getcwd() . "/server.pid";
195211
my $pid = SpawnSubProcess($p4d, " -r \"$root\" -p $p4port --pid-file=$pidfile");
@@ -288,9 +304,9 @@ Update: 2022/07/20 11:40:48
288304
289305
Access: 2022/07/20 11:40:48
290306
291-
FullName: Multi Factor Authentication
307+
FullName: Multi Factor Authentication
292308
293-
Password: ******
309+
Password: ******
294310
295311
AuthMethod: perforce+2fa
296312
EOF
@@ -313,9 +329,9 @@ sub SetupMFATriggers
313329
$TRIGGERS =<<EOF;
314330
315331
Triggers:
316-
test-pre-2fa auth-pre-2fa auth "$mfa_script -t pre-2fa -e %quote%%email%%quote% -u %user% -h %host%"
317-
test-init-2fa auth-init-2fa auth "$mfa_script -t init-2fa -e %quote%%email%%quote% -u %user% -h %host% -m %method%"
318-
test-check-2fa auth-check-2fa auth "$mfa_script -t check-2fa -e %quote%%email%%quote% -u %user% -h %host% -s %scheme% -k %token%"
332+
test-pre-2fa auth-pre-2fa auth "$mfa_script -t pre-2fa -e %quote%%email%%quote% -u %user% -h %host%"
333+
test-init-2fa auth-init-2fa auth "$mfa_script -t init-2fa -e %quote%%email%%quote% -u %user% -h %host% -m %method%"
334+
test-check-2fa auth-check-2fa auth "$mfa_script -t check-2fa -e %quote%%email%%quote% -u %user% -h %host% -s %scheme% -k %token%"
319335
EOF
320336

321337
open(FD, "| $ENV{'P4EXEC'} -p $ENV{'VCS_P4PORT'} -u mfa_test_user -P Mfau1111 triggers -i ");
@@ -341,7 +357,7 @@ Update:2013/02/19 09:13:18
341357
Access:2013/06/24 12:38:18
342358
343359
Description:
344-
Created by $ENV{'VCS_P4USER'}.
360+
Created by $ENV{'VCS_P4USER'}.
345361
346362
Root:$root
347363
@@ -352,8 +368,8 @@ SubmitOptions:submitunchanged
352368
LineEnd:local
353369
354370
View:
355-
//depot/... //$ENV{'VCS_P4CLIENT'}/...
356-
-//depot/Assets/excludedfile.txt //$ENV{'VCS_P4CLIENT'}/Assets/excludedfile.txt
371+
//depot/... //$ENV{'VCS_P4CLIENT'}/...
372+
-//depot/Assets/excludedfile.txt //$ENV{'VCS_P4CLIENT'}/Assets/excludedfile.txt
357373
EOF
358374

359375
open(FD, "| $ENV{'P4EXEC'} -p $ENV{'VCS_P4PORT'} -u vcs_test_user client -i ");

Test/VCSTest.pm

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ use PerforceTest;
33

44
sub IntegrationTest
55
{
6-
$exitCode = PerforceIntegrationTests(@_);
7-
if ($exitCode != 0)
8-
{
9-
exit $exitCode;
10-
}
6+
$failed = PerforceIntegrationTests(@_);
7+
return $failed;
118
}
129

1310
1;

build.pl

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@
2525
rmtree("Release");
2626
rmtree("Build");
2727
find(\&wanted, "./");
28-
sub wanted
28+
sub wanted
2929
{
30-
my($filename, $dirs, $suffix) = fileparse($File::Find::name, qr/\.[^.]*/);
30+
my($filename, $dirs, $suffix) = fileparse($File::Find::name, qr/\.[^.]*/);
3131
if (($suffix eq ".o") or ($suffix eq ".obj"))
3232
{
33-
print "delete $File::Find::name","\n";
34-
unlink($_);
33+
print "delete $File::Find::name","\n";
34+
unlink($_);
3535
}
36-
}
37-
unlink("PerforcePlugin");
36+
}
37+
unlink("PerforcePlugin");
3838
exit 0;
3939
}
4040

4141
if (not $target)
4242
{
43-
if ($^O eq "darwin")
43+
if ($^O eq "darwin")
4444
{
45-
$target = "mac";
45+
$target = "mac";
4646
}
47-
elsif ($^O eq "MSWin32")
47+
elsif ($^O eq "MSWin32")
4848
{
4949
$target = "win32";
5050
}
51-
elsif ($^O eq "linux")
51+
elsif ($^O eq "linux")
5252
{
5353
$target = "linux64";
5454
}
@@ -60,7 +60,7 @@
6060
{
6161
unless ($test)
6262
{
63-
BuildMac();
63+
BuildMac();
6464
}
6565
else
6666
{
@@ -71,7 +71,7 @@
7171
{
7272
unless ($test)
7373
{
74-
BuildWin32();
74+
BuildWin32();
7575
}
7676
else
7777
{
@@ -100,26 +100,37 @@
100100
TestLinux ($target);
101101
}
102102
}
103-
else
103+
else
104104
{
105-
die ("Unknown platform");
105+
die ("Unknown platform");
106106
}
107107

108108
sub TestPerforce()
109109
{
110-
IntegrationTest("Plugin", "localhost:1667", $testoption, $filter);
111-
IntegrationTest("Plugin", "ssl:localhost:1667", $testoption, $filter);
112-
IntegrationTest("Perforce/Common", "localhost:1667", $testoption, $filter);
113-
IntegrationTest("Perforce/Common", "ssl:localhost:1667", $testoption, $filter);
114-
IntegrationTest("Perforce/BaseIPv4", "tcp4:localhost:1667", $testoption, $filter);
115-
IntegrationTest("Perforce/SecureBaseIPv4", "ssl4:localhost:1667", $testoption, $filter);
116-
IntegrationTest("Perforce/SquareBracketIPv4", "tcp4:[localhost]:1667", $testoption, $filter);
110+
my $failed = 0;
111+
$failed += IntegrationTest("1/8", "Plugin", "localhost:1667", $testoption, $filter);
112+
$failed += IntegrationTest("2/8", "Plugin", "ssl:localhost:1667", $testoption, $filter);
113+
$failed += IntegrationTest("3/8", "Perforce/Common", "localhost:1667", $testoption, $filter);
114+
$failed += IntegrationTest("4/8", "Perforce/Common", "ssl:localhost:1667", $testoption, $filter);
115+
$failed += IntegrationTest("5/8", "Perforce/BaseIPv4", "tcp4:localhost:1667", $testoption, $filter);
116+
$failed += IntegrationTest("6/8", "Perforce/SecureBaseIPv4", "ssl4:localhost:1667", $testoption, $filter);
117+
$failed += IntegrationTest("7/8", "Perforce/SquareBracketIPv4", "tcp4:[localhost]:1667", $testoption, $filter);
118+
$failed += IntegrationTest("8/8", "Perforce/MultiFactorAuthentication", "localhost:1667", $testoption, $filter);
117119
# Only works if DNS routes via IPv6
118-
# IntegrationTest("Perforce/BaseIPv6", "tcp6:[localhost]:1667", $testoption, $filter);
120+
# $failed += IntegrationTest("Perforce/BaseIPv6", "tcp6:[localhost]:1667", $testoption, $filter);
119121
# Does not work in new version of Perforce server
120-
# IntegrationTest("Perforce/SquareBracketIPv6", "tcp6:[::1]:1667", $testoption, $filter);
121-
# IntegrationTest("Perforce/SecureSquareBracketIPv6", "ssl6:[::1]:1667", $testoption, $filter);
122-
IntegrationTest("Perforce/MultiFactorAuthentication", "localhost:1667", $testoption, $filter);
122+
# $failed += IntegrationTest("Perforce/SquareBracketIPv6", "tcp6:[::1]:1667", $testoption, $filter);
123+
# $failed += IntegrationTest("Perforce/SecureSquareBracketIPv6", "ssl6:[::1]:1667", $testoption, $filter);
124+
125+
if ($failed > 0)
126+
{
127+
print "\nFAILURE $failed Perforce Integrations Test(s) failed!\n\n";
128+
exit 1;
129+
}
130+
else
131+
{
132+
print "\nSUCCESS: All Perforce Integrations Tests passed\n\n";
133+
}
123134
}
124135

125136
sub BuildMac
@@ -143,9 +154,9 @@ sub TestMac
143154

144155
sub BuildWin32
145156
{
146-
rmtree("Build");
147-
system("msbuilder.cmd", "VersionControl.sln", "P4Plugin", "Win32") && die ("Failed to build PerforcePlugin.exe");
148-
system("msbuilder.cmd", "VersionControl.sln", "TestServer", "Win32") && die ("Failed to build TestServer.exe");
157+
rmtree("Build");
158+
system("msbuilder.cmd", "VersionControl.sln", "P4Plugin", "Win32") && die ("Failed to build PerforcePlugin.exe");
159+
system("msbuilder.cmd", "VersionControl.sln", "TestServer", "Win32") && die ("Failed to build TestServer.exe");
149160
}
150161

151162
sub TestWin32
@@ -194,4 +205,4 @@ ($)
194205
chmod 0755, glob("Build/linux64/*");
195206

196207
TestPerforce();
197-
}
208+
}

0 commit comments

Comments
 (0)