failures not counted correctly in some cases.
Summary output added.
This commit is contained in:
		
							parent
							
								
									0a4ed3a95f
								
							
						
					
					
						commit
						b71e4db7db
					
				| @ -128,4 +128,33 @@ func main() { | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	fmt.Printf("\n\nSUMMARY\n\n") | ||||
| 	fmt.Printf("%-60s %-10s %-10s %-10s %-10s %-10s %-10s\n\n", "SUITE", "COUNT", "PASSED", "FAILURES", "ERRORS", "DISABLED", "SKIPPED") | ||||
| 	for _, suite := range testsuites.Suites { | ||||
| 		fmt.Printf("%-60s %-10d %-10d %-10d %-10d %-10d %-10d\n", | ||||
| 			suite.Name, | ||||
| 			suite.TestCount, | ||||
| 			suite.TestCount-suite.Failures-suite.Errors-suite.Skipped-suite.Disabled, | ||||
| 			suite.Failures, suite.Errors, suite.Disabled, suite.Skipped) | ||||
| 	} | ||||
| 	fmt.Printf("\n%-60s %-10d %-10d %-10d %-10d %-10d %-10d\n", | ||||
| 		"TOTAL", | ||||
| 		testsuites.Tests, | ||||
| 		testsuites.Tests-testsuites.Failures-testsuites.Errors-testsuites.Skipped-testsuites.Disabled, | ||||
| 		testsuites.Failures, testsuites.Errors, testsuites.Disabled, testsuites.Skipped) | ||||
| 
 | ||||
| 	if testsuites.Failures+testsuites.Errors+testsuites.Skipped+testsuites.Disabled > 0 { | ||||
| 		fmt.Printf("\nFAILED TESTS\n\n") | ||||
| 		printFailedTests("", "", testsuites.Suites) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func printFailedTests(indent string, parentTest string, tests []*Test) { | ||||
| 	for _, test := range tests { | ||||
| 		if test.Failures > 0 { | ||||
| 			testName := strings.TrimPrefix(test.Name, parentTest+"/") | ||||
| 			fmt.Printf("%s%s\n", indent, testName) | ||||
| 			printFailedTests(indent+"   ", test.Name, test.Tests) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -39,8 +39,9 @@ type Test struct { | ||||
| 	Tests     []*Test `xml:"testsuite,omitempty"` | ||||
| 	SystemOut string  `xml:"system-out,omitempty"` | ||||
| 
 | ||||
| 	parent *Test | ||||
| 	t0     time.Time | ||||
| 	hasTests bool | ||||
| 	parent   *Test | ||||
| 	t0       time.Time | ||||
| } | ||||
| 
 | ||||
| type Result struct { | ||||
| @ -121,7 +122,8 @@ func (testsuites *Testsuites) Start(t time.Time, pkg string) { | ||||
| 
 | ||||
| func (testsuites *Testsuites) Test(t time.Time, pkg string, test string) { | ||||
| 	// This can be a test suite as well
 | ||||
| 	testsuites.getTest(t, pkg, test) | ||||
| 	testobj := testsuites.getTest(t, pkg, test) | ||||
| 	testobj.hasTests = true | ||||
| } | ||||
| 
 | ||||
| func (testsuites *Testsuites) Output(t time.Time, pkg string, test string, output string) { | ||||
| @ -153,12 +155,14 @@ func (testsuites *Testsuites) Skip(t time.Time, pkg string, test string) { | ||||
| 
 | ||||
| func (suite *Test) Complete() { | ||||
| 	suite.TestCount = 0 | ||||
| 	suite.Failures = 0 | ||||
| 	suite.Errors = 0 | ||||
| 	suite.Disabled = 0 | ||||
| 	suite.Skipped = 0 | ||||
| 	if len(suite.Tests) > 0 { | ||||
| 		suite.Failures = 0 | ||||
| 		suite.Errors = 0 | ||||
| 		suite.Disabled = 0 | ||||
| 		suite.Skipped = 0 | ||||
| 	} | ||||
| 
 | ||||
| 	if len(suite.Tests) == 0 { | ||||
| 	if len(suite.Tests) == 0 && suite.hasTests { | ||||
| 		suite.TestCount = 1 | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -6,7 +6,7 @@ func main() { | ||||
| 	module.GenerateLicenseNames() | ||||
| 	module.DumpOverview() | ||||
| 
 | ||||
| 	module.DumpText() | ||||
| 	module.DumpText(true) | ||||
| } | ||||
| 
 | ||||
| func truncateString(s string, length int) string { | ||||
|  | ||||
| @ -4,6 +4,7 @@ import ( | ||||
| 	"crypto/sha512" | ||||
| 	"encoding/base64" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"sort" | ||||
| @ -89,7 +90,11 @@ func NewModule(modules []ModuleDependency) *Module { | ||||
| 		if mod.Dir == "" { | ||||
| 			continue // Skip modules without local copies
 | ||||
| 		} | ||||
| 		license := module.findLicense(mod.Dir) | ||||
| 		license, err := module.findLicense(mod.Dir) | ||||
| 		if err != nil { | ||||
| 			log.Printf("ERROR: %v", err) | ||||
| 			continue | ||||
| 		} | ||||
| 		module.Licenses[hash(license.Text)] = license | ||||
| 		dependency := NewDependency(mod.Path, mod.Version, !mod.Indirect, license) | ||||
| 		module.Dependencies = append(module.Dependencies, dependency) | ||||
| @ -138,8 +143,11 @@ func (module Module) DumpOverview() { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (module Module) DumpText() { | ||||
| func (module Module) DumpText(directOnly bool) { | ||||
| 	for _, dependency := range module.Dependencies { | ||||
| 		if directOnly && !dependency.Direct { | ||||
| 			continue | ||||
| 		} | ||||
| 		fmt.Println(strings.Repeat("=", 80)) | ||||
| 		if dependency.Direct { | ||||
| 			fmt.Printf("Direct dependency") | ||||
| @ -152,7 +160,7 @@ func (module Module) DumpText() { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (module *Module) findLicense(dir string) *License { | ||||
| func (module *Module) findLicense(dir string) (*License, error) { | ||||
| 	licenseFiles := []string{ | ||||
| 		"LICENSE", | ||||
| 		"LICENSE.txt", | ||||
| @ -174,12 +182,12 @@ func (module *Module) findLicense(dir string) *License { | ||||
| 					hashcode := hash(content) | ||||
| 					license := module.Licenses[hashcode] | ||||
| 					if license != nil { | ||||
| 						return license | ||||
| 						return license, nil | ||||
| 					} | ||||
| 					return NewLicense(content) | ||||
| 					return NewLicense(content), nil | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return nil | ||||
| 	return nil, fmt.Errorf("No license found in '%s'", dir) | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user