263263
264264# issues #43
265265@testset " macro error" begin
266- err_type = VERSION < v " 1.3" ? LoadError : ArgumentError
267- @test_throws err_type @macroexpand (IrrationalConstants. @irrational Myπ big (π) Myπ)
268- @test_throws err_type @macroexpand (IrrationalConstants. @irrational Myπ 1.0 big (π) Myπ)
266+ if VERSION < v " 1.3"
267+ @test_throws LoadError @macroexpand (IrrationalConstants. @irrational Myπ big (π) Myπ)
268+ @test_throws LoadError @macroexpand (IrrationalConstants. @irrational Myπ 1.0 big (π) Myπ)
269+ else
270+ msg = " The name of the irrational constant (Myπ) and its type (Myπ) cannot be the same. Please choose a different name for the constant or specify a different type name as the last argument to the macro."
271+ @test_throws ArgumentError (msg) @macroexpand (IrrationalConstants. @irrational Myπ big (π) Myπ)
272+ @test_throws ArgumentError (msg) @macroexpand (IrrationalConstants. @irrational Myπ 1.0 big (π) Myπ)
273+ end
269274end
270275
271276# test that defining a type that already exists throws an error
@@ -275,9 +280,16 @@ module TestTypeCollision
275280 struct MyExistingType end
276281
277282 @testset " type collision" begin
278- err_type = VERSION < v " 1.3" ? LoadError : ArgumentError
279- @test_throws err_type @macroexpand (IrrationalConstants. @irrational myExistingType big (π) MyExistingType)
280- @test_throws err_type @macroexpand (IrrationalConstants. @irrational myconst big (π) MyExistingType)
281- @test_throws err_type @macroexpand (IrrationalConstants. @irrational myconst 1.0 big (π) MyExistingType)
283+ if VERSION < v " 1.3"
284+ @test_throws LoadError @macroexpand (IrrationalConstants. @irrational myExistingType big (π))
285+ @test_throws LoadError @macroexpand (IrrationalConstants. @irrational myconst big (π) MyExistingType)
286+ @test_throws LoadError @macroexpand (IrrationalConstants. @irrational myconst 1.0 big (π) MyExistingType)
287+ else
288+ msg1 = " Type `MyExistingType` of irrational constant `myExistingType` is already defined in module `Main.TestTypeCollision`."
289+ @test_throws ArgumentError (msg1) @macroexpand (IrrationalConstants. @irrational myExistingType big (π))
290+ msg2 = " Type `MyExistingType` of irrational constant `myconst` is already defined in module `Main.TestTypeCollision`."
291+ @test_throws ArgumentError (msg2) @macroexpand (IrrationalConstants. @irrational myconst big (π) MyExistingType)
292+ @test_throws ArgumentError (msg2) @macroexpand (IrrationalConstants. @irrational myconst 1.0 big (π) MyExistingType)
293+ end
282294 end
283295end
0 commit comments