Skip to content

Commit

Permalink
Isolate each test in an module.
Browse files Browse the repository at this point in the history
So that names in different tests won't conflict.
  • Loading branch information
yuyichao committed Nov 14, 2016
1 parent 2751493 commit e4b525d
Show file tree
Hide file tree
Showing 25 changed files with 198 additions and 151 deletions.
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
8 changes: 6 additions & 2 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ambig(x::Int, y::Int) = 4
ambig(x::Number, y) = 5
# END OF LINE NUMBER SENSITIVITY

const curmod = current_module()
const curmod_name = fullname(curmod)
const curmod_str = curmod === Main ? "Main" : join(curmod_name, ".")

ambigs = Any[[], [3], [2,5], [], [3]]

mt = methods(ambig)
Expand Down Expand Up @@ -52,8 +56,8 @@ let err = try
io = IOBuffer()
Base.showerror(io, err)
lines = split(takebuf_string(io), '\n')
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) in Main at") ||
startswith(str, " ambig(x::Integer, y) in Main at")
ambig_checkline(str) = startswith(str, " ambig(x, y::Integer) in $curmod_str at") ||
startswith(str, " ambig(x::Integer, y) in $curmod_str at")
@test ambig_checkline(lines[2])
@test ambig_checkline(lines[3])
end
Expand Down
4 changes: 2 additions & 2 deletions test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FooBase_module = :FooBase4b3a94a1a081a8cb
$Foo_module = 232
$FooBase_module = 9134
end
using ConflictingBindings
using .ConflictingBindings

# this environment variable would affect some error messages being tested below
# so we disable it for the tests below
Expand Down Expand Up @@ -379,7 +379,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
Expand Down
11 changes: 7 additions & 4 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# test core language features
const Bottom = Union{}
const curmod = current_module()
const curmod_name = fullname(curmod)
const curmod_prefix = "$(["$m." for m in curmod_name]...)"

macro testintersect(args...)
_testintersect(args...)
Expand Down Expand Up @@ -1187,8 +1190,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()) == "$(curmod_prefix)Foo2517()"
@test repr(Array{Foo2517}(1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]"
@test Foo2517() === Foo2517()

# issue #1474
Expand Down Expand Up @@ -2436,7 +2439,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) == "$(curmod_prefix)Int24(0x468ace)"
end

# issue #10570
Expand Down Expand Up @@ -3066,7 +3069,7 @@ x7864 = 1
end

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

# issue #11715
Expand Down
3 changes: 0 additions & 3 deletions test/dates/adjusters.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

module DatesAdjustersTests
using Base.Test
#trunc
dt = Dates.Date(2012,12,21)
@test trunc(dt,Dates.Year) == Dates.Date(2012)
Expand Down Expand Up @@ -460,4 +458,3 @@ end) == 251
end
return sum == 15
end) == 15 # On average, there's one of those months every year
end
4 changes: 0 additions & 4 deletions test/dates/io.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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

end
3 changes: 0 additions & 3 deletions test/dates/periods.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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

@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]
@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]
end
3 changes: 0 additions & 3 deletions test/dates/types.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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

@test isfinite(Dates.Date)
@test isfinite(Dates.DateTime)
end
55 changes: 34 additions & 21 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

const curmod = current_module()
const curmod_name = fullname(curmod)
const curmod_prefix = "$(["$m." for m in curmod_name]...)"

# Test helpers.
function docstrings_equal(d1, d2)
io1 = IOBuffer()
Expand Down Expand Up @@ -450,10 +454,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$(curmod_prefix)DocVars.T\n```"),
Sname = Markdown.parse("```\n$(curmod_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 +471,7 @@ let T = meta(DocVars)[@var(DocVars.T)],
)
@test docstrings_equal(S.docs[Union{}],
doc"""
DocVars.S
$Sname
"""
)
Expand Down Expand Up @@ -545,11 +552,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("`$(curmod_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 +715,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 `$(curmod_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 $(curmod_prefix)Undocumented.A <: Any
```
**Subtypes:**
```
Undocumented.B
Undocumented.C
$(curmod_prefix)Undocumented.B
$(curmod_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 $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A
```
**Subtypes:**
```
Undocumented.D
$(curmod_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 $(curmod_prefix)Undocumented.C <: $(curmod_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 $(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B
```
**Fields:**
Expand All @@ -766,14 +778,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`.
`$(curmod_prefix)Undocumented.f` is a `Function`.
""")
end

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

Expand Down Expand Up @@ -862,7 +875,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
8 changes: 4 additions & 4 deletions test/enums.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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

using Base.Test

Expand Down Expand Up @@ -156,7 +158,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::$(curmod_prefix)Fruit = 1"

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

end # module
19 changes: 10 additions & 9 deletions test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ if is_unix()
end

dc_path = joinpath(dir, "dictchannel.jl")
myid() == 1 || include(dc_path)

# Run the remote on pid 1, since runtests may terminate workers
# at any time depending on memory usage
remotecall_fetch(1, dc_path) do f
include(f)
nothing
main_ex = quote
myid() == 1 || include($dc_path)
remotecall_fetch(1, $dc_path) do f
include(f)
nothing
end
RemoteChannel(()->DictChannel(), 1)
end
dc=RemoteChannel(()->DictChannel(), 1)
@test typeof(dc) == RemoteChannel{DictChannel}
dc = eval(Main, main_ex)
@test typeof(dc) == RemoteChannel{Main.DictChannel}

@test isready(dc) == false
put!(dc, 1, 2)
Expand Down Expand Up @@ -82,8 +84,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/libgit2.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

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

const LIBGIT2_MIN_VER = v"0.23.0"
Expand Down
2 changes: 1 addition & 1 deletion test/lineedit.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

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

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

# test methodswith
# `methodswith` relies on exported symbols
export func4union, Base
immutable NoMethodHasThisType end
@test isempty(methodswith(NoMethodHasThisType))
@test !isempty(methodswith(Int))
Expand Down
Loading

0 comments on commit e4b525d

Please sign in to comment.