Skip to content

Commit

Permalink
Isolate each test in an parentless module.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jul 15, 2016
1 parent 54a6490 commit 33e977f
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 110 deletions.
2 changes: 1 addition & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function _subtypes(m::Module, x::DataType, sts=Set(), visited=Set())
push!(visited, m)
for s in names(m,true)
if isdefined(m,s)
t = eval(m,s)
t = getfield(m, s)
if isa(t, DataType) && t.name.name == s && supertype(t).name == x.name
ti = typeintersect(t, x)
ti != Bottom && push!(sts, ti)
Expand Down
2 changes: 1 addition & 1 deletion base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function showerror(io::IO, ex::MethodError)
name = ft.name.mt.name
f_is_function = false
kwargs = Any[]
if startswith(string(ft.name), "#kw#")
if startswith(string(ft.name.name), "#kw#")
f = ex.args[2]
ft = typeof(f)
name = ft.name.mt.name
Expand Down
2 changes: 1 addition & 1 deletion examples/lru_test.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using LRUExample
using .LRUExample

TestLRU = LRUExample.UnboundedLRU{String, String}()
TestBLRU = LRUExample.BoundedLRU{String, String}(1000)
Expand Down
11 changes: 6 additions & 5 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# test core language features

const Bottom = Union{}
const name_prefix = "$(["$m." for m in fullname(current_module())]...)"

macro testintersect(args...)
_testintersect(args...)
Expand Down Expand Up @@ -1184,8 +1185,8 @@ immutable Foo2509; foo::Int; end

# issue #2517
immutable Foo2517; end
@test repr(Foo2517()) == "Foo2517()"
@test repr(Array{Foo2517}(1)) == "Foo2517[Foo2517()]"
@test repr(Foo2517()) == "$(name_prefix)Foo2517()"
@test repr(Array{Foo2517}(1)) == "$(name_prefix)Foo2517[$(name_prefix)Foo2517()]"
@test Foo2517() === Foo2517()

# issue #1474
Expand Down Expand Up @@ -2451,7 +2452,7 @@ let x,y,f
y = f() # invoke llvm constant folding
@test Int(0x468ace) === Int(y)
@test x !== y
@test string(y) == "Int24(0x468ace)"
@test string(y) == "$(name_prefix)Int24(0x468ace)"
end

# issue #10570
Expand Down Expand Up @@ -3077,7 +3078,7 @@ x7864 = 1
end

@test_throws UndefVarError x7864
using M7864
using .M7864
@test x7864 == 1

# issue #11715
Expand Down Expand Up @@ -4399,7 +4400,7 @@ module A15838
const x = :a
end
module B15838
import A15838.@f
import ..A15838.@f
macro f(x); return :x; end
const x = :b
end
Expand Down
53 changes: 32 additions & 21 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

const name_prefix = "$(["$m." for m in fullname(current_module())]...)"

# Test helpers.
function docstrings_equal(d1, d2)
io1 = IOBuffer()
Expand Down Expand Up @@ -450,10 +452,13 @@ end
end

let T = meta(DocVars)[@var(DocVars.T)],
S = meta(DocVars)[@var(DocVars.S)]
S = meta(DocVars)[@var(DocVars.S)],
Tname = Markdown.parse("```\n$(name_prefix)DocVars.T\n```"),
Sname = Markdown.parse("```\n$(name_prefix)DocVars.S\n```")
# Splicing the expression directly doesn't work
@test docstrings_equal(T.docs[Union{}],
doc"""
DocVars.T
$Tname
# Fields
Expand All @@ -464,7 +469,7 @@ let T = meta(DocVars)[@var(DocVars.T)],
)
@test docstrings_equal(S.docs[Union{}],
doc"""
DocVars.S
$Sname
"""
)
Expand Down Expand Up @@ -545,11 +550,12 @@ end

@doc "This should document @m1... since its the result of expansion" @m2_11993
@test (@doc @m1_11993) !== nothing
let d = (@doc :@m2_11993)
let d = (@doc :@m2_11993),
macro_doc = Markdown.parse("`$(name_prefix)@m2_11993` is a macro.")
@test docstring_startswith(d, doc"""
No documentation found.
`@m2_11993` is a macro.""")
$macro_doc""")
end

@doc "Now @m2... should be documented" :@m2_11993
Expand Down Expand Up @@ -707,56 +713,60 @@ undocumented(x,y) = 3

end

@test docstrings_equal(@doc(Undocumented.bindingdoesnotexist), doc"""
doc_str = Markdown.parse("""
No documentation found.
Binding `Undocumented.bindingdoesnotexist` does not exist.
Binding `$(name_prefix)Undocumented.bindingdoesnotexist` does not exist.
""")
@test docstrings_equal(@doc(Undocumented.bindingdoesnotexist), doc"$doc_str")

@test docstrings_equal(@doc(Undocumented.A), doc"""
doc_str = Markdown.parse("""
No documentation found.
**Summary:**
```
abstract Undocumented.A <: Any
abstract $(name_prefix)Undocumented.A <: Any
```
**Subtypes:**
```
Undocumented.B
Undocumented.C
$(name_prefix)Undocumented.B
$(name_prefix)Undocumented.C
```
""")
@test docstrings_equal(@doc(Undocumented.A), doc"$doc_str")

@test docstrings_equal(@doc(Undocumented.B), doc"""
doc_str = Markdown.parse("""
No documentation found.
**Summary:**
```
abstract Undocumented.B <: Undocumented.A
abstract $(name_prefix)Undocumented.B <: $(name_prefix)Undocumented.A
```
**Subtypes:**
```
Undocumented.D
$(name_prefix)Undocumented.D
```
""")
@test docstrings_equal(@doc(Undocumented.B), doc"$doc_str")

@test docstrings_equal(@doc(Undocumented.C), doc"""
doc_str = Markdown.parse("""
No documentation found.
**Summary:**
```
type Undocumented.C <: Undocumented.A
type $(name_prefix)Undocumented.C <: $(name_prefix)Undocumented.A
```
""")
@test docstrings_equal(@doc(Undocumented.C), doc"$doc_str")

@test docstrings_equal(@doc(Undocumented.D), doc"""
doc_str = Markdown.parse("""
No documentation found.
**Summary:**
```
immutable Undocumented.D <: Undocumented.B
immutable $(name_prefix)Undocumented.D <: $(name_prefix)Undocumented.B
```
**Fields:**
Expand All @@ -766,14 +776,15 @@ two :: String
three :: Float64
```
""")
@test docstrings_equal(@doc(Undocumented.D), doc"$doc_str")

let d = @doc Undocumented.f
io = IOBuffer()
show(io, MIME"text/markdown"(), d)
@test startswith(takebuf_string(io),"""
No documentation found.
`Undocumented.f` is a `Function`.
`$(name_prefix)Undocumented.f` is a `Function`.
""")
end

Expand All @@ -783,7 +794,7 @@ let d = @doc Undocumented.undocumented
@test startswith(takebuf_string(io), """
No documentation found.
`Undocumented.undocumented` is a `Function`.
`$(name_prefix)Undocumented.undocumented` is a `Function`.
""")
end

Expand Down Expand Up @@ -862,7 +873,7 @@ let x = Binding(Base, :bindingdoesnotexist)
@test @var(Base.bindingdoesnotexist) == x
end

let x = Binding(Main, :bindingdoesnotexist)
let x = Binding(current_module(), :bindingdoesnotexist)
@test defined(x) == false
@test @var(bindingdoesnotexist) == x
end
Expand Down
6 changes: 2 additions & 4 deletions test/enums.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

module TestEnums
const name_prefix = "$(["$m." for m in fullname(current_module())]...)"

using Base.Test

Expand Down Expand Up @@ -156,7 +156,7 @@ end
@test string(apple) == "apple"

@test reprmime("text/plain", Fruit) == "Enum $(string(Fruit)):\napple = 0\norange = 1\nkiwi = 2"
@test reprmime("text/plain", orange) == "orange::TestEnums.Fruit = 1"
@test reprmime("text/plain", orange) == "orange::$(name_prefix)Fruit = 1"

@enum LogLevel DEBUG INFO WARN ERROR CRITICAL
@test DEBUG < CRITICAL
Expand All @@ -167,5 +167,3 @@ let b = IOBuffer()
seekstart(b)
@test deserialize(b) === apple
end

end # module
3 changes: 1 addition & 2 deletions test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ catch
end

if !zmq_found
eval(parse("module ZMQ end"))
eval(Main, parse("module ZMQ end"))
end

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

2 changes: 1 addition & 1 deletion test/lineedit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Base.LineEdit
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
using TestHelpers
using .TestHelpers

a_foo = 0

Expand Down
2 changes: 2 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ end
@test gc_enable(true)

# test methodswith
# `methodwith` relies on exported symbols
export func4union, Base
immutable NoMethodHasThisType end
@test isempty(methodswith(NoMethodHasThisType))
@test !isempty(methodswith(Int))
Expand Down
3 changes: 2 additions & 1 deletion test/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ for (i, T) in enumerate(types)
end

module NullableTestEnum
const name_prefix = "$(["$m." for m in fullname(current_module())]...)"
io = IOBuffer()
@enum TestEnum a b
show(io, Nullable(a))
Base.Test.@test takebuf_string(io) == "Nullable{NullableTestEnum.TestEnum}(a)"
Base.Test.@test takebuf_string(io) == "Nullable{$(name_prefix)TestEnum}(a)"
end

# showcompact(io::IO, x::Nullable)
Expand Down
2 changes: 1 addition & 1 deletion test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ indsoffset(i::Integer) = 0

end

using OAs
using .OAs

let
# Basics
Expand Down
14 changes: 10 additions & 4 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ not_const = 1
## find bindings tests
@test ccall(:jl_get_module_of_binding, Any, (Any, Any), Base, :sin)==Base

const curmod = current_module()
const curmod_name = fullname(curmod)

module TestMod7648
using Base.Test
import ..curmod_name, ..curmod
export a9475, c7648, foo7648

const c7648 = 8
Expand All @@ -173,14 +177,16 @@ foo7648(x) = x
module TestModSub9475
using Base.Test
using ..TestMod7648
import ..curmod_name
export a9475
a9475 = 5
b9475 = 7
let
@test Base.binding_module(:a9475)==current_module()
@test Base.binding_module(:c7648)==TestMod7648
@test Base.module_name(current_module())==:TestModSub9475
@test Base.fullname(current_module())==(:TestMod7648, :TestModSub9475)
@test Base.fullname(current_module()) == (curmod_name..., :TestMod7648,
:TestModSub9475)
@test Base.module_parent(current_module())==TestMod7648
end
end # module TestModSub9475
Expand All @@ -191,7 +197,7 @@ let
@test Base.binding_module(:d7648)==current_module()
@test Base.binding_module(:a9475)==TestModSub9475
@test Base.module_name(current_module())==:TestMod7648
@test Base.module_parent(current_module())==Main
@test Base.module_parent(current_module())==curmod
end
end # module TestMod7648

Expand All @@ -205,7 +211,7 @@ let
end

let
using TestMod7648
using .TestMod7648
@test Base.binding_module(:a9475)==TestMod7648.TestModSub9475
@test Base.binding_module(:c7648)==TestMod7648
@test Base.function_name(foo7648)==:foo7648
Expand Down Expand Up @@ -326,7 +332,7 @@ end
end

let
using MacroTest
using .MacroTest
a = 1
m = getfield(current_module(), Symbol("@macrotest"))
@test which(m, Tuple{Int,Symbol})==@which @macrotest 1 a
Expand Down
9 changes: 7 additions & 2 deletions test/repl.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

const name_prefix = "$(["$m." for m in fullname(current_module())]...)"

# REPL tests
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
using TestHelpers
using .TestHelpers
import Base: REPL, LineEdit

function fake_repl()
Expand Down Expand Up @@ -38,12 +40,15 @@ if !is_windows() || Sys.windows_version() >= Sys.WINDOWS_VISTA_VER
Base.REPL.run_repl(repl)
end

sendrepl(cmd) = write(stdin_write,"inc || wait(b); r = $cmd; notify(c); r\r")
sendrepl(cmd) = begin
write(stdin_write,"$(name_prefix)inc || wait($(name_prefix)b); r = $cmd; notify($(name_prefix)c); r\r")
end

inc = false
b = Condition()
c = Condition()
sendrepl("\"Hello REPL\"")

inc=true
begin
notify(b)
Expand Down
Loading

0 comments on commit 33e977f

Please sign in to comment.