From d90814520c26c21382a6d7756535240b1de839d3 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Mon, 29 Jan 2024 15:37:51 +0100 Subject: [PATCH 1/4] Improve test coverage --- test/trixi_include.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/trixi_include.jl b/test/trixi_include.jl index dbd31e5..8f0f88c 100644 --- a/test/trixi_include.jl +++ b/test/trixi_include.jl @@ -19,6 +19,10 @@ @test_nowarn trixi_include(@__MODULE__, filename, x=7) @test x == 7 + # Verify default version (that includes in `Main`) + @test_nowarn trixi_include(filename, x = 11) + @test Main.x == 11 + @test_throws "assignment `y` not found in expression" trixi_include(@__MODULE__, filename, y=3) @@ -84,10 +88,17 @@ # This is the default `maxiters` inserted by `trixi_include` @test x == 10^5 + # Non-semicolon version @test_nowarn trixi_include(@__MODULE__, filename2, maxiters=7) # Test that `maxiters` got overwritten @test x == 7 + + # Semicolon version + @test_nowarn trixi_include(@__MODULE__, filename2; + maxiters=11) + # Test that `maxiters` got overwritten + @test x == 11 finally rm(filename1, force=true) rm(filename2, force=true) From f2806b56654fb65ba5b16a8f75e3de33bd437cf7 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Mon, 29 Jan 2024 15:44:53 +0100 Subject: [PATCH 2/4] Format code --- test/trixi_include.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/trixi_include.jl b/test/trixi_include.jl index 8f0f88c..2a6c7a8 100644 --- a/test/trixi_include.jl +++ b/test/trixi_include.jl @@ -20,7 +20,7 @@ @test x == 7 # Verify default version (that includes in `Main`) - @test_nowarn trixi_include(filename, x = 11) + @test_nowarn trixi_include(filename, x=11) @test Main.x == 11 @test_throws "assignment `y` not found in expression" trixi_include(@__MODULE__, From a20308abf171cafa5f75e3bc9a96ea01af173937 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Mon, 29 Jan 2024 16:27:59 +0100 Subject: [PATCH 3/4] Hopefully improve coverage --- test/trixi_include.jl | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/test/trixi_include.jl b/test/trixi_include.jl index 2a6c7a8..94a7d14 100644 --- a/test/trixi_include.jl +++ b/test/trixi_include.jl @@ -62,6 +62,8 @@ # We need another example file that we include with `Base.include` first, in order to # define the `solve` method without `trixi_include` trying to insert `maxiters` kwargs. # Then, we can test that `trixi_include` inserts the kwarg in the `solve()` call. + # Finally, we verify the logic that prevents adding multiple `maxiters` in case it + # is already present (either before or after the `;`) example1 = """ solve(; maxiters=0) = maxiters """ @@ -70,8 +72,18 @@ x = solve() """ + example3 = """ + y = solve(maxiters=0) + """ + + example4 = """ + y = solve(; maxiters=0) + """ + filename1 = tempname() filename2 = tempname() + filename3 = tempname() + filename4 = tempname() try open(filename1, "w") do file write(file, example1) @@ -79,6 +91,12 @@ open(filename2, "w") do file write(file, example2) end + open(filename3, "w") do file + write(file, example3) + end + open(filename4, "w") do file + write(file, example4) + end # Use `@trixi_testset`, which wraps code in a temporary module, and call # `Base.include` and `trixi_include` with `@__MODULE__` in order to isolate this test. @@ -88,20 +106,22 @@ # This is the default `maxiters` inserted by `trixi_include` @test x == 10^5 - # Non-semicolon version - @test_nowarn trixi_include(@__MODULE__, filename2, - maxiters=7) + @test_nowarn trixi_include(@__MODULE__, filename2, maxiters = 7) # Test that `maxiters` got overwritten @test x == 7 - # Semicolon version - @test_nowarn trixi_include(@__MODULE__, filename2; - maxiters=11) - # Test that `maxiters` got overwritten - @test x == 11 + # Verify that adding `maxiters` to `maxiters` results in exactly one of them + # case 1) `maxiters` is *before* semicolon in included file + @test_nowarn trixi_include(@__MODULE__, filename3, maxiters = 11) + @test y == 11 + # case 2) `maxiters` is *after* semicolon in included file + @test_nowarn trixi_include(@__MODULE__, filename3, maxiters = 14) + @test y == 14 finally rm(filename1, force=true) rm(filename2, force=true) + rm(filename3, force=true) + rm(filename4, force=true) end end end From 440a7d8a124381a76bfac0f164c7c4fb779042ee Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Mon, 29 Jan 2024 16:37:03 +0100 Subject: [PATCH 4/4] Fix formatting --- test/trixi_include.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/trixi_include.jl b/test/trixi_include.jl index 94a7d14..24c6bf8 100644 --- a/test/trixi_include.jl +++ b/test/trixi_include.jl @@ -106,16 +106,16 @@ # This is the default `maxiters` inserted by `trixi_include` @test x == 10^5 - @test_nowarn trixi_include(@__MODULE__, filename2, maxiters = 7) + @test_nowarn trixi_include(@__MODULE__, filename2, maxiters=7) # Test that `maxiters` got overwritten @test x == 7 # Verify that adding `maxiters` to `maxiters` results in exactly one of them # case 1) `maxiters` is *before* semicolon in included file - @test_nowarn trixi_include(@__MODULE__, filename3, maxiters = 11) + @test_nowarn trixi_include(@__MODULE__, filename3, maxiters=11) @test y == 11 # case 2) `maxiters` is *after* semicolon in included file - @test_nowarn trixi_include(@__MODULE__, filename3, maxiters = 14) + @test_nowarn trixi_include(@__MODULE__, filename3, maxiters=14) @test y == 14 finally rm(filename1, force=true)