From 30a2a25540f3e94512a90fa0cfe453cd2feb4414 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Tue, 2 Jan 2024 16:11:23 +0100 Subject: [PATCH] Move the tests to use ReTest.jl This allows for a faster workflow when developing the package. Also made a few paths in the tests explicitly relative to the test/ directory instead of the PWD (since that may not be test/ when running the tests interactively). --- docs/src/index.md | 23 +++++++++++++++++++++++ test/ClangTests.jl | 21 +++++++++++++++++++++ test/Project.toml | 1 + test/generators.jl | 2 +- test/runtests.jl | 9 ++++----- test/test.toml | 1 - test/test_bitfield.jl | 11 ++++++++--- 7 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 test/ClangTests.jl 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..c8be78e3 --- /dev/null +++ b/test/ClangTests.jl @@ -0,0 +1,21 @@ +# 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("generators.jl") + +include("test_mpi.jl") +include("test_bitfield.jl") + +end diff --git a/test/Project.toml b/test/Project.toml index e8b41533..a7f682c8 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -3,6 +3,7 @@ BinaryBuilder = "12aac903-9f7c-5d81-afc2-d9565ea332ae" CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" CMake_jll = "3f4e10e2-61f2-5801-8945-23b9d642d0e6" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +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/generators.jl b/test/generators.jl index fa827351..c615514d 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 db6213b0..0859e314 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,6 @@ -using Clang -using Test +import ReTest: retest +import Clang -include("generators.jl") +include("ClangTests.jl") -include("test_mpi.jl") -include("test_bitfield.jl") +retest(Clang, ClangTests) 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 d76fe5c8..3eafcd6f 100644 --- a/test/test_bitfield.jl +++ b/test/test_bitfield.jl @@ -66,13 +66,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 @@ -85,7 +87,10 @@ end @testset "Bitfield" begin - if build_libbitfield() + build_success = build_libbitfield() + @test build_success + + if build_success bf = Ref(LibBitField.BitField(Int8(10), 1.5, Int32(1e6), Int32(-4), Int32(7), UInt32(3))) m = Ref(LibBitField.Mirror(10, 1.5, 1e6, -4, 7, 3)) GC.@preserve bf m begin