Skip to content

Commit 735554d

Browse files
authored
Merge pull request JuliaLang#17435 from JuliaLang/yyc/tests/isolate
Isolate each test in a parentless module.
2 parents 2751493 + e4b525d commit 735554d

25 files changed

+198
-151
lines changed

examples/lru_test.jl

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

3-
using LRUExample
3+
using .LRUExample
44

55
TestLRU = LRUExample.UnboundedLRU{String, String}()
66
TestBLRU = LRUExample.BoundedLRU{String, String}(1000)

test/ambiguous.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ ambig(x::Int, y::Int) = 4
99
ambig(x::Number, y) = 5
1010
# END OF LINE NUMBER SENSITIVITY
1111

12+
const curmod = current_module()
13+
const curmod_name = fullname(curmod)
14+
const curmod_str = curmod === Main ? "Main" : join(curmod_name, ".")
15+
1216
ambigs = Any[[], [3], [2,5], [], [3]]
1317

1418
mt = methods(ambig)
@@ -52,8 +56,8 @@ let err = try
5256
io = IOBuffer()
5357
Base.showerror(io, err)
5458
lines = split(takebuf_string(io), '\n')
55-
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) in Main at") ||
56-
startswith(str, " ambig(x::Integer, y) in Main at")
59+
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) in $curmod_str at") ||
60+
startswith(str, " ambig(x::Integer, y) in $curmod_str at")
5761
@test ambig_checkline(lines[2])
5862
@test ambig_checkline(lines[3])
5963
end

test/compile.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ FooBase_module = :FooBase4b3a94a1a081a8cb
2323
$Foo_module = 232
2424
$FooBase_module = 9134
2525
end
26-
using ConflictingBindings
26+
using .ConflictingBindings
2727

2828
# this environment variable would affect some error messages being tested below
2929
# so we disable it for the tests below
@@ -379,7 +379,7 @@ let module_name = string("a",randstring())
379379
code = """module $(module_name)\nend\n"""
380380
write(file_name, code)
381381
reload(module_name)
382-
@test typeof(eval(Symbol(module_name))) == Module
382+
@test isa(eval(Main, Symbol(module_name)), Module)
383383
deleteat!(LOAD_PATH,1)
384384
rm(file_name)
385385
end

test/core.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# test core language features
44
const Bottom = Union{}
5+
const curmod = current_module()
6+
const curmod_name = fullname(curmod)
7+
const curmod_prefix = "$(["$m." for m in curmod_name]...)"
58

69
macro testintersect(args...)
710
_testintersect(args...)
@@ -1187,8 +1190,8 @@ immutable Foo2509; foo::Int; end
11871190

11881191
# issue #2517
11891192
immutable Foo2517; end
1190-
@test repr(Foo2517()) == "Foo2517()"
1191-
@test repr(Array{Foo2517}(1)) == "Foo2517[Foo2517()]"
1193+
@test repr(Foo2517()) == "$(curmod_prefix)Foo2517()"
1194+
@test repr(Array{Foo2517}(1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]"
11921195
@test Foo2517() === Foo2517()
11931196

11941197
# issue #1474
@@ -2436,7 +2439,7 @@ let x,y,f
24362439
y = f() # invoke llvm constant folding
24372440
@test Int(0x468ace) === Int(y)
24382441
@test x !== y
2439-
@test string(y) == "Int24(0x468ace)"
2442+
@test string(y) == "$(curmod_prefix)Int24(0x468ace)"
24402443
end
24412444

24422445
# issue #10570
@@ -3066,7 +3069,7 @@ x7864 = 1
30663069
end
30673070

30683071
@test_throws UndefVarError x7864
3069-
using M7864
3072+
using .M7864
30703073
@test x7864 == 1
30713074

30723075
# issue #11715

test/dates/adjusters.jl

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

3-
module DatesAdjustersTests
4-
using Base.Test
53
#trunc
64
dt = Dates.Date(2012,12,21)
75
@test trunc(dt,Dates.Year) == Dates.Date(2012)
@@ -460,4 +458,3 @@ end) == 251
460458
end
461459
return sum == 15
462460
end) == 15 # On average, there's one of those months every year
463-
end

test/dates/io.jl

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

3-
module DatesIo
4-
using Base.Test
53
# Test string/show representation of Date
64
@test string(Dates.Date(1,1,1)) == "0001-01-01" # January 1st, 1 AD/CE
75
@test sprint(show, Dates.Date(1,1,1)) == "0001-01-01"
@@ -366,5 +364,3 @@ end
366364
@test Dates.Date("Apr 01 2014", "uuu dd yyyy") == Dates.Date(2014,4,1)
367365
@test_throws ArgumentError Dates.Date("Apr 01 xx 2014", "uuu dd zz yyyy")
368366
@test_throws ArgumentError Dates.Date("Apr 01 xx 2014", "uuu dd yyyy")
369-
370-
end

test/dates/periods.jl

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

3-
module DatesPeriodTesting
4-
using Base.Test
53
# Period testing
64
@test -Dates.Year(1) == Dates.Year(-1)
75
@test Dates.Year(1) > Dates.Year(0)
@@ -382,4 +380,3 @@ cpa = [1y+1s 1m+1s 1w+1s 1d+1s; 1h+1s 1mi+1s 2m+1s 1s+1ms]
382380

383381
@test [1y+1s 1m+1s; 1w+1s 1d+1s] + [1y+1h 1y+1mi; 1y+1s 1y+1ms] == [2y+1h+1s 1y+1m+1mi+1s; 1y+1w+2s 1y+1d+1s+1ms]
384382
@test [1y+1s 1m+1s; 1w+1s 1d+1s] - [1y+1h 1y+1mi; 1y+1s 1y+1ms] == [1s-1h 1m+1s-1y-1mi; 1w-1y 1d+1s-1y-1ms]
385-
end

test/dates/types.jl

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

3-
module DatesTypesTests
4-
using Base.Test
53
# Date internal algorithms
64
@test Dates.totaldays(0,2,28) == -307
75
@test Dates.totaldays(0,2,29) == -306
@@ -173,4 +171,3 @@ ms = Dates.Millisecond(1)
173171

174172
@test isfinite(Dates.Date)
175173
@test isfinite(Dates.DateTime)
176-
end

test/docs.jl

+34-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import Base.Docs: meta, @var, DocStr, parsedoc
44

5+
const curmod = current_module()
6+
const curmod_name = fullname(curmod)
7+
const curmod_prefix = "$(["$m." for m in curmod_name]...)"
8+
59
# Test helpers.
610
function docstrings_equal(d1, d2)
711
io1 = IOBuffer()
@@ -450,10 +454,13 @@ end
450454
end
451455

452456
let T = meta(DocVars)[@var(DocVars.T)],
453-
S = meta(DocVars)[@var(DocVars.S)]
457+
S = meta(DocVars)[@var(DocVars.S)],
458+
Tname = Markdown.parse("```\n$(curmod_prefix)DocVars.T\n```"),
459+
Sname = Markdown.parse("```\n$(curmod_prefix)DocVars.S\n```")
460+
# Splicing the expression directly doesn't work
454461
@test docstrings_equal(T.docs[Union{}],
455462
doc"""
456-
DocVars.T
463+
$Tname
457464
458465
# Fields
459466
@@ -464,7 +471,7 @@ let T = meta(DocVars)[@var(DocVars.T)],
464471
)
465472
@test docstrings_equal(S.docs[Union{}],
466473
doc"""
467-
DocVars.S
474+
$Sname
468475
469476
"""
470477
)
@@ -545,11 +552,12 @@ end
545552

546553
@doc "This should document @m1... since its the result of expansion" @m2_11993
547554
@test (@doc @m1_11993) !== nothing
548-
let d = (@doc :@m2_11993)
555+
let d = (@doc :@m2_11993),
556+
macro_doc = Markdown.parse("`$(curmod_prefix)@m2_11993` is a macro.")
549557
@test docstring_startswith(d, doc"""
550558
No documentation found.
551559
552-
`@m2_11993` is a macro.""")
560+
$macro_doc""")
553561
end
554562

555563
@doc "Now @m2... should be documented" :@m2_11993
@@ -707,56 +715,60 @@ undocumented(x,y) = 3
707715

708716
end
709717

710-
@test docstrings_equal(@doc(Undocumented.bindingdoesnotexist), doc"""
718+
doc_str = Markdown.parse("""
711719
No documentation found.
712720
713-
Binding `Undocumented.bindingdoesnotexist` does not exist.
721+
Binding `$(curmod_prefix)Undocumented.bindingdoesnotexist` does not exist.
714722
""")
723+
@test docstrings_equal(@doc(Undocumented.bindingdoesnotexist), doc"$doc_str")
715724

716-
@test docstrings_equal(@doc(Undocumented.A), doc"""
725+
doc_str = Markdown.parse("""
717726
No documentation found.
718727
719728
**Summary:**
720729
```
721-
abstract Undocumented.A <: Any
730+
abstract $(curmod_prefix)Undocumented.A <: Any
722731
```
723732
724733
**Subtypes:**
725734
```
726-
Undocumented.B
727-
Undocumented.C
735+
$(curmod_prefix)Undocumented.B
736+
$(curmod_prefix)Undocumented.C
728737
```
729738
""")
739+
@test docstrings_equal(@doc(Undocumented.A), doc"$doc_str")
730740

731-
@test docstrings_equal(@doc(Undocumented.B), doc"""
741+
doc_str = Markdown.parse("""
732742
No documentation found.
733743
734744
**Summary:**
735745
```
736-
abstract Undocumented.B <: Undocumented.A
746+
abstract $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A
737747
```
738748
739749
**Subtypes:**
740750
```
741-
Undocumented.D
751+
$(curmod_prefix)Undocumented.D
742752
```
743753
""")
754+
@test docstrings_equal(@doc(Undocumented.B), doc"$doc_str")
744755

745-
@test docstrings_equal(@doc(Undocumented.C), doc"""
756+
doc_str = Markdown.parse("""
746757
No documentation found.
747758
748759
**Summary:**
749760
```
750-
type Undocumented.C <: Undocumented.A
761+
type $(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A
751762
```
752763
""")
764+
@test docstrings_equal(@doc(Undocumented.C), doc"$doc_str")
753765

754-
@test docstrings_equal(@doc(Undocumented.D), doc"""
766+
doc_str = Markdown.parse("""
755767
No documentation found.
756768
757769
**Summary:**
758770
```
759-
immutable Undocumented.D <: Undocumented.B
771+
immutable $(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B
760772
```
761773
762774
**Fields:**
@@ -766,14 +778,15 @@ two :: String
766778
three :: Float64
767779
```
768780
""")
781+
@test docstrings_equal(@doc(Undocumented.D), doc"$doc_str")
769782

770783
let d = @doc Undocumented.f
771784
io = IOBuffer()
772785
show(io, MIME"text/markdown"(), d)
773786
@test startswith(takebuf_string(io),"""
774787
No documentation found.
775788
776-
`Undocumented.f` is a `Function`.
789+
`$(curmod_prefix)Undocumented.f` is a `Function`.
777790
""")
778791
end
779792

@@ -783,7 +796,7 @@ let d = @doc Undocumented.undocumented
783796
@test startswith(takebuf_string(io), """
784797
No documentation found.
785798
786-
`Undocumented.undocumented` is a `Function`.
799+
`$(curmod_prefix)Undocumented.undocumented` is a `Function`.
787800
""")
788801
end
789802

@@ -862,7 +875,7 @@ let x = Binding(Base, :bindingdoesnotexist)
862875
@test @var(Base.bindingdoesnotexist) == x
863876
end
864877

865-
let x = Binding(Main, :bindingdoesnotexist)
878+
let x = Binding(current_module(), :bindingdoesnotexist)
866879
@test defined(x) == false
867880
@test @var(bindingdoesnotexist) == x
868881
end

test/enums.jl

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

3-
module TestEnums
3+
const curmod = current_module()
4+
const curmod_name = fullname(curmod)
5+
const curmod_prefix = "$(["$m." for m in curmod_name]...)"
46

57
using Base.Test
68

@@ -156,7 +158,7 @@ end
156158
@test string(apple) == "apple"
157159

158160
@test reprmime("text/plain", Fruit) == "Enum $(string(Fruit)):\napple = 0\norange = 1\nkiwi = 2"
159-
@test reprmime("text/plain", orange) == "orange::TestEnums.Fruit = 1"
161+
@test reprmime("text/plain", orange) == "orange::$(curmod_prefix)Fruit = 1"
160162

161163
@enum LogLevel DEBUG INFO WARN ERROR CRITICAL
162164
@test DEBUG < CRITICAL
@@ -167,5 +169,3 @@ let b = IOBuffer()
167169
seekstart(b)
168170
@test deserialize(b) === apple
169171
end
170-
171-
end # module

test/examples.jl

+10-9
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ if is_unix()
4545
end
4646

4747
dc_path = joinpath(dir, "dictchannel.jl")
48-
myid() == 1 || include(dc_path)
49-
5048
# Run the remote on pid 1, since runtests may terminate workers
5149
# at any time depending on memory usage
52-
remotecall_fetch(1, dc_path) do f
53-
include(f)
54-
nothing
50+
main_ex = quote
51+
myid() == 1 || include($dc_path)
52+
remotecall_fetch(1, $dc_path) do f
53+
include(f)
54+
nothing
55+
end
56+
RemoteChannel(()->DictChannel(), 1)
5557
end
56-
dc=RemoteChannel(()->DictChannel(), 1)
57-
@test typeof(dc) == RemoteChannel{DictChannel}
58+
dc = eval(Main, main_ex)
59+
@test typeof(dc) == RemoteChannel{Main.DictChannel}
5860

5961
@test isready(dc) == false
6062
put!(dc, 1, 2)
@@ -82,8 +84,7 @@ catch
8284
end
8385

8486
if !zmq_found
85-
eval(parse("module ZMQ end"))
87+
eval(Main, parse("module ZMQ end"))
8688
end
8789

8890
include(joinpath(dir, "clustermanager/0mq/ZMQCM.jl"))
89-

test/libgit2.jl

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

3-
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
3+
isdefined(Main, :TestHelpers) || eval(Main, :(include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))))
44
using TestHelpers
55

66
const LIBGIT2_MIN_VER = v"0.23.0"

test/lineedit.jl

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

33
using Base.LineEdit
4-
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
4+
isdefined(Main, :TestHelpers) || eval(Main, :(include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))))
55
using TestHelpers
66

77
function run_test(d,buf)

test/misc.jl

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ end
117117
@test gc_enable(true)
118118

119119
# test methodswith
120+
# `methodswith` relies on exported symbols
121+
export func4union, Base
120122
immutable NoMethodHasThisType end
121123
@test isempty(methodswith(NoMethodHasThisType))
122124
@test !isempty(methodswith(Int))

0 commit comments

Comments
 (0)