22
33using Test, Printf
44
5- # this macro tests for exceptions thrown at macro expansion
6- macro test_me (ty, ex)
7- return quote
8- @test_throws $ (esc (ty)) try
9- $ (esc (ex))
10- catch err
11- @test err isa LoadError
12- @test err. file === $ (string (__source__. file))
13- @test err. line === $ (__source__. line)
14- rethrow (err. error)
15- end
16- end
17- end
18-
195# printf
206# int
217@test (@sprintf " %d" typemax (Int64)) == " 9223372036854775807"
@@ -205,14 +191,14 @@ end
205191# escape %
206192@test (@sprintf " %%" ) == " %"
207193@test (@sprintf " %%s" ) == " %s"
208- @test_me ArgumentError (" invalid printf format string: \" %\" " ) @macroexpand (@sprintf " %" ) # " (fixes syntax highlighting)
194+ @test_throws ArgumentError (" invalid printf format string: \" %\" " ) @macroexpand (@sprintf " %" ) # " (fixes syntax highlighting)
209195
210196# argument count
211- @test_me ArgumentError (" @sprintf: wrong number of arguments (0) should be (1)" ) @macroexpand (@sprintf " %s" )
212- @test_me ArgumentError (" @sprintf: wrong number of arguments (2) should be (1)" ) @macroexpand (@sprintf " %s" " 1" " 2" )
197+ @test_throws ArgumentError (" @sprintf: wrong number of arguments (0) should be (1)" ) @macroexpand (@sprintf " %s" )
198+ @test_throws ArgumentError (" @sprintf: wrong number of arguments (2) should be (1)" ) @macroexpand (@sprintf " %s" " 1" " 2" )
213199
214200# no interpolation
215- @test_me ArgumentError (" @sprintf: format must be a plain static string (no interpolation or prefix)" ) @macroexpand (@sprintf " $n " )
201+ @test_throws ArgumentError (" @sprintf: format must be a plain static string (no interpolation or prefix)" ) @macroexpand (@sprintf " $n " )
216202
217203# type width specifier parsing (ignored)
218204@test (@sprintf " %llf" 1.2 ) == " 1.200000"
258244# invalid format specifiers, not "diouxXDOUeEfFgGaAcCsSpn"
259245for c in " bBhHIjJkKlLmMNPqQrRtTvVwWyYzZ"
260246 fmt_str = string (" %" , c)
261- @test_me ArgumentError (" @sprintf: first argument must be a format string" ) @macroexpand (@sprintf $ fmt_str 1 )
247+ @test_throws ArgumentError (" @sprintf: first argument must be a format string" ) @macroexpand (@sprintf $ fmt_str 1 )
262248end
263249
264250# combo
271257@test (@sprintf " %s %s %s %d %d %d %f %f %f" Any[10 ^ x+ y for x= 1 : 3 ,y= 1 : 3 ]. .. ) == " 11 101 1001 12 102 1002 13.000000 103.000000 1003.000000"
272258
273259# @printf
274- @test_me ArgumentError (" @printf: first or second argument must be a format string" ) @macroexpand (@printf 1 )
260+ @test_throws ArgumentError (" @printf: first or second argument must be a format string" ) @macroexpand (@printf 1 )
275261
276262# Check bug with trailing nul printing BigFloat
277263@test (@sprintf (" %.330f" , BigFloat (1 )))[end ] != ' \0 '
@@ -286,10 +272,10 @@ end
286272@test (@sprintf (" %d\u 0f00%d" , 1 , 2 )) == " 1\u 0f002"
287273@test (@sprintf (" %d\U 0001ffff%d" , 1 , 2 )) == " 1\U 0001ffff2"
288274@test (@sprintf (" %d\u 2203%d\u 0203" , 1 , 2 )) == " 1\u 22032\u 0203"
289- @test_me ArgumentError @macroexpand (@sprintf (" %y%d" , 1 , 2 ))
290- @test_me ArgumentError @macroexpand (@sprintf (" %\u 00d0%d" , 1 , 2 ))
291- @test_me ArgumentError @macroexpand (@sprintf (" %\u 0f00%d" , 1 , 2 ))
292- @test_me ArgumentError @macroexpand (@sprintf (" %\U 0001ffff%d" , 1 , 2 ))
275+ @test_throws ArgumentError @macroexpand (@sprintf (" %y%d" , 1 , 2 ))
276+ @test_throws ArgumentError @macroexpand (@sprintf (" %\u 00d0%d" , 1 , 2 ))
277+ @test_throws ArgumentError @macroexpand (@sprintf (" %\u 0f00%d" , 1 , 2 ))
278+ @test_throws ArgumentError @macroexpand (@sprintf (" %\U 0001ffff%d" , 1 , 2 ))
293279
294280# test at macro execution time
295281@test_throws ArgumentError (" @sprintf: wrong number of arguments (2) should be (3)" ) (@sprintf " %d%d%d" 1 : 2 ... )
0 commit comments