Skip to content

Commit

Permalink
Use === to compare with nothing in tests (#55563)
Browse files Browse the repository at this point in the history
This follows the generally recommended style, and updates instances of
`a == nothing` to `a === nothing` in tests, and similarly for the `!=`
comparison.
  • Loading branch information
jishnub authored Aug 22, 2024
1 parent 58c7186 commit 6d7f4a2
Show file tree
Hide file tree
Showing 24 changed files with 170 additions and 170 deletions.
2 changes: 1 addition & 1 deletion stdlib/OpenBLAS_jll/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ else
end

@testset "OpenBLAS_jll" begin
@test dlsym(OpenBLAS_jll.libopenblas_handle, @blasfunc(openblas_set_num_threads); throw_error=false) != nothing
@test dlsym(OpenBLAS_jll.libopenblas_handle, @blasfunc(openblas_set_num_threads); throw_error=false) !== nothing
end
18 changes: 9 additions & 9 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -591,32 +591,32 @@ end
@test findall(!, m) == [k for (k,v) in pairs(m) if !v]
@test findfirst(!iszero, a) == 2
@test findfirst(a.==0) == 1
@test findfirst(a.==5) == nothing
@test findfirst(a.==5) === nothing
@test findfirst(Dict(1=>false, 2=>true)) == 2
@test findfirst(Dict(1=>false)) == nothing
@test findfirst(Dict(1=>false)) === nothing
@test findfirst(isequal(3), [1,2,4,1,2,3,4]) == 6
@test findfirst(!isequal(1), [1,2,4,1,2,3,4]) == 2
@test findfirst(isodd, [2,4,6,3,9,2,0]) == 4
@test findfirst(isodd, [2,4,6,2,0]) == nothing
@test findfirst(isodd, [2,4,6,2,0]) === nothing
@test findnext(!iszero,a,4) == 4
@test findnext(!iszero,a,5) == 6
@test findnext(!iszero,a,1) == 2
@test findnext(isequal(1),a,4) == 6
@test findnext(isequal(5),a,4) == nothing
@test findnext(isequal(5),a,4) === nothing
@test findlast(!iszero, a) == 8
@test findlast(a.==0) == 5
@test findlast(a.==5) == nothing
@test findlast(false) == nothing # test non-AbstractArray findlast
@test findlast(a.==5) === nothing
@test findlast(false) === nothing # test non-AbstractArray findlast
@test findlast(isequal(3), [1,2,4,1,2,3,4]) == 6
@test findlast(isodd, [2,4,6,3,9,2,0]) == 5
@test findlast(isodd, [2,4,6,2,0]) == nothing
@test findlast(isodd, [2,4,6,2,0]) === nothing
@test findprev(!iszero,a,4) == 4
@test findprev(!iszero,a,5) == 4
@test findprev(!iszero,a,1) == nothing
@test findprev(!iszero,a,1) === nothing
@test findprev(isequal(1),a,4) == 2
@test findprev(isequal(1),a,8) == 6
@test findprev(isodd, [2,4,5,3,9,2,0], 7) == 5
@test findprev(isodd, [2,4,5,3,9,2,0], 2) == nothing
@test findprev(isodd, [2,4,5,3,9,2,0], 2) === nothing
@test findfirst(isequal(0x00), [0x01, 0x00]) == 2
@test findlast(isequal(0x00), [0x01, 0x00]) == 2
@test findnext(isequal(0x00), [0x00, 0x01, 0x00], 2) == 3
Expand Down
34 changes: 17 additions & 17 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,11 @@ timesofar("find")
@test findprev(b1, 777) == findprevnot(b2, 777) == findprev(!, b2, 777) == 777
@test findprev(b1, 776) == findprevnot(b2, 776) == findprev(!, b2, 776) == 77
@test findprev(b1, 77) == findprevnot(b2, 77) == findprev(!, b2, 77) == 77
@test findprev(b1, 76) == findprevnot(b2, 76) == findprev(!, b2, 76) == nothing
@test findprev(b1, -1) == findprevnot(b2, -1) == findprev(!, b2, -1) == nothing
@test findprev(identity, b1, -1) == nothing
@test findprev(Returns(false), b1, -1) == nothing
@test findprev(Returns(true), b1, -1) == nothing
@test findprev(b1, 76) == findprevnot(b2, 76) == findprev(!, b2, 76) === nothing
@test findprev(b1, -1) == findprevnot(b2, -1) == findprev(!, b2, -1) === nothing
@test findprev(identity, b1, -1) === nothing
@test findprev(Returns(false), b1, -1) === nothing
@test findprev(Returns(true), b1, -1) === nothing
@test_throws BoundsError findnext(b1, -1)
@test_throws BoundsError findnextnot(b2, -1)
@test_throws BoundsError findnext(!, b2, -1)
Expand All @@ -1372,28 +1372,28 @@ timesofar("find")
@test findnext(b1, 77) == findnextnot(b2, 77) == findnext(!, b2, 77) == 77
@test findnext(b1, 78) == findnextnot(b2, 78) == findnext(!, b2, 78) == 777
@test findnext(b1, 777) == findnextnot(b2, 777) == findnext(!, b2, 777) == 777
@test findnext(b1, 778) == findnextnot(b2, 778) == findnext(!, b2, 778) == nothing
@test findnext(b1, 1001) == findnextnot(b2, 1001) == findnext(!, b2, 1001) == nothing
@test findnext(identity, b1, 1001) == findnext(Returns(false), b1, 1001) == findnext(Returns(true), b1, 1001) == nothing
@test findnext(b1, 778) == findnextnot(b2, 778) == findnext(!, b2, 778) === nothing
@test findnext(b1, 1001) == findnextnot(b2, 1001) == findnext(!, b2, 1001) === nothing
@test findnext(identity, b1, 1001) == findnext(Returns(false), b1, 1001) == findnext(Returns(true), b1, 1001) === nothing

@test findlast(b1) == Base.findlastnot(b2) == 777
@test findfirst(b1) == Base.findfirstnot(b2) == 77

b0 = BitVector()
@test findprev(Returns(true), b0, -1) == nothing
@test findprev(Returns(true), b0, -1) === nothing
@test_throws BoundsError findprev(Returns(true), b0, 1)
@test_throws BoundsError findnext(Returns(true), b0, -1)
@test findnext(Returns(true), b0, 1) == nothing
@test findnext(Returns(true), b0, 1) === nothing

b1 = falses(10)
@test findprev(Returns(true), b1, 5) == 5
@test findnext(Returns(true), b1, 5) == 5
@test findprev(Returns(true), b1, -1) == nothing
@test findnext(Returns(true), b1, 11) == nothing
@test findprev(Returns(false), b1, 5) == nothing
@test findnext(Returns(false), b1, 5) == nothing
@test findprev(Returns(false), b1, -1) == nothing
@test findnext(Returns(false), b1, 11) == nothing
@test findprev(Returns(true), b1, -1) === nothing
@test findnext(Returns(true), b1, 11) === nothing
@test findprev(Returns(false), b1, 5) === nothing
@test findnext(Returns(false), b1, 5) === nothing
@test findprev(Returns(false), b1, -1) === nothing
@test findnext(Returns(false), b1, 11) === nothing
@test_throws BoundsError findprev(Returns(true), b1, 11)
@test_throws BoundsError findnext(Returns(true), b1, -1)

Expand All @@ -1415,7 +1415,7 @@ timesofar("find")
for l = [1, 63, 64, 65, 127, 128, 129]
f = falses(l)
t = trues(l)
@test findprev(f, l) == findprevnot(t, l) == nothing
@test findprev(f, l) == findprevnot(t, l) === nothing
@test findprev(t, l) == findprevnot(f, l) == l
b1 = falses(l)
b1[end] = true
Expand Down
2 changes: 1 addition & 1 deletion test/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ end
c = Channel(1)
close(c)
@test !isopen(c)
c.excp == nothing # to trigger the branch
c.excp === nothing # to trigger the branch
@test_throws InvalidStateException Base.check_channel_state(c)
end

Expand Down
2 changes: 1 addition & 1 deletion test/char.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end
#iterate(c::Char)
for x in testarrays
@test iterate(x)[1] == x
@test iterate(x, iterate(x)[2]) == nothing
@test iterate(x, iterate(x)[2]) === nothing
end

#isless(x::Char, y::Integer) = isless(UInt32(x), y)
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ function f1_30093(r)
end
end

@test f1_30093(Ref(0)) == nothing
@test f1_30093(Ref(0)) === nothing

# issue 33590
function f33590(b, x)
Expand Down
4 changes: 2 additions & 2 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ gl_17003 = [1, 2, 3]
f2_17003(item::AVector_17003) = nothing
f2_17003(::Any) = f2_17003(NArray_17003(gl_17003))

@test f2_17003(1) == nothing
@test f2_17003(1) === nothing

# issue #20847
function segfaultfunction_20847(A::Vector{NTuple{N, T}}) where {N, T}
Expand All @@ -1076,7 +1076,7 @@ end
tuplevec_20847 = Tuple{Float64, Float64}[(0.0,0.0), (1.0,0.0)]

for A in (1,)
@test segfaultfunction_20847(tuplevec_20847) == nothing
@test segfaultfunction_20847(tuplevec_20847) === nothing
end

# Issue #20902, check that this doesn't error.
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/ssair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ let code = Any[
]
ir = make_ircode(code; verify=false)
ir = Core.Compiler.compact!(ir, true)
@test Core.Compiler.verify_ir(ir) == nothing
@test Core.Compiler.verify_ir(ir) === nothing
end

# issue #37919
Expand Down
2 changes: 1 addition & 1 deletion test/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ end
bar = Bar19921(foo, Dict(foo => 3))
bar2 = deepcopy(bar)
@test bar2.foo keys(bar2.fooDict)
@test bar2.fooDict[bar2.foo] != nothing
@test bar2.fooDict[bar2.foo] !== nothing
end

let d = IdDict(rand(2) => rand(2) for i = 1:100)
Expand Down
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7031,7 +7031,7 @@ translate27368(::Type{Val{name}}) where {name} =
# issue #27456
@inline foo27456() = try baz_nonexistent27456(); catch; nothing; end
bar27456() = foo27456()
@test bar27456() == nothing
@test bar27456() === nothing

# issue #27365
mutable struct foo27365
Expand Down
6 changes: 3 additions & 3 deletions test/corelogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ end
end
@test length(logger.logs) == 1
record = logger.logs[1]
@test record._module == nothing
@test record.file == nothing
@test record.line == nothing
@test record._module === nothing
@test record.file === nothing
@test record.line === nothing
end

# PR #28209
Expand Down
6 changes: 3 additions & 3 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Random
@test isequal(p,10=>20)
@test iterate(p)[1] == 10
@test iterate(p, iterate(p)[2])[1] == 20
@test iterate(p, iterate(p, iterate(p)[2])[2]) == nothing
@test iterate(p, iterate(p, iterate(p)[2])[2]) === nothing
@test firstindex(p) == 1
@test lastindex(p) == length(p) == 2
@test Base.indexed_iterate(p, 1, nothing) == (10,2)
Expand Down Expand Up @@ -683,9 +683,9 @@ end
@inferred setindex!(d, -1, 10)
@test d[10] == -1
@test 1 == @inferred d[1]
@test get(d, -111, nothing) == nothing
@test get(d, -111, nothing) === nothing
@test 1 == @inferred get(d, 1, 1)
@test pop!(d, -111, nothing) == nothing
@test pop!(d, -111, nothing) === nothing
@test 1 == @inferred pop!(d, 1)

# get! and delete!
Expand Down
2 changes: 1 addition & 1 deletion test/generic_map_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function generic_map_tests(mapf, inplace_mapf=nothing)
@test mapf(f, Int[], Int[], Complex{Int}[]) == Union{}[]

# In-place map
if inplace_mapf != nothing
if inplace_mapf !== nothing
A = Float64[1:10...]
inplace_mapf(x -> x*x, A, A)
@test A == map(x -> x*x, Float64[1:10...])
Expand Down
4 changes: 2 additions & 2 deletions test/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ for order in (:not_atomic, :monotonic, :acquire, :release, :acquire_release, :se
@test (order -> Core.Intrinsics.atomic_fence(order))(order) === nothing
@test Base.invokelatest(@eval () -> Core.Intrinsics.atomic_fence($(QuoteNode(order)))) === nothing
end
@test Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent) == nothing
@test (@force_compile; Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent)) == nothing
@test Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent) === nothing
@test (@force_compile; Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent)) === nothing

primitive type Int256 <: Signed 256 end
Int256(i::Int) = Core.Intrinsics.sext_int(Int256, i)
Expand Down
2 changes: 1 addition & 1 deletion test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ end
a = Base.GenericIOBuffer(UInt8[], true, true, false, true, typemax(Int))
mark(a) # mark at position 0
write(a, "Hello!")
@test Base.compact(a) == nothing # because pointer > mark
@test Base.compact(a) === nothing # because pointer > mark
close(a)
b = Base.GenericIOBuffer(UInt8[], true, true, false, true, typemax(Int))
write(b, "Hello!")
Expand Down
4 changes: 2 additions & 2 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ end
@test Base.IteratorSize(product(1:2, countfrom(1))) == Base.IsInfinite()

@test Base.iterate(product()) == ((), true)
@test Base.iterate(product(), 1) == nothing
@test Base.iterate(product(), 1) === nothing

# intersection
@test intersect(product(1:3, 4:6), product(2:4, 3:5)) == Iterators.ProductIterator((2:3, 4:5))
Expand Down Expand Up @@ -993,7 +993,7 @@ end
end

@testset "Iterators.peel" begin
@test Iterators.peel([]) == nothing
@test Iterators.peel([]) === nothing
@test Iterators.peel(1:10)[1] == 1
@test Iterators.peel(1:10)[2] |> collect == 2:10
@test Iterators.peel(x^2 for x in 2:4)[1] == 4
Expand Down
16 changes: 8 additions & 8 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ end

@test root.uuid == root_uuid
@test this.uuid == this_uuid
@test that == nothing
@test that === nothing

write(project_file, """
name = "Root"
Expand All @@ -180,8 +180,8 @@ end
that = Base.identify_package("That")

@test root.uuid == proj_uuid
@test this == nothing
@test that == nothing
@test this === nothing
@test that === nothing
finally
copy!(LOAD_PATH, old_load_path)
end
Expand Down Expand Up @@ -213,8 +213,8 @@ end
that = Base.identify_package("That")

@test root.uuid == root_uuid
@test this == nothing
@test that == nothing
@test this === nothing
@test that === nothing

@test Base.get_uuid_name(project_file, this_uuid) == "This"
finally
Expand Down Expand Up @@ -273,8 +273,8 @@ end
@test joinpath(@__DIR__, normpath(path)) == locate_package(pkg)
@test Base.compilecache_path(pkg, UInt64(0)) == Base.compilecache_path(pkg, UInt64(0))
end
@test identify_package("Baz") == nothing
@test identify_package("Qux") == nothing
@test identify_package("Baz") === nothing
@test identify_package("Qux") === nothing
@testset "equivalent package names" begin
classes = [
["Foo"],
Expand Down Expand Up @@ -848,7 +848,7 @@ end
proj = joinpath(tmp, "Project.toml")
touch(proj)
touch(joinpath(tmp, "Manifest-v1.5.toml"))
@test Base.project_file_manifest_path(proj) == nothing
@test Base.project_file_manifest_path(proj) === nothing
touch(joinpath(tmp, "Manifest.toml"))
man = basename(Base.project_file_manifest_path(proj))
@test man == "Manifest.toml"
Expand Down
14 changes: 7 additions & 7 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,17 @@ end
@testset "findfirst" begin
@test findfirst(==(1), Base.IdentityUnitRange(-1:1)) == 1
@test findfirst(isequal(3), Base.OneTo(10)) == 3
@test findfirst(==(0), Base.OneTo(10)) == nothing
@test findfirst(==(11), Base.OneTo(10)) == nothing
@test findfirst(==(0), Base.OneTo(10)) === nothing
@test findfirst(==(11), Base.OneTo(10)) === nothing
@test findfirst(==(4), Int16(3):Int16(7)) === Int(2)
@test findfirst(==(2), Int16(3):Int16(7)) == nothing
@test findfirst(isequal(8), 3:7) == nothing
@test findfirst(==(2), Int16(3):Int16(7)) === nothing
@test findfirst(isequal(8), 3:7) === nothing
@test findfirst(isequal(7), 1:2:10) == 4
@test findfirst(==(7), 1:2:10) == 4
@test findfirst(==(10), 1:2:10) == nothing
@test findfirst(==(11), 1:2:10) == nothing
@test findfirst(==(10), 1:2:10) === nothing
@test findfirst(==(11), 1:2:10) === nothing
@test findfirst(==(-7), 1:-1:-10) == 9
@test findfirst(==(2),1:-1:2) == nothing
@test findfirst(==(2),1:-1:2) === nothing
end
@testset "reverse" begin
@test reverse(reverse(1:10)) == 1:10
Expand Down
2 changes: 1 addition & 1 deletion test/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@

r = r"" * raw"a\Eb|c"
@test match(r, raw"a\Eb|c").match == raw"a\Eb|c"
@test match(r, raw"c") == nothing
@test match(r, raw"c") === nothing

# error for really incompatible options
@test_throws ArgumentError r"a" * Regex("b", Base.DEFAULT_COMPILER_OPTS & ~Base.PCRE.UCP, Base.DEFAULT_MATCH_OPTS)
Expand Down
4 changes: 2 additions & 2 deletions test/some.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

## == and isequal nothing

@test Some(1) != nothing
@test Some(nothing) != nothing
@test Some(1) !== nothing
@test Some(nothing) !== nothing
@test !isequal(Some(1), nothing)
@test !isequal(Some(nothing), nothing)

Expand Down
2 changes: 1 addition & 1 deletion test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ end
@test Cmd(`foo`, env=["A=true"]).env == ["A=true"]
@test Cmd(`foo`, env=("A"=>true,)).env == ["A=true"]
@test Cmd(`foo`, env=["A"=>true]).env == ["A=true"]
@test Cmd(`foo`, env=nothing).env == nothing
@test Cmd(`foo`, env=nothing).env === nothing

# test for interpolation of Cmd
let c = setenv(`x`, "A"=>true)
Expand Down
Loading

0 comments on commit 6d7f4a2

Please sign in to comment.