Skip to content

Commit ca7a692

Browse files
authored
split out TestHelpers into separate parts (#28292)
1 parent 4b8c697 commit ca7a692

22 files changed

+127
-120
lines changed

stdlib/LibGit2/test/libgit2.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ using Test
77
using Random, Serialization, Sockets
88

99
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
10-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
11-
import .Main.TestHelpers: with_fake_pty
10+
isdefined(Main, :FakePTYs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FakePTYs.jl"))
11+
import .Main.FakePTYs: with_fake_pty
1212

1313
function challenge_prompt(code::Expr, challenges; timeout::Integer=60, debug::Bool=true)
1414
input_code = tempname()

stdlib/LinearAlgebra/test/adjtrans.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ end
482482
end
483483

484484
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
485-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
486-
using .Main.TestHelpers.OAs
485+
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
486+
using .Main.OffsetArrays
487487

488488
@testset "offset axes" begin
489489
s = Base.Slice(-3:3)'

stdlib/LinearAlgebra/test/triangular.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,10 @@ end
519519

520520
# dimensional correctness:
521521
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
522-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
523-
using .Main.TestHelpers: Furlong
522+
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
523+
using .Main.Furlongs
524+
LinearAlgebra.sylvester(a::Furlong,b::Furlong,c::Furlong) = -c / (a + b)
525+
524526
let A = UpperTriangular([Furlong(1) Furlong(4); Furlong(0) Furlong(1)])
525527
@test sqrt(A) == Furlong{1//2}.(UpperTriangular([1 2; 0 1]))
526528
end

stdlib/REPL/test/lineedit.jl

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import REPL.LineEdit: edit_insert, buffer, content, setmark, getmark, region
88
include("FakeTerminals.jl")
99
import .FakeTerminals.FakeTerminal
1010

11-
const BASE_TEST_PATH = joinpath(@__DIR__, "..", "..", "..", "test")
12-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
13-
import .Main.TestHelpers
14-
1511
# no need to have animation in tests
1612
REPL.GlobalOptions.region_animation_duration=0.001
1713

stdlib/REPL/test/repl.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import REPL.LineEdit
77
using Markdown
88

99
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
10-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
11-
import .Main.TestHelpers
10+
isdefined(Main, :FakePTYs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FakePTYs.jl"))
11+
import .Main.FakePTYs: with_fake_pty
1212

1313
# For curmod_*
1414
include(joinpath(BASE_TEST_PATH, "testenv.jl"))
@@ -719,7 +719,7 @@ ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 1)
719719
let exename = Base.julia_cmd()
720720
# Test REPL in dumb mode
721721
if !Sys.iswindows()
722-
TestHelpers.with_fake_pty() do slave, master
722+
with_fake_pty() do slave, master
723723
nENV = copy(ENV)
724724
nENV["TERM"] = "dumb"
725725
p = run(setenv(`$exename --startup-file=no -q`,nENV),slave,slave,slave,wait=false)

stdlib/Random/test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using Test, SparseArrays
44
using Test: guardsrand
55

66
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
7-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
8-
using .Main.TestHelpers.OAs
7+
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
8+
using .Main.OffsetArrays
99

1010
using Random
1111
using Random.DSFMT

stdlib/Statistics/test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ end
505505

506506
# dimensional correctness
507507
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
508-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath($(BASE_TEST_PATH), "TestHelpers.jl"))
509-
using .Main.TestHelpers: Furlong
508+
isdefined(Main, :Furlongs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "Furlongs.jl"))
509+
using .Main.Furlongs
510510

511511
Statistics.middle(x::Furlong{p}) where {p} = Furlong{p}(middle(x.val))
512512
Statistics.middle(x::Furlong{p}, y::Furlong{p}) where {p} = Furlong{p}(middle(x.val, y.val))

test/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include $(JULIAHOME)/Make.inc
88
TESTGROUPS = unicode strings compiler
99
TESTS = all stdlib $(TESTGROUPS) \
1010
$(patsubst $(STDLIBDIR)/%/,%,$(dir $(wildcard $(STDLIBDIR)/*/.))) \
11-
$(filter-out TestHelpers runtests testdefs, \
11+
$(filter-out runtests testdefs, \
1212
$(patsubst $(SRCDIR)/%.jl,%,$(wildcard $(SRCDIR)/*.jl))) \
1313
$(foreach group,$(TESTGROUPS), \
1414
$(patsubst $(SRCDIR)/%.jl,%,$(wildcard $(SRCDIR)/$(group)/*.jl)))

test/arrayops.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
# Array test
4-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
5-
using .Main.TestHelpers.OAs
4+
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
5+
using .Main.OffsetArrays
66
using SparseArrays
77

88
using Random, LinearAlgebra

test/enums.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ include("testenv.jl")
55

66
using Test, Serialization
77

8-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
9-
using Main.TestHelpers
8+
isdefined(Main, :MacroCalls) || @eval Main include("testhelpers/MacroCalls.jl")
9+
using Main.MacroCalls
1010

1111
@test_throws MethodError convert(Enum, 1.0)
1212

test/logging.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import Base.CoreLogging: BelowMinLevel, Debug, Info, Warn, Error,
77
import Test: collect_test_logs, TestLogger
88
using Base.Printf: @sprintf
99

10-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
11-
using Main.TestHelpers
10+
isdefined(Main, :MacroCalls) || @eval Main include("testhelpers/MacroCalls.jl")
11+
using Main.MacroCalls
1212

1313
#-------------------------------------------------------------------------------
1414
@testset "Logging" begin

test/math.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,8 @@ end
978978
end
979979
end
980980

981-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
982-
using .Main.TestHelpers: Furlong
981+
isdefined(Main, :Furlongs) || @eval Main include("testhelpers/Furlongs.jl")
982+
using .Main.Furlongs
983983
@test hypot(Furlong(0), Furlong(0)) == Furlong(0.0)
984984
@test hypot(Furlong(3), Furlong(4)) == Furlong(5.0)
985985
@test hypot(Furlong(NaN), Furlong(Inf)) == Furlong(Inf)

test/offsetarray.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
4-
using .Main.TestHelpers.OAs
3+
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
4+
using .Main.OffsetArrays
55
using DelimitedFiles
66
using Random
77
using LinearAlgebra
88
using Statistics
99

10-
const OAs_name = join(fullname(OAs), ".")
10+
const OAs_name = join(fullname(OffsetArrays), ".")
1111

1212
let
1313
# Basics

test/ranges.jl

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Dates, Random
4-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
4+
isdefined(Main, :PhysQuantities) || @eval Main include("testhelpers/PhysQuantities.jl")
5+
using .Main.PhysQuantities
56

67
# Compare precision in a manner sensitive to subnormals, which lose
78
# precision compared to widening.
@@ -187,10 +188,10 @@ end
187188
@test isnan(Float64(x0/0))
188189
@test isnan(Float64(x0/0.0))
189190

190-
x = Base.TwicePrecision(Main.TestHelpers.PhysQuantity{1}(4.0))
191-
@test x.hi*2 === Main.TestHelpers.PhysQuantity{1}(8.0)
191+
x = Base.TwicePrecision(PhysQuantity{1}(4.0))
192+
@test x.hi*2 === PhysQuantity{1}(8.0)
192193
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x*2 # not a MethodError for convert
193-
@test x.hi/2 === Main.TestHelpers.PhysQuantity{1}(2.0)
194+
@test x.hi/2 === PhysQuantity{1}(2.0)
194195
@test_throws ErrorException("Int is incommensurate with PhysQuantity") x/2
195196
end
196197
@testset "ranges" begin
@@ -1224,8 +1225,9 @@ Base.rem(x, y::NotReal) = rem(x, y.val)
12241225
Base.isless(x, y::NotReal) = isless(x, y.val)
12251226
@test (:)(1, NotReal(1), 5) isa StepRange{Int,NotReal}
12261227

1227-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
1228-
using .Main.TestHelpers: Furlong
1228+
isdefined(Main, :Furlongs) || @eval Main include("testhelpers/Furlongs.jl")
1229+
using .Main.Furlongs
1230+
12291231
@testset "dimensional correctness" begin
12301232
@test length(Vector(Furlong(2):Furlong(10))) == 9
12311233
@test length(range(Furlong(2), length=9)) == 9

test/reduce.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Random
4-
isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
5-
using .Main.TestHelpers.OAs
4+
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
5+
using .Main.OffsetArrays
66

77
# fold(l|r) & mapfold(l|r)
88
@test foldl(+, Int64[]) === Int64(0) # In reference to issues #7465/#20144 (PR #20160)

test/reinterpretarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Test
4-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
5-
using .Main.TestHelpers.OAs
4+
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
5+
using .Main.OffsetArrays
66

77
A = Int64[1, 2, 3, 4]
88
B = Complex{Int64}[5+6im, 7+8im, 9+10im]

test/sets.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
# Set tests
4-
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
5-
using .Main.TestHelpers.OAs
4+
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
5+
using .Main.OffsetArrays
66

77
using Dates
88

test/testhelpers/FakePTYs.jl

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
module FakePTYs
4+
5+
function open_fake_pty()
6+
@static if Sys.iswindows()
7+
error("Unable to create a fake PTY in Windows")
8+
end
9+
10+
O_RDWR = Base.Filesystem.JL_O_RDWR
11+
O_NOCTTY = Base.Filesystem.JL_O_NOCTTY
12+
13+
fdm = ccall(:posix_openpt, Cint, (Cint,), O_RDWR|O_NOCTTY)
14+
fdm == -1 && error("Failed to open PTY master")
15+
rc = ccall(:grantpt, Cint, (Cint,), fdm)
16+
rc != 0 && error("grantpt failed")
17+
rc = ccall(:unlockpt, Cint, (Cint,), fdm)
18+
rc != 0 && error("unlockpt")
19+
20+
fds = ccall(:open, Cint, (Ptr{UInt8}, Cint),
21+
ccall(:ptsname, Ptr{UInt8}, (Cint,), fdm), O_RDWR|O_NOCTTY)
22+
23+
# slave
24+
slave = RawFD(fds)
25+
master = Base.TTY(RawFD(fdm); readable = true)
26+
slave, master
27+
end
28+
29+
function with_fake_pty(f)
30+
slave, master = open_fake_pty()
31+
try
32+
f(slave, master)
33+
finally
34+
ccall(:close,Cint,(Cint,),slave) # XXX: this causes the kernel to throw away all unread data on the pty
35+
close(master)
36+
end
37+
end
38+
39+
end

test/dimensionful.jl test/testhelpers/Furlongs.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
module Furlongs
4+
5+
export Furlong
6+
37
# Here we implement a minimal dimensionful type Furlong, which is used
4-
# to test dimensional correctness of various functions in Base. Furlong
5-
# is exported by the TestHelpers module.
8+
# to test dimensional correctness of various functions in Base.
69

710
# represents a quantity in furlongs^p
811
struct Furlong{p,T<:Number} <: Number
@@ -34,8 +37,6 @@ canonical_p(p) = isinteger(p) ? Int(p) : Rational{Int}(p)
3437
Base.abs(x::Furlong{p}) where {p} = Furlong{p}(abs(x.val))
3538
@generated Base.abs2(x::Furlong{p}) where {p} = :(Furlong{$(canonical_p(2p))}(abs2(x.val)))
3639
@generated Base.inv(x::Furlong{p}) where {p} = :(Furlong{$(canonical_p(-p))}(inv(x.val)))
37-
import LinearAlgebra: sylvester
38-
sylvester(a::Furlong,b::Furlong,c::Furlong) = -c / (a + b)
3940

4041
for f in (:isfinite, :isnan, :isreal, :isinf)
4142
@eval Base.$f(x::Furlong) = $f(x.val)
@@ -76,3 +77,5 @@ for op in (:rem, :mod)
7677
end
7778
end
7879
Base.sqrt(x::Furlong) = _div(sqrt(x.val), x, Val(2))
80+
81+
end

test/testhelpers/MacroCalls.jl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module MacroCalls
2+
3+
export @macrocall
4+
5+
macro macrocall(ex)
6+
@assert Meta.isexpr(ex, :macrocall)
7+
ex.head = :call
8+
for i in 2:length(ex.args)
9+
ex.args[i] = QuoteNode(ex.args[i])
10+
end
11+
insert!(ex.args, 3, __module__)
12+
return esc(ex)
13+
end
14+
15+
end

0 commit comments

Comments
 (0)