From 7d38f43226f242a6a7ae266f9021372e8cc39a7f Mon Sep 17 00:00:00 2001 From: Frames White Date: Thu, 28 Sep 2023 12:44:57 +0800 Subject: [PATCH 1/5] Monkey patch Test.scrub_backtrace --- src/ChainRulesTestUtils.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ChainRulesTestUtils.jl b/src/ChainRulesTestUtils.jl index 1226056..64c93eb 100644 --- a/src/ChainRulesTestUtils.jl +++ b/src/ChainRulesTestUtils.jl @@ -17,7 +17,17 @@ export ⊢, rand_tangent export @maybe_inferred export test_method_tables -__init__() = init_test_inferred_setting!() +function __init__() + init_test_inferred_setting!() + + # Try to disable backtrace scrubbing so that full failures are shown + try + isdefined(Test, :scrub_backtrace) || error("Test.scrub_backtrace not defined") + @eval Test scrub_backtrace(bt, file_ts, file_t) = bt # make it do nothing + catch err + @warn "Failed to monkey=patch scrub_backtrace. Code is functional but stacktraces may be less useful" exception=(err, catch_backtrace()) + end +end include("global_config.jl") @@ -36,3 +46,4 @@ include("testers.jl") include("deprecated.jl") include("global_checks.jl") end # module + From 11b2974a3c585c6e9de32f68d51547de7dc5c23d Mon Sep 17 00:00:00 2001 From: Frames White Date: Fri, 29 Sep 2023 13:38:01 +0800 Subject: [PATCH 2/5] Add unitary version --- src/ChainRulesTestUtils.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ChainRulesTestUtils.jl b/src/ChainRulesTestUtils.jl index 64c93eb..43f6f64 100644 --- a/src/ChainRulesTestUtils.jl +++ b/src/ChainRulesTestUtils.jl @@ -23,6 +23,8 @@ function __init__() # Try to disable backtrace scrubbing so that full failures are shown try isdefined(Test, :scrub_backtrace) || error("Test.scrub_backtrace not defined") + # depending on julia version or one or the other of these will be hit + @eval Test scrub_backtrace(bt,) = bt # make it do nothing @eval Test scrub_backtrace(bt, file_ts, file_t) = bt # make it do nothing catch err @warn "Failed to monkey=patch scrub_backtrace. Code is functional but stacktraces may be less useful" exception=(err, catch_backtrace()) From 718568c2064df0547aca27b638a5fa3d1f7fe97e Mon Sep 17 00:00:00 2001 From: Frames White Date: Fri, 29 Sep 2023 16:15:33 +0800 Subject: [PATCH 3/5] Mute monkey-patching warning --- Project.toml | 2 ++ src/ChainRulesTestUtils.jl | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 7eb0381..4a0beae 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] @@ -15,6 +16,7 @@ ChainRulesCore = "1.11.2" Compat = "3, 4" FiniteDifferences = "0.12.12" MetaTesting = "0.1" +Suppressor = "0.2.6" julia = "1" [extras] diff --git a/src/ChainRulesTestUtils.jl b/src/ChainRulesTestUtils.jl index 43f6f64..84c6fb4 100644 --- a/src/ChainRulesTestUtils.jl +++ b/src/ChainRulesTestUtils.jl @@ -10,6 +10,7 @@ using FiniteDifferences: to_vec using LinearAlgebra using Random using Test +using Suppressor export TestIterator export test_approx, test_scalar, test_frule, test_rrule, generate_well_conditioned_matrix @@ -23,9 +24,11 @@ function __init__() # Try to disable backtrace scrubbing so that full failures are shown try isdefined(Test, :scrub_backtrace) || error("Test.scrub_backtrace not defined") - # depending on julia version or one or the other of these will be hit - @eval Test scrub_backtrace(bt,) = bt # make it do nothing - @eval Test scrub_backtrace(bt, file_ts, file_t) = bt # make it do nothing + @suppress begin # mute warning about monkey-patching + # depending on julia version or one or the other of these will be hit + @eval Test scrub_backtrace(bt,) = bt # make it do nothing + @eval Test scrub_backtrace(bt, file_ts, file_t) = bt # make it do nothing + end catch err @warn "Failed to monkey=patch scrub_backtrace. Code is functional but stacktraces may be less useful" exception=(err, catch_backtrace()) end From b7f5b0ad5b3feaed16ad9b6c41c62c9e9743c46b Mon Sep 17 00:00:00 2001 From: Frames White Date: Fri, 29 Sep 2023 16:16:38 +0800 Subject: [PATCH 4/5] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4a0beae..a60bed4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ChainRulesTestUtils" uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a" -version = "1.11.0" +version = "1.12.0" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" From ebfe4c1cba28cf463fdd1d052167e5c0371afcf5 Mon Sep 17 00:00:00 2001 From: Frames White Date: Mon, 2 Oct 2023 11:22:54 +0800 Subject: [PATCH 5/5] fix typo in commentr --- src/ChainRulesTestUtils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChainRulesTestUtils.jl b/src/ChainRulesTestUtils.jl index 84c6fb4..2d424f1 100644 --- a/src/ChainRulesTestUtils.jl +++ b/src/ChainRulesTestUtils.jl @@ -30,7 +30,7 @@ function __init__() @eval Test scrub_backtrace(bt, file_ts, file_t) = bt # make it do nothing end catch err - @warn "Failed to monkey=patch scrub_backtrace. Code is functional but stacktraces may be less useful" exception=(err, catch_backtrace()) + @warn "Failed to monkey-patch scrub_backtrace. Code is functional but stacktraces may be less useful" exception=(err, catch_backtrace()) end end