diff --git a/docs/src/index.md b/docs/src/index.md index 99db20b1..ae542d05 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -12,6 +12,29 @@ could simply install it by running: pkg> add Clang ``` +If you want to run the tests to check that everything is working the usual `] +test` command will work. If you're making changes to the package you can also +use [ReTest.jl](https://juliatesting.github.io/ReTest.jl/stable/) and +[TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl) to run the tests (or a +selection) iteratively: +```julia +# One-liner to keep in your shell history +julia> using TestEnv; TestEnv.activate(); import ReTest, Clang; ReTest.load(Clang) + +# Run all the tests. This will be slow the first time because ReTest needs to +# start the worker process for running the tests. +julia> ClangTests.runtests() + +# Run a selection of the tests +julia> ClangTests.runtests("comments") +``` + +We need to load the `ClangTests` module with `ReTest.load(Clang)` because that +will take care of tracking all the `include`'ed test files if Revise is already +loaded. This way the tests will be tracked by Revise just like regular package +code and the worker process used for running the tests will be kept around, +which is a much faster workflow than running `] test`. + ## C-bindings generator The package includes a generator to create Julia wrappers for C libraries from a collection of header files. The following declarations are currently supported: diff --git a/test/ClangTests.jl b/test/ClangTests.jl new file mode 100644 index 00000000..988dbadf --- /dev/null +++ b/test/ClangTests.jl @@ -0,0 +1,23 @@ +# This is the test module for Clang.jl, intended for use by ReTest.jl. Note that +# it should be loaded with ReTest.load() instead of includet() because the files +# in the tests include() other files and that doesn't play well with +# Revise. See: https://juliatesting.github.io/ReTest.jl/stable/#Working-with-Revise +# +# Just adding test/ to LOAD_PATH doesn't work because of the Project.toml file, +# which makes Pkg treat the directory as a single package directory instead of a +# directory containing possibly multiple modules. + +module ClangTests + +__revise_mode__ = :eval + +using ReTest + +include("jllenvs.jl") +include("file.jl") +include("generators.jl") + +include("test_mpi.jl") +include("test_bitfield.jl") + +end diff --git a/test/Project.toml b/test/Project.toml index dbd6c374..bea7f29f 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,6 +4,7 @@ CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" CMake_jll = "3f4e10e2-61f2-5801-8945-23b9d642d0e6" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" +ReTest = "e0db7c4e-2690-44b9-bad6-7687da720f89" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/file.jl b/test/file.jl index 11907930..091bafa1 100644 --- a/test/file.jl +++ b/test/file.jl @@ -1,5 +1,4 @@ using Clang -using Test @testset "File" begin @@ -48,4 +47,4 @@ end end -end \ No newline at end of file +end diff --git a/test/generators.jl b/test/generators.jl index 9f72c7e0..ee33df65 100644 --- a/test/generators.jl +++ b/test/generators.jl @@ -1,7 +1,6 @@ using Clang using Clang.Generators using Clang.LibClang.Clang_jll -using Test using Clang.Generators: StructDefinition, StructMutualRef, strip_comment_markers include("rewriter.jl") @@ -11,6 +10,7 @@ include("rewriter.jl") CLANG_C_DIR = joinpath(INCLUDE_DIR, "clang-c") options = load_options(joinpath(@__DIR__, "test.toml")) + options["general"]["output_file_path"] = joinpath(@__DIR__, "LibClang.jl") # add compiler flags args = get_default_args() diff --git a/test/runtests.jl b/test/runtests.jl index 4fb038d9..3a1b3466 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,10 @@ -using Clang -using Test +import ReTest: retest +import Clang # Temporary hack to make @doc work in 1.11 for the documentation tests. See: # https://github.com/JuliaLang/julia/issues/54664 using REPL -include("jllenvs.jl") -include("file.jl") -include("generators.jl") +include("ClangTests.jl") -include("test_mpi.jl") -include("test_bitfield.jl") +retest(Clang, ClangTests; stats=true) diff --git a/test/test.toml b/test/test.toml index 3fc14f19..e629033d 100644 --- a/test/test.toml +++ b/test/test.toml @@ -1,6 +1,5 @@ [general] library_name = "libclang" -output_file_path = "./LibClang.jl" module_name = "LibClang" jll_pkg_name = "Clang_jll" extract_c_comment = "doxygen" diff --git a/test/test_bitfield.jl b/test/test_bitfield.jl index 51bc6da1..ed184e95 100644 --- a/test/test_bitfield.jl +++ b/test/test_bitfield.jl @@ -65,13 +65,15 @@ function build_libbitfield() headers = joinpath(@__DIR__, "build", "include", "bitfield.h") options = load_options(joinpath(@__DIR__, "bitfield", "generate.toml")) lib_path = joinpath(@__DIR__, "build", "lib", Sys.iswindows() ? "bitfield.dll" : "libbitfield") + output_path = joinpath(@__DIR__, "LibBitField.jl") options["general"]["library_name"] = "\"$(escape_string(lib_path))\"" - options["general"]["output_file_path"] = joinpath(@__DIR__, "LibBitField.jl") + options["general"]["output_file_path"] = output_path ctx = create_context(headers, args, options) build!(ctx) # Call a function to ensure build is successful - include("LibBitField.jl") + include(output_path) + m = Base.@invokelatest LibBitField.Mirror(10, 1.5, 1e6, -4, 7, 3) Base.@invokelatest LibBitField.toBitfield(Ref(m)) catch e