diff --git a/framework/ldtest/test_logger.go b/framework/ldtest/test_logger.go index ce07842e..6bd626d7 100644 --- a/framework/ldtest/test_logger.go +++ b/framework/ldtest/test_logger.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strings" + "sync" "github.com/launchdarkly/sdk-test-harness/v2/framework" "github.com/launchdarkly/sdk-test-harness/v2/framework/helpers" @@ -44,6 +45,51 @@ type MultiTestLogger struct { Loggers []TestLogger } +type CountingTestLogger struct { + wrapped TestLogger + totalTests int + skippedTests int + mu sync.Mutex +} + +func NewCountingTestLogger(wrapped TestLogger) *CountingTestLogger { + return &CountingTestLogger{ + wrapped: wrapped, + } +} + +func (c *CountingTestLogger) TestStarted(id TestID) { + c.mu.Lock() + c.totalTests++ + c.mu.Unlock() + c.wrapped.TestStarted(id) +} + +func (c *CountingTestLogger) TestError(id TestID, err error) { + c.wrapped.TestError(id, err) +} + +func (c *CountingTestLogger) TestFinished(id TestID, result TestResult, debugOutput framework.CapturedOutput) { + c.wrapped.TestFinished(id, result, debugOutput) +} + +func (c *CountingTestLogger) TestSkipped(id TestID, reason string) { + c.mu.Lock() + c.skippedTests++ + c.mu.Unlock() + c.wrapped.TestSkipped(id, reason) +} + +func (c *CountingTestLogger) EndLog(results Results) error { + return c.wrapped.EndLog(results) +} + +func (c *CountingTestLogger) GetCounts() (total, skipped int) { + c.mu.Lock() + defer c.mu.Unlock() + return c.totalTests, c.skippedTests +} + func (c ConsoleTestLogger) TestStarted(id TestID) { fmt.Printf("[%s]\n", id) } diff --git a/main.go b/main.go index 8f524199..b90d04c3 100644 --- a/main.go +++ b/main.go @@ -79,11 +79,18 @@ func run(params commandParams) (*ldtest.Results, error) { }} } - results := sdktests.RunSDKTestSuite(harness, params.filters, testLogger) + countingLogger := ldtest.NewCountingTestLogger(testLogger) + testLogger = countingLogger + + results := sdktests.RunSDKTestSuite(harness, params.filters, countingLogger) fmt.Println() logErr := testLogger.EndLog(results) + total, skipped := countingLogger.GetCounts() + fmt.Printf("Test Summary: %d total, %d skipped, %d ran\n", total, skipped, total-skipped) + fmt.Println() + if params.stopServiceAtEnd { fmt.Println("Stopping test service") if err := harness.StopService(); err != nil {