Skip to content

Commit 7abcce2

Browse files
authored
Merge pull request #88 from jw3126/hellotestsets
migrate from FactCheck to TestSets
2 parents 20a80ec + 628eb41 commit 7abcce2

File tree

5 files changed

+160
-143
lines changed

5 files changed

+160
-143
lines changed

test/REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FactCheck
1+
BaseTestNext

test/error_handling.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
println("these tests will print warnings: ")
2-
context("Not installed") do
2+
@testset "Not installed" begin
33
eval(Base, :(is_interactive = true)) # for interactive error handling
44

55
add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
@@ -10,15 +10,15 @@ context("Not installed") do
1010
ref = @async save("test.not_installed")
1111
println(wr, "y")
1212
if VERSION < v"0.4.0-dev"
13-
@fact_throws ErrorException wait(ref) #("unknown package NotInstalled")
13+
@test_throws ErrorException wait(ref) #("unknown package NotInstalled")
1414
else
15-
@fact_throws CompositeException wait(ref) #("unknown package NotInstalled")
15+
@test_throws CompositeException wait(ref) #("unknown package NotInstalled")
1616
end
1717
ref = @async save("test.not_installed")
1818
println(wr, "invalid") #test invalid input
1919
println(wr, "n") # don't install
2020
wait(ref)
21-
@fact istaskdone(ref) --> true
21+
@test istaskdone(ref)
2222

2323
close(rs);close(wr);close(rserr);close(wrerr)
2424
redirect_stdin(stdin_copy)
@@ -35,11 +35,11 @@ using FileIO
3535
end
3636
add_format(format"BROKEN", (), ".brok", [:BrokenIO])
3737

38-
context("Absent implementation") do
38+
@testset "Absent implementation" begin
3939
stderr_copy = STDERR
4040
rserr, wrerr = redirect_stderr()
41-
@fact_throws FileIO.LoaderError load(Stream(format"BROKEN", STDIN))
42-
@fact_throws FileIO.WriterError save(Stream(format"BROKEN", STDOUT))
41+
@test_throws FileIO.LoaderError load(Stream(format"BROKEN",STDIN))
42+
@test_throws FileIO.WriterError save(Stream(format"BROKEN",STDOUT))
4343
redirect_stderr(stderr_copy)
4444
end
4545

@@ -51,7 +51,7 @@ module MultiError2
5151
import FileIO: @format_str, File, magic
5252
load(file::File{format"MultiError"}) = error("2")
5353
end
54-
context("multiple errors") do
54+
@testset "multiple errors" begin
5555
println("this test will print warnings: ")
5656
add_format(
5757
format"MultiError",
@@ -62,4 +62,4 @@ context("multiple errors") do
6262
)
6363
ret = @test_throws ErrorException load("test.multierr")
6464
#@test ret.value.msg == "1" # this is 0.5 only
65-
end
65+
end

test/loadsave.jl

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
using FileIO, Compat
2-
using FactCheck
2+
if VERSION >= v"0.5.0-dev+7720"
3+
using Base.Test
4+
else
5+
using BaseTestNext
6+
const Test = BaseTestNext
7+
end
38

49
# Stub readers---these might bork any existing readers, so don't
510
# run these tests while doing other things!
@@ -18,28 +23,28 @@ try
1823
empty!(FileIO.sym2loader)
1924
empty!(FileIO.sym2saver)
2025
file_dir = joinpath(dirname(@__FILE__), "files")
21-
context("Load") do
26+
@testset "Load" begin
2227

2328
add_loader(format"PBMText", :TestLoadSave)
2429
add_loader(format"PBMBinary", :TestLoadSave)
2530
add_loader(format"HDF5", :TestLoadSave)
2631
add_loader(format"JLD", :TestLoadSave)
2732

28-
@fact load(joinpath(file_dir, "file1.pbm")) --> "PBMText"
29-
@fact load(joinpath(file_dir, "file2.pbm")) --> "PBMBinary"
33+
@test load(joinpath(file_dir,"file1.pbm")) == "PBMText"
34+
@test load(joinpath(file_dir,"file2.pbm")) == "PBMBinary"
3035
# Regular HDF5 file with magic bytes starting at position 0
31-
@fact load(joinpath(file_dir, "file1.h5")) --> "HDF5"
36+
@test load(joinpath(file_dir,"file1.h5")) == "HDF5"
3237
# This one is actually a JLD file saved with an .h5 extension,
3338
# and the JLD magic bytes edited to prevent it from being recognized
3439
# as JLD.
3540
# JLD files are also HDF5 files, so this should be recognized as
3641
# HDF5. However, what makes this more interesting is that the
3742
# magic bytes start at position 512.
38-
@fact load(joinpath(file_dir, "file2.h5")) --> "HDF5"
43+
@test load(joinpath(file_dir,"file2.h5")) == "HDF5"
3944
# JLD file saved with .jld extension
40-
@fact load(joinpath(file_dir, "file.jld")) --> "JLD"
45+
@test load(joinpath(file_dir,"file.jld")) == "JLD"
4146

42-
@fact_throws load("missing.fmt")
47+
@test_throws Exception load("missing.fmt")
4348
end
4449
finally
4550
merge!(FileIO.sym2loader, sym2loader)
@@ -87,7 +92,7 @@ end
8792
add_loader(format"DUMMY", :Dummy)
8893
add_saver(format"DUMMY", :Dummy)
8994

90-
context("Save") do
95+
@testset "Save" begin
9196
a = [0x01,0x02,0x03]
9297
fn = string(tempname(), ".dmy")
9398
save(fn, a)
@@ -96,46 +101,46 @@ context("Save") do
96101
cd(dirname(fn)) do
97102
fnrel = basename(fn)
98103
f = query(fnrel)
99-
@fact isabspath(filename(f)) --> true
100-
@fact endswith(filename(f), fn) --> true # TravisOSX prepends "/private"
104+
@test isabspath(filename(f))
105+
@test endswith(filename(f),fn) # TravisOSX prepends "/private"
101106
f = File(format"DUMMY", fnrel)
102-
@fact isabspath(filename(f)) --> false
107+
@test !(isabspath(filename(f)))
103108
open(f) do s
104-
@fact isabspath(get(filename(s))) --> true
105-
@fact endswith(get(filename(s)), fn) --> true
109+
@test isabspath(get(filename(s)))
110+
@test endswith(get(filename(s)),fn)
106111
end
107112
end
108113

109114
# Test IO
110115
b = load(query(fn))
111-
@fact a --> b
116+
@test a == b
112117

113118
b = open(query(fn)) do s
114119
skipmagic(s)
115120
load(s)
116121
end
117-
@fact a --> b
122+
@test a == b
118123

119124
# low-level I/O test
120125
open(query(fn)) do s
121-
@fact position(s) --> 0
126+
@test position(s) == 0
122127
skipmagic(s)
123-
@fact position(s) --> length(magic(format"DUMMY"))
128+
@test position(s) == length(magic(format"DUMMY"))
124129
seek(s, 1)
125-
@fact position(s) --> 1
130+
@test position(s) == 1
126131
seekstart(s)
127-
@fact position(s) --> 0
132+
@test position(s) == 0
128133
seekend(s)
129-
@fact eof(s) --> true
134+
@test eof(s)
130135
skip(s, -position(s)+1)
131-
@fact position(s) --> 1
132-
@fact isreadonly(s) --> true
133-
@fact isopen(s) --> true
134-
@fact read(s, 2) --> b"UM"
136+
@test position(s) == 1
137+
@test isreadonly(s)
138+
@test isopen(s)
139+
@test read(s,2) == b"UM"
135140
end
136141
rm(fn)
137142

138-
@fact_throws save("missing.fmt", 5)
143+
@test_throws Exception save("missing.fmt",5)
139144
end
140145

141146
del_format(format"DUMMY")
@@ -167,7 +172,7 @@ save(f::File{format"AmbigExt2"}, testdata) = open(f, "w") do io
167172
end
168173
end
169174

170-
context("Ambiguous extension") do
175+
@testset "Ambiguous extension" begin
171176
add_format(format"AmbigExt1", "ambigext1", ".aext", [:AmbigExt])
172177
add_format(format"AmbigExt2", "ambigext2", ".aext", [:AmbigExt])
173178
A = "this is a test"
@@ -179,18 +184,18 @@ context("Ambiguous extension") do
179184
save(format"AmbigExt2", fn, A)
180185

181186
B = load(fn)
182-
@fact B --> A
183-
@fact typeof(query(fn)) --> File{format"AmbigExt2"}
187+
@test B == A
188+
@test typeof(query(fn)) == File{format"AmbigExt2"}
184189
rm(fn)
185190

186191
save(fn, A)
187192
B = load(fn)
188-
@fact B --> A
189-
@fact typeof(query(fn)) --> File{format"AmbigExt1"}
193+
@test B == A
194+
@test typeof(query(fn)) == File{format"AmbigExt1"}
190195

191196
rm(fn)
192197
end
193198

194-
context("Absent file") do
195-
@fact_throws SystemError load("nonexistent.oops")
196-
end
199+
@testset "Absent file" begin
200+
@test_throws SystemError load("nonexistent.oops")
201+
end

0 commit comments

Comments
 (0)