-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add maxfailures option to limit test failures before stopping #61560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1952,6 +1952,119 @@ end | |
| end | ||
| end | ||
|
|
||
| @testset "maxfailures option" begin | ||
| @testset "default (no limit)" begin | ||
| mktemp() do f, _ | ||
| write(f, | ||
| """ | ||
| using Test | ||
| Test.global_failure_count[] = 0 | ||
| @testset "outer" begin | ||
| @testset "First" begin | ||
| @test false | ||
| @test false | ||
| end | ||
| @testset "Second" begin | ||
| @test true | ||
| end | ||
| end | ||
| """) | ||
| cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f` | ||
| result = read(pipeline(ignorestatus(cmd), stderr=devnull), String) | ||
| @test occursin("Test Summary:", result) | ||
| @test occursin("First", result) | ||
| @test occursin("Second", result) | ||
| end | ||
| end | ||
| @testset "stop after 1 failure" begin | ||
| mktemp() do f, _ | ||
| write(f, | ||
| """ | ||
| using Test | ||
| Test.global_failure_count[] = 0 | ||
| Test.global_failure_limit[] = 1 | ||
| @testset "outer" begin | ||
| @testset "First" begin | ||
| @test false | ||
| end | ||
| @testset "Second" begin | ||
| @test true | ||
| end | ||
| end | ||
| """) | ||
| cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f` | ||
| result = read(pipeline(ignorestatus(cmd), stderr=devnull), String) | ||
| @test occursin("Max failures reached: 1", result) | ||
| @test occursin("First", result) | ||
| @test !occursin(r"Test Summary:.*\n.*Second", result) | ||
| end | ||
| end | ||
| @testset "stop after N failures" begin | ||
| mktemp() do f, _ | ||
| write(f, | ||
| """ | ||
| using Test | ||
| Test.global_failure_count[] = 0 | ||
| Test.global_failure_limit[] = 2 | ||
| @testset "outer" begin | ||
| @testset "First" begin | ||
| @test false | ||
| @test false | ||
| end | ||
| @testset "Second" begin | ||
| @test true | ||
| end | ||
| end | ||
| """) | ||
| cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f` | ||
| result = read(pipeline(ignorestatus(cmd), stderr=devnull), String) | ||
| @test occursin("Max failures reached: 2", result) | ||
| @test occursin("First", result) | ||
| @test !occursin(r"Test Summary:.*\n.*Second", result) | ||
|
||
| end | ||
| end | ||
| @testset "errors count toward limit" begin | ||
| mktemp() do f, _ | ||
| write(f, | ||
| """ | ||
| using Test | ||
| Test.global_failure_count[] = 0 | ||
| Test.global_failure_limit[] = 1 | ||
| @testset "outer" begin | ||
| @testset "First" begin | ||
| @test error("oops") | ||
| end | ||
| @testset "Second" begin | ||
| @test true | ||
| end | ||
| end | ||
| """) | ||
| cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f` | ||
| result = read(pipeline(ignorestatus(cmd), stderr=devnull), String) | ||
| @test occursin("Max failures reached: 1", result) | ||
| @test occursin("First", result) | ||
| @test !occursin(r"Test Summary:.*\n.*Second", result) | ||
|
||
| end | ||
| end | ||
| @testset "process exits with failure" begin | ||
| mktemp() do f, _ | ||
| write(f, | ||
| """ | ||
| using Test | ||
| Test.global_failure_count[] = 0 | ||
| Test.global_failure_limit[] = 1 | ||
| @testset "outer" begin | ||
| @testset "First" begin | ||
| @test false | ||
| end | ||
| end | ||
| """) | ||
| cmd = `$(Base.julia_cmd()) --startup-file=no --color=no $f` | ||
| @test !success(ignorestatus(cmd)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Non-booleans in @test (#35888) | ||
| struct T35888 end | ||
| Base.isequal(::T35888, ::T35888) = T35888() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These regexes assume
\nline endings. To make the tests more robust across platforms/environments, consider matching\r?\n(or otherwise avoiding hard-coding newline style) so the assertion doesn’t become Windows-sensitive.