Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit 2ba00d6

Browse files
author
Mark Ryan
committed
test-cases: Fix hang when computing the root package
The code that computed the root package of all packages under test was buggy. Depending on the order of the packages supplied to test-cases, it was possible to enter an endless loop. This PR fixes the issue. Fixes #307 Signed-off-by: Mark Ryan <[email protected]>
1 parent 52648be commit 2ba00d6

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

test-cases/test-cases.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,27 +424,30 @@ func generateHTMLReport(tests []*PackageTests) error {
424424
}
425425

426426
func findCommonPrefix(tests []*PackageTests) string {
427-
if len(tests) == 0 {
428-
return ""
429-
}
430-
431-
pkgName := tests[0].Name
432-
OUTER:
433-
for {
427+
for j := range tests {
428+
pkgName := tests[j].Name
434429
index := strings.LastIndex(pkgName, "/")
435430
if index == -1 {
436431
return ""
437432
}
438-
pkgName := pkgName[:index+1]
433+
pkgRoot := pkgName[:index+1]
439434

440435
var i int
441-
for i = 1; i < len(tests); i++ {
442-
if !strings.HasPrefix(tests[i].Name, pkgName) {
443-
continue OUTER
436+
for i = 0; i < len(tests); i++ {
437+
if i == j {
438+
continue
439+
}
440+
if !strings.HasPrefix(tests[i].Name, pkgRoot) {
441+
break
444442
}
445443
}
446-
return pkgName
444+
445+
if i == len(tests) {
446+
return pkgRoot
447+
}
447448
}
449+
450+
return ""
448451
}
449452

450453
func dumpFailedTestOutput(prefix string, tests []*PackageTests, colourOn, colourOff string) {

0 commit comments

Comments
 (0)