From aca82a6e51c51893edd22cb42608f4312067d574 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 15 Jul 2016 08:55:44 -0400 Subject: [PATCH] Isolate each test in an parentless module. --- base/reflection.jl | 2 +- base/replutil.jl | 2 +- examples/lru_test.jl | 2 +- test/compile.jl | 2 +- test/core.jl | 11 +++++---- test/docs.jl | 53 ++++++++++++++++++++++++---------------- test/enums.jl | 6 ++--- test/examples.jl | 3 +-- test/lineedit.jl | 2 +- test/misc.jl | 2 ++ test/nullable.jl | 3 ++- test/offsetarray.jl | 2 +- test/reflection.jl | 14 ++++++++--- test/repl.jl | 9 +++++-- test/replcompletions.jl | 28 ++++++++++++--------- test/replutil.jl | 54 +++++++++++++++++++++-------------------- test/runtests.jl | 4 ++- test/show.jl | 10 +++++--- test/testdefs.jl | 26 +++++++++++++++++--- 19 files changed, 144 insertions(+), 91 deletions(-) diff --git a/base/reflection.jl b/base/reflection.jl index 36b8ad34a23147..c81471b0801ef1 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -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) diff --git a/base/replutil.jl b/base/replutil.jl index edbc2863e53a9c..478b8cfe4c3e89 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -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 diff --git a/examples/lru_test.jl b/examples/lru_test.jl index 57fca9e0979801..92117f027ba5e6 100644 --- a/examples/lru_test.jl +++ b/examples/lru_test.jl @@ -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) diff --git a/test/compile.jl b/test/compile.jl index b0170a3015ccce..2d6f10724f0c67 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -229,7 +229,7 @@ let module_name = string("a",randstring()) code = """module $(module_name)\nend\n""" write(file_name, code) reload(module_name) - @test typeof(eval(Symbol(module_name))) == Module + @test isa(eval(Main, Symbol(module_name)), Module) deleteat!(LOAD_PATH,1) rm(file_name) end diff --git a/test/core.jl b/test/core.jl index d98db8c25826f9..8aeb7828aac5c0 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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...) @@ -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 @@ -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 @@ -3077,7 +3078,7 @@ x7864 = 1 end @test_throws UndefVarError x7864 -using M7864 +using .M7864 @test x7864 == 1 # issue #11715 @@ -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 diff --git a/test/docs.jl b/test/docs.jl index 563bc9366f98f6..592d1d82a14399 100644 --- a/test/docs.jl +++ b/test/docs.jl @@ -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() @@ -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 @@ -464,7 +469,7 @@ let T = meta(DocVars)[@var(DocVars.T)], ) @test docstrings_equal(S.docs[Union{}], doc""" - DocVars.S + $Sname """ ) @@ -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 @@ -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:** @@ -766,6 +776,7 @@ two :: String three :: Float64 ``` """) +@test docstrings_equal(@doc(Undocumented.D), doc"$doc_str") let d = @doc Undocumented.f io = IOBuffer() @@ -773,7 +784,7 @@ let d = @doc Undocumented.f @test startswith(takebuf_string(io),""" No documentation found. - `Undocumented.f` is a `Function`. + `$(name_prefix)Undocumented.f` is a `Function`. """) end @@ -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 @@ -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 diff --git a/test/enums.jl b/test/enums.jl index f6524104a04df2..7ce0c6fca2dc61 100644 --- a/test/enums.jl +++ b/test/enums.jl @@ -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 @@ -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 @@ -167,5 +167,3 @@ let b = IOBuffer() seekstart(b) @test deserialize(b) === apple end - -end # module diff --git a/test/examples.jl b/test/examples.jl index 494a93deebd826..2fbcf21593ce45 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -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")) - diff --git a/test/lineedit.jl b/test/lineedit.jl index 3f24fdf9e87927..1a653bf4665bab 100644 --- a/test/lineedit.jl +++ b/test/lineedit.jl @@ -2,7 +2,7 @@ using Base.LineEdit isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl")) -using TestHelpers +using .TestHelpers a_foo = 0 diff --git a/test/misc.jl b/test/misc.jl index 16066830498e94..e27723dc5ed14c 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -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)) diff --git a/test/nullable.jl b/test/nullable.jl index 7ef888f2d87eda..66b9303f54c56d 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -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) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 4a91bf6a29f269..e248d5e85b1a03 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -95,7 +95,7 @@ indsoffset(i::Integer) = 0 end -using OAs +using .OAs let # Basics diff --git a/test/reflection.jl b/test/reflection.jl index 6b4864c772cccc..64baae764fc84f 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -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 @@ -173,6 +177,7 @@ foo7648(x) = x module TestModSub9475 using Base.Test using ..TestMod7648 + import ..curmod_name export a9475 a9475 = 5 b9475 = 7 @@ -180,7 +185,8 @@ foo7648(x) = x @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 @@ -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 @@ -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 @@ -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 diff --git a/test/repl.jl b/test/repl.jl index e6b3369c75d39c..965c35e91b7869 100644 --- a/test/repl.jl +++ b/test/repl.jl @@ -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() @@ -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) diff --git a/test/replcompletions.jl b/test/replcompletions.jl index 98dad9089194c6..643e69d25ac2ff 100644 --- a/test/replcompletions.jl +++ b/test/replcompletions.jl @@ -2,7 +2,10 @@ using Base.REPLCompletions -module CompletionFoo +const name_prefix = "$(["$m." for m in fullname(current_module())]...)" + +ex = quote + module CompletionFoo type Test_y yy end @@ -54,7 +57,10 @@ module CompletionFoo test_dict = Dict("abc"=>1, "abcd"=>10, :bar=>2, :bar2=>9, Base=>3, contains=>4, `ls`=>5, 66=>7, 67=>8, ("q",3)=>11, "α"=>12, :α=>13) + end end +ex.head = :toplevel +eval(Main, ex) function temp_pkg_dir(fn::Function) # Used in tests below to setup and teardown a sandboxed package directory @@ -221,7 +227,7 @@ end s = "CompletionFoo.test(1,1, " c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test, Tuple{Int, Int}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test, Tuple{Int, Int}))) @test length(c) == 3 @test r == 1:18 @test s[r] == "CompletionFoo.test" @@ -229,7 +235,7 @@ c, r, res = test_complete(s) s = "CompletionFoo.test(CompletionFoo.array," c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test, Tuple{Array{Int, 1}, Any}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test, Tuple{Array{Int, 1}, Any}))) @test length(c) == 2 @test r == 1:18 @test s[r] == "CompletionFoo.test" @@ -237,7 +243,7 @@ c, r, res = test_complete(s) s = "CompletionFoo.test(1,1,1," c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test, Tuple{Any, Any, Any}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test, Tuple{Any, Any, Any}))) @test r == 1:18 @test s[r] == "CompletionFoo.test" @@ -265,26 +271,26 @@ for (T, arg) in [(String,"\")\""),(Char, "')'")] s = "(1, CompletionFoo.test2($arg," c, r, res = test_complete(s) @test length(c) == 1 - @test c[1] == string(first(methods(CompletionFoo.test2, Tuple{T,}))) + @test c[1] == string(first(methods(Main.CompletionFoo.test2, Tuple{T,}))) @test r == 5:23 @test s[r] == "CompletionFoo.test2" end s = "(1, CompletionFoo.test2(`)`," c, r, res = test_complete(s) -@test c[1] == string(first(methods(CompletionFoo.test2, Tuple{Cmd}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test2, Tuple{Cmd}))) @test length(c) == 1 s = "CompletionFoo.test3([1, 2] + CompletionFoo.varfloat," c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64}))) @test length(c) == 1 s = "CompletionFoo.test3([1.,2.], 1.," c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test3, Tuple{Array{Float64, 1}, Float64}))) @test r == 1:19 @test length(c) == 1 @test s[r] == "CompletionFoo.test3" @@ -292,7 +298,7 @@ c, r, res = test_complete(s) s = "CompletionFoo.test4(\"e\",r\" \"," c, r, res = test_complete(s) @test !res -@test c[1] == string(first(methods(CompletionFoo.test4, Tuple{String, Regex}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test4, Tuple{String, Regex}))) @test r == 1:19 @test length(c) == 1 @test s[r] == "CompletionFoo.test4" @@ -301,13 +307,13 @@ s = "CompletionFoo.test5(push!(Base.split(\"\",' '),\"\",\"\").==\"\"," c, r, res = test_complete(s) @test !res @test length(c) == 1 -@test c[1] == string(first(methods(CompletionFoo.test5, Tuple{BitArray{1}}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test5, Tuple{BitArray{1}}))) s = "CompletionFoo.test4(CompletionFoo.test_y_array[1]()[1], CompletionFoo.test_y_array[1]()[2], " c, r, res = test_complete(s) @test !res @test length(c) == 1 -@test c[1] == string(first(methods(CompletionFoo.test4, Tuple{String, String}))) +@test c[1] == string(first(methods(Main.CompletionFoo.test4, Tuple{String, String}))) # Test that string escaption is handled correct s = """CompletionFoo.test4("\\"",""" diff --git a/test/replutil.jl b/test/replutil.jl index c0a34b29df5e9b..511323dacc1d35 100644 --- a/test/replutil.jl +++ b/test/replutil.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license +const name_prefix = "$(["$m." for m in fullname(current_module())]...)" + function test_have_color(buf, color, no_color) if Base.have_color @test takebuf_string(buf) == color @@ -79,12 +81,12 @@ type PR16155 end Base.show_method_candidates(buf, MethodError(PR16155,(1.0, 2.0, Int64(3)))) -test_have_color(buf, "\e[0m\nClosest candidates are:\n PR16155(::Any, ::Any)\n PR16155(\e[1m\e[31m::Int64\e[0m, ::Any)\n PR16155{T}(::Any)\e[0m", - "\nClosest candidates are:\n PR16155(::Any, ::Any)\n PR16155(!Matched::Int64, ::Any)\n PR16155{T}(::Any)") +test_have_color(buf, "\e[0m\nClosest candidates are:\n $(name_prefix)PR16155(::Any, ::Any)\n $(name_prefix)PR16155(\e[1m\e[31m::Int64\e[0m, ::Any)\n $(name_prefix)PR16155{T}(::Any)\e[0m", + "\nClosest candidates are:\n $(name_prefix)PR16155(::Any, ::Any)\n $(name_prefix)PR16155(!Matched::Int64, ::Any)\n $(name_prefix)PR16155{T}(::Any)") Base.show_method_candidates(buf, MethodError(PR16155,(Int64(3), 2.0, Int64(3)))) -test_have_color(buf, "\e[0m\nClosest candidates are:\n PR16155(::Int64, ::Any)\n PR16155(::Any, ::Any)\n PR16155{T}(::Any)\e[0m", - "\nClosest candidates are:\n PR16155(::Int64, ::Any)\n PR16155(::Any, ::Any)\n PR16155{T}(::Any)") +test_have_color(buf, "\e[0m\nClosest candidates are:\n $(name_prefix)PR16155(::Int64, ::Any)\n $(name_prefix)PR16155(::Any, ::Any)\n $(name_prefix)PR16155{T}(::Any)\e[0m", + "\nClosest candidates are:\n $(name_prefix)PR16155(::Int64, ::Any)\n $(name_prefix)PR16155(::Any, ::Any)\n $(name_prefix)PR16155{T}(::Any)") method_c6(; x=1) = x method_c6(a; y=1) = y @@ -178,14 +180,14 @@ let f11007(::MethodType11007) = nothing err_str = @except_str(invoke(f11007, Tuple{InvokeType11007}, InstanceType11007()), MethodError) - @test !contains(err_str, "::InstanceType11007") - @test contains(err_str, "::InvokeType11007") + @test !contains(err_str, "::$(name_prefix)InstanceType11007") + @test contains(err_str, "::$(name_prefix)InvokeType11007") end module __tmp_replutil using Base.Test -import Main.@except_str +import ..@except_str global + +() = nothing err_str = @except_str 1 + 2 MethodError @@ -210,7 +212,7 @@ end abstract T11007 let err_str = @except_str T11007() MethodError - @test contains(err_str, "no method matching T11007()") + @test contains(err_str, "no method matching $(name_prefix)T11007()") end immutable TypeWithIntParam{T <: Integer} end @@ -286,17 +288,17 @@ let err_str, err_str = @except_str :a() MethodError @test contains(err_str, "MethodError: objects of type Symbol are not callable") err_str = @except_str EightBitType() MethodError - @test contains(err_str, "MethodError: no method matching EightBitType()") + @test contains(err_str, "MethodError: no method matching $(name_prefix)EightBitType()") err_str = @except_str i() MethodError - @test contains(err_str, "MethodError: objects of type EightBitType are not callable") + @test contains(err_str, "MethodError: objects of type $(name_prefix)EightBitType are not callable") err_str = @except_str EightBitTypeT() MethodError - @test contains(err_str, "MethodError: no method matching EightBitTypeT{T}()") + @test contains(err_str, "MethodError: no method matching $(name_prefix)EightBitTypeT{T}()") err_str = @except_str EightBitTypeT{Int32}() MethodError - @test contains(err_str, "MethodError: no method matching EightBitTypeT{Int32}()") + @test contains(err_str, "MethodError: no method matching $(name_prefix)EightBitTypeT{Int32}()") err_str = @except_str j() MethodError - @test contains(err_str, "MethodError: objects of type EightBitTypeT{Int32} are not callable") + @test contains(err_str, "MethodError: objects of type $(name_prefix)EightBitTypeT{Int32} are not callable") err_str = @except_str FunctionLike()() MethodError - @test contains(err_str, "MethodError: no method matching (::FunctionLike)()") + @test contains(err_str, "MethodError: no method matching (::$(name_prefix)FunctionLike)()") err_str = @except_str [1,2](1) MethodError @test contains(err_str, "MethodError: objects of type Array{$Int,1} are not callable\nUse square brackets [] for indexing an Array.") # Issue 14940 @@ -325,13 +327,13 @@ let err_str, @test sprint(show, which(Symbol, Tuple{})) == "Symbol() at $sp:$(method_defs_lineno + 0)" @test sprint(show, which(:a, Tuple{})) == "(::Symbol)() at $sp:$(method_defs_lineno + 1)" - @test sprint(show, which(EightBitType, Tuple{})) == "EightBitType() at $sp:$(method_defs_lineno + 2)" - @test sprint(show, which(reinterpret(EightBitType, 0x54), Tuple{})) == "(::EightBitType)() at $sp:$(method_defs_lineno + 3)" - @test sprint(show, which(EightBitTypeT, Tuple{})) == "(::Type{EightBitTypeT})() at $sp:$(method_defs_lineno + 4)" - @test sprint(show, which(EightBitTypeT{Int32}, Tuple{})) == "(::Type{EightBitTypeT{T}}){T}() at $sp:$(method_defs_lineno + 5)" - @test sprint(show, which(reinterpret(EightBitTypeT{Int32}, 0x54), Tuple{})) == "(::EightBitTypeT)() at $sp:$(method_defs_lineno + 6)" + @test sprint(show, which(EightBitType, Tuple{})) == "$(name_prefix)EightBitType() at $sp:$(method_defs_lineno + 2)" + @test sprint(show, which(reinterpret(EightBitType, 0x54), Tuple{})) == "(::$(name_prefix)EightBitType)() at $sp:$(method_defs_lineno + 3)" + @test sprint(show, which(EightBitTypeT, Tuple{})) == "(::Type{$(name_prefix)EightBitTypeT})() at $sp:$(method_defs_lineno + 4)" + @test sprint(show, which(EightBitTypeT{Int32}, Tuple{})) == "(::Type{$(name_prefix)EightBitTypeT{T}}){T}() at $sp:$(method_defs_lineno + 5)" + @test sprint(show, which(reinterpret(EightBitTypeT{Int32}, 0x54), Tuple{})) == "(::$(name_prefix)EightBitTypeT)() at $sp:$(method_defs_lineno + 6)" @test startswith(sprint(show, which(getfield(Base, Symbol("@doc")), Tuple{Vararg{Any}})), "@doc(x...) at boot.jl:") - @test startswith(sprint(show, which(FunctionLike(), Tuple{})), "(::FunctionLike)() at $sp:$(method_defs_lineno + 7)") + @test startswith(sprint(show, which(FunctionLike(), Tuple{})), "(::$(name_prefix)FunctionLike)() at $sp:$(method_defs_lineno + 7)") @test stringmime("text/plain", FunctionLike()) == "(::FunctionLike) (generic function with 1 method)" @test stringmime("text/plain", Core.arraysize) == "arraysize (built-in function)" @@ -340,17 +342,17 @@ let err_str, err_str = @except_stackframe :a() ErrorException @test err_str == " in (::Symbol)() at $sn:$(method_defs_lineno + 1)" err_str = @except_stackframe EightBitType() ErrorException - @test err_str == " in EightBitType() at $sn:$(method_defs_lineno + 2)" + @test err_str == " in $(name_prefix)EightBitType() at $sn:$(method_defs_lineno + 2)" err_str = @except_stackframe i() ErrorException - @test err_str == " in (::EightBitType)() at $sn:$(method_defs_lineno + 3)" + @test err_str == " in (::$(name_prefix)EightBitType)() at $sn:$(method_defs_lineno + 3)" err_str = @except_stackframe EightBitTypeT() ErrorException - @test err_str == " in EightBitTypeT{T}() at $sn:$(method_defs_lineno + 4)" + @test err_str == " in $(name_prefix)EightBitTypeT{T}() at $sn:$(method_defs_lineno + 4)" err_str = @except_stackframe EightBitTypeT{Int32}() ErrorException - @test err_str == " in EightBitTypeT{Int32}() at $sn:$(method_defs_lineno + 5)" + @test err_str == " in $(name_prefix)EightBitTypeT{Int32}() at $sn:$(method_defs_lineno + 5)" err_str = @except_stackframe j() ErrorException - @test err_str == " in (::EightBitTypeT{Int32})() at $sn:$(method_defs_lineno + 6)" + @test err_str == " in (::$(name_prefix)EightBitTypeT{Int32})() at $sn:$(method_defs_lineno + 6)" err_str = @except_stackframe FunctionLike()() ErrorException - @test err_str == " in (::FunctionLike)() at $sn:$(method_defs_lineno + 7)" + @test err_str == " in (::$(name_prefix)FunctionLike)() at $sn:$(method_defs_lineno + 7)" end # Issue #13032 diff --git a/test/runtests.jl b/test/runtests.jl index 4fef9b34cfbf28..de9ff80ed7bb73 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,7 +41,9 @@ cd(dirname(@__FILE__)) do test = shift!(tests) local resp try - resp = remotecall_fetch(t -> runtests(t), p, test) + # FIXME: `remote_fetch` doesn't work when + # a new module is define. + resp = remotecall_fetch(t -> runtests(t, t != "examples"), p, test) catch e resp = e end diff --git a/test/show.jl b/test/show.jl index 3eadf5e1e434c3..20cf5a0c6f6e50 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license +const name_prefix = "$(["$m." for m in fullname(current_module())]...)" + replstr(x) = sprint((io,x) -> show(IOContext(io, limit=true), MIME("text/plain"), x), x) @test replstr(Array{Any}(2)) == "2-element Array{Any,1}:\n #undef\n #undef" @@ -9,7 +11,7 @@ replstr(x) = sprint((io,x) -> show(IOContext(io, limit=true), MIME("text/plain") immutable T5589 names::Vector{String} end -@test replstr(T5589(Array(String,100))) == "T5589(String[#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef … #undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef])" +@test replstr(T5589(Array(String,100))) == "$(name_prefix)T5589(String[#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef … #undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef,#undef])" @test replstr(parse("type X end")) == ":(type X # none, line 1:\n end)" @test replstr(parse("immutable X end")) == ":(immutable X # none, line 1:\n end)" @@ -324,8 +326,8 @@ let @test sprint(show, B) == "\n\t[1, 1] = #undef\n\t[2, 2] = #undef\n\t[3, 3] = #undef" @test sprint(print, B) == "\n\t[1, 1] = #undef\n\t[2, 2] = #undef\n\t[3, 3] = #undef" B[1,2] = T12960() - @test sprint(show, B) == "\n\t[1, 1] = #undef\n\t[1, 2] = T12960()\n\t[2, 2] = #undef\n\t[3, 3] = #undef" - @test sprint(print, B) == "\n\t[1, 1] = #undef\n\t[1, 2] = T12960()\n\t[2, 2] = #undef\n\t[3, 3] = #undef" + @test sprint(show, B) == "\n\t[1, 1] = #undef\n\t[1, 2] = $(name_prefix)T12960()\n\t[2, 2] = #undef\n\t[3, 3] = #undef" + @test sprint(print, B) == "\n\t[1, 1] = #undef\n\t[1, 2] = $(name_prefix)T12960()\n\t[2, 2] = #undef\n\t[3, 3] = #undef" end # issue #13127 @@ -335,7 +337,7 @@ function f13127() show(buf, f) takebuf_string(buf) end -@test f13127() == "f" +@test f13127() == "$(name_prefix)f" let a = Pair(1.0,2.0) @test sprint(show,a) == "1.0=>2.0" diff --git a/test/testdefs.jl b/test/testdefs.jl index 0c9a7cb4f002b3..4f067d69f688aa 100644 --- a/test/testdefs.jl +++ b/test/testdefs.jl @@ -1,10 +1,28 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -using Base.Test - -function runtests(name) +function runtests(name, isolate=true) + if isolate + mod_name = Symbol("TestMain_", basename(name)) + m = Module(mod_name, true) + eval(m, :(const $mod_name = $m; + eval(x) = Core.eval($m, x); + eval(m, x) = Core.eval(m, x))) + # Make this visible from Main module. + # Certain functions (e.g. `deserialize`, `subtypes` and `methodswith` + # relies on this). + eval(Main, :($mod_name = $m)) + # Non-anonymous version + # mod_name = Symbol("TestMain_", basename(name)) + # m = eval(Main, :(module $mod_name end)) + else + m = Main + end + eval(m, :(using Base.Test)) @printf(" \033[1m*\033[0m \033[31m%-21s\033[0m", name) - tt = @elapsed include("$name.jl") + tt = @elapsed eval(m, :(include($"$name.jl"))) + if isolate + eval(Main, :($mod_name = nothing)) + end rss = Sys.maxrss() @printf(" in %6.2f seconds, maxrss %7.2f MB\n", tt, rss / 2^20) rss