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 Jan 2, 2024
1 parent bdb93d8 commit 30a2a25
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 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
21 changes: 21 additions & 0 deletions test/ClangTests.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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
9 changes: 4 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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)
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
11 changes: 8 additions & 3 deletions test/test_bitfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 30a2a25

Please sign in to comment.