@@ -266,7 +266,7 @@ mktempdir() do dir
266266end
267267
268268# # Tests for LazyLibrary
269- @testset " LazyLibrary" begin ; mktempdir () do dir
269+ @testset " LazyLibrary" begin
270270 lclf_path = joinpath (private_libdir, " libccalllazyfoo.$(Libdl. dlext) " )
271271 lclb_path = joinpath (private_libdir, " libccalllazybar.$(Libdl. dlext) " )
272272
278278 global lclf_loaded = false
279279 global lclb_loaded = false
280280
281- # We don't provide `dlclose()` on `LazyLibrary`'s, you have to manage it yourself:
281+ # We don't provide `dlclose()` on `LazyLibrary`'s since it is dangerous , you have to manage it yourself:
282282 function close_libs ()
283283 global lclf_loaded = false
284284 global lclb_loaded = false
294294 @test ! any (contains .(dllist (), lclb_path))
295295 end
296296
297- global libccalllazyfoo = LazyLibrary (lclf_path; on_load_callback= () -> global lclf_loaded = true )
298- global libccalllazybar = LazyLibrary (lclb_path; dependencies= [libccalllazyfoo], on_load_callback= () -> global lclb_loaded = true )
297+ let libccalllazyfoo = LazyLibrary (lclf_path; on_load_callback= () -> global lclf_loaded = true ),
298+ libccalllazybar = LazyLibrary (lclb_path; dependencies= [libccalllazyfoo], on_load_callback= () -> global lclb_loaded = true )
299+ eval (:(const libccalllazyfoo = $ libccalllazyfoo))
300+ eval (:(const libccalllazybar = $ libccalllazybar))
301+ end
302+ Core. @latestworld
299303
300304 # Creating `LazyLibrary` doesn't actually load anything
301305 @test ! lclf_loaded
308312 close_libs ()
309313
310314 # Test that the library gets loaded when you use `ccall()`
311- @test ccall ((:bar , libccalllazybar), Cint, (Cint,), 2 ) == 6
315+ compiled_bar () = ccall ((:bar , libccalllazybar), Cint, (Cint,), 2 )
316+ @test ccall ((:bar , libccalllazybar), Cint, (Cint,), 2 ) == compiled_bar () == 6
312317 @test lclf_loaded
313318 @test lclb_loaded
314319 close_libs ()
@@ -324,11 +329,17 @@ end
324329 @test lclf_loaded
325330 close_libs ()
326331
332+ # Test that `cglobal()` works, both compiled and runtime emulation
333+ compiled_cglobal () = cglobal ((:bar , libccalllazybar))
334+ @test cglobal ((:bar , libccalllazybar)) === compiled_cglobal () === dlsym (dlopen (libccalllazybar), :bar )
335+ @test lclf_loaded
336+ close_libs ()
337+
327338 # Test that we can use lazily-evaluated library names:
328339 libname = LazyLibraryPath (private_libdir, " libccalllazyfoo.$(Libdl. dlext) " )
329340 lazy_name_lazy_lib = LazyLibrary (libname)
330341 @test dlpath (lazy_name_lazy_lib) == realpath (string (libname))
331- end ; end
342+ end
332343
333344@testset " Docstrings" begin
334345 @test isempty (Docs. undocumented_names (Libdl))
0 commit comments