Skip to content

Commit 712f30f

Browse files
authored
Merge pull request #52 from Evizero/ox/noprompttocreate
If file does not exist, create it (No Prompt)
2 parents 24cafe2 + 6791818 commit 712f30f

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ReferenceTests"
22
uuid = "324d217c-45ce-50fc-942e-d289b448e8cf"
33
authors = ["Christof Stocker <stocker.christof@gmail.com>", "Lyndon White <oxinabox@ucc.asn.au>"]
4-
version = "0.8.4"
4+
version = "0.9.0"
55

66
[deps]
77
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"

src/test_reference.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,14 @@ function test_reference(
110110
actual = _convert(F, raw_actual; kw...)
111111
# preprocessing when reference file doesn't exists
112112
if !isfile(path)
113-
println("Reference file for \"$filename\" does not exist.")
113+
@info("Reference file for \"$filename\" does not exist. It will be created")
114114
# TODO: move encoding out from render
115115
render(rendermode, raw_actual)
116116

117-
if !isinteractive()
118-
error("You need to run the tests interactively with 'include(\"test/runtests.jl\")' to create new reference images")
119-
end
120-
121-
if !input_bool("Create reference file with above content (path: $path)?")
122-
@test false
123-
else
124-
mkpath(dir)
125-
savefile(file, actual)
126-
@info("Please run the tests again for any changes to take effect")
127-
end
117+
mkpath(dir)
118+
savefile(file, actual)
128119

120+
@info("Please run the tests again for any changes to take effect")
129121
return nothing # skip current test case
130122
end
131123

test/runtests.jl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ end
6565
"""
6666

6767
@test_throws ErrorException @test_reference "references/string1.txt" "intentionally wrong to check that this message prints"
68-
@test_throws ErrorException @test_reference "references/wrong.txt" "intentional error to check that this message prints"
6968
@test_throws ErrorException @test_reference "references/string5.txt" """
7069
This is an incorrect
7170
multiline string that does not end with a new line."""
@@ -77,7 +76,7 @@ end
7776

7877
@testset "images as txt using ImageInTerminal" begin
7978
#@test_throws MethodError @test_reference "references/fail.txt" rand(2,2)
80-
@test_throws ErrorException @test_reference "references/camera_new.txt" camera size=(5,10)
79+
8180
@test_reference "references/camera.txt" camera size=(5,10)
8281
@test_reference "references/lena.txt" lena
8382
end
@@ -111,16 +110,38 @@ end
111110
@testset "images as PNG" begin
112111
@test_reference "references/camera.png" imresize(camera, (64,64))
113112
@test_reference "references/camera.png" imresize(camera, (64,64)) by=psnr_equality(25)
114-
@test_throws Exception @test_reference "references/wrongfilename.png" imresize(camera, (64,64))
115113
@test_throws ErrorException @test_reference "references/camera.png" imresize(lena, (64,64))
116114
@test_throws Exception @test_reference "references/camera.png" camera # unequal size
117115
end
118116

119117
using DataFrames, CSVFiles
120118
@testset "DataFrame as CSV" begin
121119
@test_reference "references/dataframe.csv" DataFrame(v1=[1,2,3], v2=["a","b","c"])
122-
@test_throws ErrorException @test_reference "references/wrongfilename.csv" DataFrame(v1=[1,2,3], v2=["a","b","c"])
123120
@test_throws ErrorException @test_reference "references/dataframe.csv" DataFrame(v1=[1,2,3], v2=["c","b","c"])
121+
124122
end
125123

124+
@testset "Create new $ext" for (ext, val) in (
125+
(".csv", DataFrame(v1=[1,2,3], v2=["c","b","c"])),
126+
(".png", imresize(camera, (64,64))),
127+
(".txt", "Lorem ipsum dolor sit amet, labore et dolore magna aliqua."),
128+
)
129+
newfilename = "references/newfilename.$ext"
130+
@assert !isfile(newfilename)
131+
@test_reference newfilename val # this should create it
132+
@test isfile(newfilename) # Was created
133+
@test_reference newfilename val # Matches expected content
134+
rm(newfilename, force=true)
126135
end
136+
137+
@testset "Create new image as txt" begin
138+
# This is a sperate testset as need to use the `size` argument to ``@test_reference`
139+
newfilename = "references/new_camera.txt"
140+
@assert !isfile(newfilename)
141+
@test_reference newfilename camera size=(5,10) # this should create it
142+
@test isfile(newfilename) # Was created
143+
@test_reference newfilename camera size=(5,10) # Matches expected content
144+
rm(newfilename, force=true)
145+
end
146+
147+
end # top level testset

0 commit comments

Comments
 (0)