diff --git a/examples/lru_test.jl b/examples/lru_test.jl index 57fca9e097980..92117f027ba5e 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 b0170a3015ccc..2d6f10724f0c6 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 394f7882dd0b3..f4ab8244556c2 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...) @@ -1178,8 +1179,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 @@ -2425,7 +2426,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 @@ -3051,7 +3052,7 @@ x7864 = 1 end @test_throws UndefVarError x7864 -using M7864 +using .M7864 @test x7864 == 1 # issue #11715 diff --git a/test/docs.jl b/test/docs.jl index 4c08d8ba05198..1348f06f5d7ea 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 f6524104a04df..7ce0c6fca2dc6 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 494a93deebd82..2fbcf21593ce4 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 3f24fdf9e8792..1a653bf4665ba 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 7a2e5738089f8..7a3b0eccea9da 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 7ef888f2d87ed..66b9303f54c56 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 4e83a3299226d..71f52ba6a6334 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -98,7 +98,7 @@ indsoffset(i::Integer) = 0 end -using OAs +using .OAs let # Basics diff --git a/test/parse.jl b/test/parse.jl index 6714351c4016d..63e1530befe67 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -630,7 +630,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/reflection.jl b/test/reflection.jl index 352ff8db8d9ea..853c3eef323b3 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, foo9475, c7648, foo7648, foo7648_nomethods, Foo7648 const c7648 = 8 @@ -175,6 +179,7 @@ type Foo7648 end module TestModSub9475 using Base.Test using ..TestMod7648 + import ..curmod_name export a9475, foo9475 a9475 = 5 b9475 = 7 @@ -183,7 +188,8 @@ type Foo7648 end @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 @@ -194,7 +200,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 @@ -211,7 +217,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 @@ -341,7 +347,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 f75411b165b58..cdc9049c92c33 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 1b9ee804bd6e5..6719d81dd93dd 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,8 +57,11 @@ 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 + test_repl_comp_dict = CompletionFoo.test_dict end -test_repl_comp_dict = CompletionFoo.test_dict +ex.head = :toplevel +eval(Main, ex) function temp_pkg_dir_noinit(fn::Function) # Used in tests below to set up and tear down a sandboxed package directory @@ -226,7 +232,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" @@ -234,7 +240,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" @@ -242,7 +248,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" @@ -270,26 +276,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" @@ -297,7 +303,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" @@ -306,13 +312,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 4ad026f3a8f80..61ac227f5a6d4 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 @@ -97,12 +99,12 @@ PR16155line2 = @__LINE__ + 1 (::Type{T}){T<:PR16155}(arg::Any) = "replace call-to-convert method from sysimg" 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)$cfile$PR16155line\n PR16155(\e[1m\e[31m::Int64\e[0m, ::Any)$cfile$PR16155line\n PR16155{T<:PR16155}(::Any)$cfile$PR16155line2\n ...\e[0m", - "\nClosest candidates are:\n PR16155(::Any, ::Any)$cfile$PR16155line\n PR16155(!Matched::Int64, ::Any)$cfile$PR16155line\n PR16155{T<:PR16155}(::Any)$cfile$PR16155line2\n ...") +test_have_color(buf, "\e[0m\nClosest candidates are:\n $(name_prefix)PR16155(::Any, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155(\e[1m\e[31m::Int64\e[0m, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155{T<:$(name_prefix)PR16155}(::Any)$cfile$PR16155line2\n ...\e[0m", + "\nClosest candidates are:\n $(name_prefix)PR16155(::Any, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155(!Matched::Int64, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155{T<:$(name_prefix)PR16155}(::Any)$cfile$PR16155line2\n ...") 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)$cfile$PR16155line\n PR16155(::Any, ::Any)$cfile$PR16155line\n PR16155{T<:PR16155}(::Any)$cfile$PR16155line2\n ...\e[0m", - "\nClosest candidates are:\n PR16155(::Int64, ::Any)$cfile$PR16155line\n PR16155(::Any, ::Any)$cfile$PR16155line\n PR16155{T<:PR16155}(::Any)$cfile$PR16155line2\n ...") +test_have_color(buf, "\e[0m\nClosest candidates are:\n $(name_prefix)PR16155(::Int64, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155(::Any, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155{T<:$(name_prefix)PR16155}(::Any)$cfile$PR16155line2\n ...\e[0m", + "\nClosest candidates are:\n $(name_prefix)PR16155(::Int64, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155(::Any, ::Any)$cfile$PR16155line\n $(name_prefix)PR16155{T<:$(name_prefix)PR16155}(::Any)$cfile$PR16155line2\n ...") c6line = @__LINE__ method_c6(; x=1) = x @@ -218,14 +220,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 @@ -250,7 +252,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 @@ -326,17 +328,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 @@ -365,13 +367,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)" @@ -380,17 +382,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 4fef9b34cfbf2..de9ff80ed7bb7 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 5c5327b381147..83b841bd7ac1f 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,1}(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,1}(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)" @@ -325,8 +327,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 @@ -336,7 +338,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 0c9a7cb4f002b..b64d45d9e325a 100644 --- a/test/testdefs.jl +++ b/test/testdefs.jl @@ -1,10 +1,15 @@ # 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 = 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"))) rss = Sys.maxrss() @printf(" in %6.2f seconds, maxrss %7.2f MB\n", tt, rss / 2^20) rss