Skip to content

go: fail selected tests -failfast stopped, and run only packages with selected tests - #98

Closed
sipsma wants to merge 3 commits into
mainfrom
sipsma/go-test-failfast-selected-packages
Closed

sipsma wants to merge 3 commits into
mainfrom
sipsma/go-test-failfast-selected-packages

Conversation

@sipsma

@sipsma sipsma commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Two changes to how the per-test Go checks report results.

Tests that -failfast stopped now fail as "did not run"

With -failfast in goflags, go test stops a package at its first failing test, and the selected tests after it get no result. Their checks used to pass, so one failure looked like a single red check among green ones that never ran. They now fail.

For example, with TestFoo failing before TestBar in m1/p1, dagger check shows:

CHECKS  ✘ 2 failed  ✔ 6 passed
✘ ...go-package=m1/p1&go-test=TestBar   ERROR
  ! Go tests in m1/p1: TestBar did not run: go test failed example.com/m1/p1 without running it
    === RUN   TestFoo
        tests_test.go:3: selected failure
    --- FAIL: TestFoo (0.00s)
✘ ...go-package=m1/p1&go-test=TestFoo   ERROR
  ! Go tests in m1/p1: TestFoo failed

Before, the result was 1 failed and 7 passed, with TestBar green. One failure under -failfast now shows as one red check for the failing test and one for each selected test it stopped. The same applies to a selected test that is missing from a failing package's test binary.

Only packages that hold selected tests run

When nothing was selected out of a module, its test command ran ./.... That also ran the module's packages that hold no selected test. If one of them failed, every selected test in the module failed with it, for example a package of test helpers that fails to build or whose TestMain fails. The command now names only the packages that hold selected tests, as a partial selection already did.

For a module with tests in ok and hidden, plus a package broken that fails to compile or fails in TestMain: before, both checks failed with "failures in packages without selected test checks: example.com/reporting/broken". Now both pass. A failing package without selected tests is not run and is reported nowhere.

Two cases are unchanged. A package with selected tests still fails them when it fails to build. So does a selected package whose imported package is broken. The report helper's handling of failures in packages without selected tests is unreachable now, and is removed.

Performance

The test command does less work: packages without selected tests are no longer built or run. Their package list is in discovery's byte order, so narrowed runs also stop sorting it on every check. Nothing was measured.

Testing

  • New check selected-failfast-check.
  • selected-unchecked-build-check and selected-unchecked-teardown-check now expect both tests to pass.
  • The report helper's unit test expects "did not run" after a named failure.
  • Without the change, all four fail. With it, they pass.
  • Of the full dagger check, only go-sdk/generate/stale fails. It flags gobuild/dagger.gen.go, which this PR doesn't touch, and main fails it the same way.

With -failfast, go test stops a package at its first failing test, and
the selected tests after it have no events in the report. The helper
passed them, so one failure showed as a single red check among green
ones that never ran. A test the binary left out of a failing package
passed the same way.

Such a test now fails, saying go test failed its package without
running it, as a selected test absent from a passing package already
does. One failure under -failfast now shows as one red check for the
failing test and one for each selected test it stopped.

Signed-off-by: Erik Sipsma <[email protected]>
With nothing selected out, a module's test command ran ./..., so it
also ran the module's packages that hold no selected test. When one of
them failed, such as a package of test helpers that fails to build or
whose TestMain fails, every selected test in the module failed with it,
however unrelated.

The command now names only the packages that hold selected tests, as a
partial selection already did. A failing package without any is not
run and fails no check. The helper's report of failures in packages
without selected test checks can no longer happen and is gone.

The packages come in discovery's byte order, so the command is stable
without the sort a partial selection did on every check.

Signed-off-by: Erik Sipsma <[email protected]>
…t run

With -failfast, go test starts no further test binary once a package
fails: a package that has not started yet returns without output, so
the report has no event for it at all. Its selected tests failed as
"no successful result", and which packages that hit depended on
whether each had started before the failure.

They now fail as "did not run", saying go test stopped before starting
their package after a failure. selected-failfast-check no longer
selects the second package of the failing module, whose result
depended on that timing, so its totals are the same on every run.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma

sipsma commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #95, which now carries this PR's commits unchanged alongside the rest of the per-package build.

@sipsma sipsma closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant