Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stdlib/Test/test/nothrow_testset.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutable struct NoThrowTestSet <: Test.AbstractTestSet
results::Vector
NoThrowTestSet(desc) = new([])
end
Test.record(ts::NoThrowTestSet, t::Test.Result) = (push!(ts.results, t); t)
Test.finish(ts::NoThrowTestSet) = ts.results
45 changes: 21 additions & 24 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ end
"Thrown: ErrorException")
end
# Test printing of Fail results
mutable struct NoThrowTestSet <: Test.AbstractTestSet
results::Vector
NoThrowTestSet(desc) = new([])
end
Test.record(ts::NoThrowTestSet, t::Test.Result) = (push!(ts.results, t); t)
Test.finish(ts::NoThrowTestSet) = ts.results
include("nothrow_testset.jl")

let fails = @testset NoThrowTestSet begin
# 1 - Fail - wrong exception
@test_throws OverflowError error()
Expand Down Expand Up @@ -797,29 +793,30 @@ end
@test startswith(fails[4].value, "ErrorException")
end

function newfunc()
42
end
@deprecate oldfunc newfunc
let code = quote
function newfunc()
42
end
@deprecate oldfunc newfunc

@testset "@test_deprecated" begin
@test_deprecated oldfunc()
@testset "@test_deprecated" begin
@test_deprecated oldfunc()
@test Base.JLOptions().depwarn == 1

# Expression passthrough
if Base.JLOptions().depwarn != 2
@test (@test_deprecated oldfunc()) == 42
@test (@test_deprecated oldfunc()) == 42

fails = @testset NoThrowTestSet "check that @test_deprecated detects bad input" begin
@test_deprecated newfunc()
@test_deprecated r"Not found in message" oldfunc()
fails = @testset NoThrowTestSet "check that @test_deprecated detects bad input" begin
@test_deprecated newfunc()
@test_deprecated r"Not found in message" oldfunc()
end
@test length(fails) == 2
@test fails[1] isa Test.LogTestFailure
@test fails[2] isa Test.LogTestFailure
end
@test length(fails) == 2
@test fails[1] isa Test.LogTestFailure
@test fails[2] isa Test.LogTestFailure
else
@warn """Omitting `@test_deprecated` tests which can't yet
be tested in --depwarn=error mode"""
end
incl = "include($(repr(joinpath(@__DIR__, "nothrow_testset.jl"))))"
cmd = `$(Base.julia_cmd()) --startup-file=no --depwarn=yes -e 'using Test' -e $incl -e $code`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that -e $code works in backticks and is completely safe... 😍

(Yes, I've been bash scripting today)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can often still be a bit more reliable to put the content into stdin (via pipeline below). But the maximum here is getconf ARG_MAX, or 2MB on linux, 256KB on most posix, and 32k on Windows, and we're very well inside those limits here.

@test success(pipeline(cmd))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does pipeline do anything here?

Suggested change
@test success(pipeline(cmd))
@test success(cmd)

end

@testset "@testset preserves GLOBAL_RNG's state, and re-seeds it" begin
Expand Down