@@ -99,6 +99,7 @@ function test_reference(
9999
100100 path = file. filename
101101 dir, filename = splitdir (path)
102+ testmode = TESTMODE ()
102103
103104 # infer the default rendermode here
104105 # since `nothing` is always passed to this method from
@@ -112,19 +113,11 @@ function test_reference(
112113 println (" Reference file for \" $filename \" does not exist." )
113114 render (rendermode, raw_actual)
114115
115- if ! isinteractive ()
116- error (" You need to run the tests interactively with 'include(\" test/runtests.jl\" )' to create new reference images" )
117- end
118-
119- if ! input_bool (" Create reference file with above content (path: $path )?" )
116+ continue_test = _create_new_reference (testmode, file, raw_actual)
117+ if ! continue_test
120118 @test false
121- else
122- mkpath (dir)
123- savefile (file, raw_actual)
124- @info (" Please run the tests again for any changes to take effect" )
119+ return nothing
125120 end
126-
127- return nothing # skip current test case
128121 end
129122
130123 # file exists
@@ -137,21 +130,63 @@ function test_reference(
137130 end
138131
139132 if equiv (reference, actual)
140- @test true # to increase test counter if reached
133+ @test true
141134 else
142135 # post-processing when test fails
143136 println (" Test for \" $filename \" failed." )
144137 render (rendermode, reference, actual)
145138
146- if ! isinteractive ()
147- error (" You need to run the tests interactively with 'include(\" test/runtests.jl\" )' to update reference images" )
148- end
139+ increase_fail_count = _update_reference (testmode, file, reference, actual)
140+ increase_fail_count && @test false
141+ end
142+ end
149143
150- if ! input_bool (" Replace reference with actual result (path: $path )?" )
151- @test false
152- else
153- savefile (file, actual)
154- @info (" Please run the tests again for any changes to take effect" )
155- end
144+ function _create_new_reference (:: NonInteractiveMode , file:: File , actual):: Bool
145+ error (" You need to run the tests interactively with 'include(\" test/runtests.jl\" )' to update reference images" )
146+
147+ # # automatically create new reference file and continue test
148+ # path = file.filename
149+ # dir, filename = splitdir(path)
150+
151+ # println("Create new reference file \"$filename\".")
152+ # mkpath(dir)
153+ # savefile(file, actual)
154+
155+ # continue_test = true
156+ # return continue_test
157+ end
158+
159+ function _create_new_reference (:: InteractiveMode , file:: File , actual):: Bool
160+ path = file. filename
161+ dir = splitdir (path)[1 ]
162+
163+ if ! input_bool (" Create reference file with above content (path: $path )?" )
164+ continue_test = false
165+ else
166+ mkpath (dir)
167+ savefile (file, actual)
168+ continue_test = true
169+ end
170+ return continue_test
171+ end
172+
173+ function _update_reference (:: NonInteractiveMode , file:: File , reference, actual):: Bool
174+ error (" You need to run the tests interactively with 'include(\" test/runtests.jl\" )' to update reference images" )
175+
176+ # # Do not update reference
177+ # increase_fail_count = true
178+ # return increase_fail_count
179+ end
180+
181+ function _update_reference (:: InteractiveMode , file:: File , reference, actual):: Bool
182+ path = file. filename
183+
184+ if ! input_bool (" Replace reference with actual result (path: $path )?" )
185+ increase_fail_count = true
186+ else
187+ savefile (file, actual)
188+ @info (" Please run the tests again for any changes to take effect" )
189+ increase_fail_count = false
156190 end
191+ return increase_fail_count
157192end
0 commit comments