Skip to content

Commit

Permalink
Move the tests to use ReTest.jl
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
JamesWrigley committed Oct 15, 2024
1 parent d965e86 commit 8b823e9
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
23 changes: 23 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
23 changes: 23 additions & 0 deletions test/ClangTests.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions test/file.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Clang
using Test

@testset "File" begin

Expand Down Expand Up @@ -48,4 +47,4 @@ end

end

end
end
2 changes: 1 addition & 1 deletion test/generators.jl
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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()
Expand Down
11 changes: 4 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion test/test.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions test/test_bitfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b823e9

Please sign in to comment.