Skip to content

Commit

Permalink
Add check before deregistering modules
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 9e02d8840f6b832e8bf9a870cc8787fe44925c88
Author: Konrad Rudolph <[email protected]>
Date:   Sat Jun 29 18:51:36 2024 +0200

    Check before dereginstering a module

    A module may have already been deregistered if it was loaded by two
    modules which are both loaded by the module being unloaded by the user.

commit b7a464c9024e58e42e44ac5cd6ba5c76db248e80
Author: Konrad Rudolph <[email protected]>
Date:   Sun Jun 30 23:13:42 2024 +0200

    Add failing unit test

Fixes #363.
  • Loading branch information
klmr committed Jun 30, 2024
1 parent 10e1b45 commit ee04593
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/loaded.r
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ register_mod = function (info, mod_ns) {

#' @rdname loaded
deregister_mod = function (info) {
rm(list = info$source_path, envir = loaded_mods)
# May already have been removed if called by `unload_mod_recursive`, where
# a given module is imported by multiple submodules.
if (exists(info$source_path, envir = loaded_mods)) {
rm(list = info$source_path, envir = loaded_mods)
}
}

#' @rdname loaded
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/mod/reload/nested/a.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
box::export()
3 changes: 3 additions & 0 deletions tests/testthat/mod/reload/nested/b.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
box::use(./a)

box::export()
3 changes: 3 additions & 0 deletions tests/testthat/mod/reload/nested/c.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
box::use(./a, ./b)

box::export()
6 changes: 6 additions & 0 deletions tests/testthat/test-reload.r
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ test_that('`reload` shows expected errors', {
'"reload" expects a module object, got "x", which is of type "integer" instead'
)
})

test_that('reloading a module used twice does not cause a warning', {
box::use(mod/reload/nested/c)

expect_warning(box::reload(c), NA)
})

0 comments on commit ee04593

Please sign in to comment.