TestMain runs after all tests to ensure that all tools in this package have been tested once.
(m *testing.M)
| 2565 | // TestMain runs after all tests to ensure that all tools in this package have |
| 2566 | // been tested once. |
| 2567 | func TestMain(m *testing.M) { |
| 2568 | // Initialize testedTools |
| 2569 | for _, tool := range toolsdk.All { |
| 2570 | testedTools.Store(tool.Name, false) |
| 2571 | } |
| 2572 | |
| 2573 | code := m.Run() |
| 2574 | |
| 2575 | // Ensure all tools have been tested |
| 2576 | var untested []string |
| 2577 | for _, tool := range toolsdk.All { |
| 2578 | if tested, ok := testedTools.Load(tool.Name); !ok || !tested.(bool) { |
| 2579 | // Test is skipped on Windows |
| 2580 | if runtime.GOOS == "windows" && tool.Name == "coder_workspace_bash" { |
| 2581 | continue |
| 2582 | } |
| 2583 | untested = append(untested, tool.Name) |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | if len(untested) > 0 && code == 0 { |
| 2588 | code = 1 |
| 2589 | println("The following tools were not tested:") |
| 2590 | for _, tool := range untested { |
| 2591 | println(" - " + tool) |
| 2592 | } |
| 2593 | println("Please ensure that all tools are tested using testTool().") |
| 2594 | println("If you just added a new tool, please add a test for it.") |
| 2595 | println("NOTE: if you just ran an individual test, this is expected.") |
| 2596 | } |
| 2597 | |
| 2598 | // Check for goroutine leaks. Below is adapted from goleak.VerifyTestMain: |
| 2599 | if code == 0 { |
| 2600 | if err := goleak.Find(testutil.GoleakOptions...); err != nil { |
| 2601 | println("goleak: Errors on successful test run: ", err.Error()) |
| 2602 | code = 1 |
| 2603 | } |
| 2604 | } |
| 2605 | |
| 2606 | os.Exit(code) |
| 2607 | } |
| 2608 | |
| 2609 | func TestReportTaskNilPointerDeref(t *testing.T) { |
| 2610 | t.Parallel() |