From 8a5c2146b63d5aecccb789da7e18a4dc4a77a032 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 8 Aug 2025 09:06:25 +1200 Subject: [PATCH 1/7] Add a test that methods are not overwritten in test modules --- test/runtests.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 3f54349f4d..1690e34c59 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,6 +22,8 @@ # If present, the tests run only those submodules defined above. `General` is # not a submodule, but it runs all of the top-level tests in MOI. +import Test + # This file gets called first. If it doesn't crash, all is well. include("issue980.jl") @@ -32,7 +34,14 @@ MODULES_TO_TEST = get( ) for submodule in split(MODULES_TO_TEST, ";") - include("$(submodule)/runtests.jl") + # This `test_nowarn` checks for warnings that get thrown when we include a + # method twice by mistake: + # WARNING: Method definition test_foo() in module TestFoo + # These warnings are thrown only if Julia is started with + # julia --warn-overwrite=yes + # The entire test file is run, and then the warnings are checked on exit + # from `include()`. + Test.@test_nowarn include("$(submodule)/runtests.jl") GC.gc() # Force GC run here to reduce memory pressure end From b7de1babf0402e3e7ee250b3e966676818169bf6 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 8 Aug 2025 09:41:47 +1200 Subject: [PATCH 2/7] Update --- test/runtests.jl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 1690e34c59..2748be48bb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,15 +33,25 @@ MODULES_TO_TEST = get( "General;Benchmarks;Bridges;Bridges/Constraint;Bridges/Objective;Bridges/Variable;FileFormats;Nonlinear;Test;Utilities", ) +function include_with_method_redefinition_check(jl_filename) + stderr_filename = tempname() + open(stderr_filename, "w") do io + return redirect_stderr(() -> include(jl_filename), io) + end + contents = read(stderr_filename, String) + print(stderr, contents) + warnings = findall( + r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n", + contents, + ) + if isempty(warnings) + error("Found overwritten method") + end + return +end + for submodule in split(MODULES_TO_TEST, ";") - # This `test_nowarn` checks for warnings that get thrown when we include a - # method twice by mistake: - # WARNING: Method definition test_foo() in module TestFoo - # These warnings are thrown only if Julia is started with - # julia --warn-overwrite=yes - # The entire test file is run, and then the warnings are checked on exit - # from `include()`. - Test.@test_nowarn include("$(submodule)/runtests.jl") + include_with_method_redefinition_check("$submodule/runtests") GC.gc() # Force GC run here to reduce memory pressure end From 4e1a180f35931141406e9e03ccc31ee33c9af4b5 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 8 Aug 2025 09:51:54 +1200 Subject: [PATCH 3/7] Update test/runtests.jl --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2748be48bb..ef1b7c88fb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -51,7 +51,7 @@ function include_with_method_redefinition_check(jl_filename) end for submodule in split(MODULES_TO_TEST, ";") - include_with_method_redefinition_check("$submodule/runtests") + include_with_method_redefinition_check("$(submodule)/runtests.jl") GC.gc() # Force GC run here to reduce memory pressure end From 248ac8800bb0db06011ff2e728805a39a6bb1168 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 8 Aug 2025 09:59:31 +1200 Subject: [PATCH 4/7] Update --- test/runtests.jl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2748be48bb..3dc0f1e94d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,11 +40,8 @@ function include_with_method_redefinition_check(jl_filename) end contents = read(stderr_filename, String) print(stderr, contents) - warnings = findall( - r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n", - contents, - ) - if isempty(warnings) + regex = r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n" + if match(regex, contents) !== nothing error("Found overwritten method") end return From 0f3d319ff8b52ceed7fb744f5070b70d1cd3bf27 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 8 Aug 2025 10:20:48 +1200 Subject: [PATCH 5/7] Update --- test/FileFormats/NL/read.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FileFormats/NL/read.jl b/test/FileFormats/NL/read.jl index fcc0574b44..c52c59597e 100644 --- a/test/FileFormats/NL/read.jl +++ b/test/FileFormats/NL/read.jl @@ -955,7 +955,7 @@ function test_binary_parse_x() return end -function test_parse_d() +function test_binary_parse_d() model = NL._CacheModel() model.is_binary = true io = IOBuffer() From 12cc35ce8672e20893981ce24d6d39e78e4965db Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 8 Aug 2025 10:33:00 +1200 Subject: [PATCH 6/7] Update test/runtests.jl --- test/runtests.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index cf0ff77898..13d9b3a607 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -40,7 +40,8 @@ function include_with_method_redefinition_check(jl_filename) end contents = read(stderr_filename, String) print(stderr, contents) - regex = r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n" + regex = + r"WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n" if match(regex, contents) !== nothing error("Found overwritten method") end From b94b0bfa7809314eed37b520c489cdf1b22f3d63 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 8 Aug 2025 11:12:07 +1200 Subject: [PATCH 7/7] Update runtests.jl --- test/runtests.jl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 13d9b3a607..4c7b8f0683 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,8 +22,6 @@ # If present, the tests run only those submodules defined above. `General` is # not a submodule, but it runs all of the top-level tests in MOI. -import Test - # This file gets called first. If it doesn't crash, all is well. include("issue980.jl") @@ -33,6 +31,19 @@ MODULES_TO_TEST = get( "General;Benchmarks;Bridges;Bridges/Constraint;Bridges/Objective;Bridges/Variable;FileFormats;Nonlinear;Test;Utilities", ) +""" + include_with_method_redefinition_check(jl_filename) + +This function runs `include(jl_filename)` with an additional check that there +are no `WARNING: Method definition foo in module Foo overwritten` warnings. + +It does this by piping `stderr` to a file, and then parsing the file. + +One consequence is that `stderr` is not printed until the _end_ of this +function. Thus, some warnings may appear in the wrong place. + +This function requires Julia to be started with `--warn-overwrite=true`. +""" function include_with_method_redefinition_check(jl_filename) stderr_filename = tempname() open(stderr_filename, "w") do io