@@ -31,8 +31,36 @@ MODULES_TO_TEST = get(
3131 " General;Benchmarks;Bridges;Bridges/Constraint;Bridges/Objective;Bridges/Variable;FileFormats;Nonlinear;Test;Utilities" ,
3232)
3333
34+ """
35+ include_with_method_redefinition_check(jl_filename)
36+
37+ This function runs `include(jl_filename)` with an additional check that there
38+ are no `WARNING: Method definition foo in module Foo overwritten` warnings.
39+
40+ It does this by piping `stderr` to a file, and then parsing the file.
41+
42+ One consequence is that `stderr` is not printed until the _end_ of this
43+ function. Thus, some warnings may appear in the wrong place.
44+
45+ This function requires Julia to be started with `--warn-overwrite=true`.
46+ """
47+ function include_with_method_redefinition_check (jl_filename)
48+ stderr_filename = tempname ()
49+ open (stderr_filename, " w" ) do io
50+ return redirect_stderr (() -> include (jl_filename), io)
51+ end
52+ contents = read (stderr_filename, String)
53+ print (stderr , contents)
54+ regex =
55+ r" WARNING: Method definition (.+?) in module (.+?) at (.+?) overwritten at (.+?)\n "
56+ if match (regex, contents) != = nothing
57+ error (" Found overwritten method" )
58+ end
59+ return
60+ end
61+
3462for submodule in split (MODULES_TO_TEST, " ;" )
35- include (" $(submodule) /runtests.jl" )
63+ include_with_method_redefinition_check (" $(submodule) /runtests.jl" )
3664 GC. gc () # Force GC run here to reduce memory pressure
3765end
3866
0 commit comments