Skip to content

Commit 2c52e0f

Browse files
authored
Move the tests to use ReTest.jl (#461)
* 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). * Set BinaryBuilder compat to 0.5.8
1 parent d965e86 commit 2c52e0f

File tree

8 files changed

+65
-13
lines changed

8 files changed

+65
-13
lines changed

docs/src/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ could simply install it by running:
1212
pkg> add Clang
1313
```
1414

15+
If you want to run the tests to check that everything is working the usual `]
16+
test` command will work. If you're making changes to the package you can also
17+
use [ReTest.jl](https://juliatesting.github.io/ReTest.jl/stable/) and
18+
[TestEnv.jl](https://github.com/JuliaTesting/TestEnv.jl) to run the tests (or a
19+
selection) iteratively:
20+
```julia
21+
# One-liner to keep in your shell history
22+
julia> using TestEnv; TestEnv.activate(); import ReTest, Clang; ReTest.load(Clang)
23+
24+
# Run all the tests. This will be slow the first time because ReTest needs to
25+
# start the worker process for running the tests.
26+
julia> ClangTests.runtests()
27+
28+
# Run a selection of the tests
29+
julia> ClangTests.runtests("comments")
30+
```
31+
32+
We need to load the `ClangTests` module with `ReTest.load(Clang)` because that
33+
will take care of tracking all the `include`'ed test files if Revise is already
34+
loaded. This way the tests will be tracked by Revise just like regular package
35+
code and the worker process used for running the tests will be kept around,
36+
which is a much faster workflow than running `] test`.
37+
1538
## C-bindings generator
1639
The package includes a generator to create Julia wrappers for C libraries from a collection of header files. The following declarations are currently supported:
1740

test/ClangTests.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This is the test module for Clang.jl, intended for use by ReTest.jl. Note that
2+
# it should be loaded with ReTest.load() instead of includet() because the files
3+
# in the tests include() other files and that doesn't play well with
4+
# Revise. See: https://juliatesting.github.io/ReTest.jl/stable/#Working-with-Revise
5+
#
6+
# Just adding test/ to LOAD_PATH doesn't work because of the Project.toml file,
7+
# which makes Pkg treat the directory as a single package directory instead of a
8+
# directory containing possibly multiple modules.
9+
10+
module ClangTests
11+
12+
__revise_mode__ = :eval
13+
14+
using ReTest
15+
16+
include("jllenvs.jl")
17+
include("file.jl")
18+
include("generators.jl")
19+
20+
include("test_mpi.jl")
21+
include("test_bitfield.jl")
22+
23+
end

test/Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
44
CMake_jll = "3f4e10e2-61f2-5801-8945-23b9d642d0e6"
55
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
66
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
7+
ReTest = "e0db7c4e-2690-44b9-bad6-7687da720f89"
78
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
89
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
910
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1011
p7zip_jll = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
12+
13+
[compat]
14+
# This is the last release that won't error out on Julia >1.7:
15+
# https://github.com/JuliaPackaging/BinaryBuilder.jl/pull/1318
16+
#
17+
# We don't require much of BinaryBuilder so until BB2 comes out this should be
18+
# safe.
19+
BinaryBuilder = "0.5.8"

test/file.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Clang
2-
using Test
32

43
@testset "File" begin
54

@@ -48,4 +47,4 @@ end
4847

4948
end
5049

51-
end
50+
end

test/generators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Clang
22
using Clang.Generators
33
using Clang.LibClang.Clang_jll
4-
using Test
54
using Clang.Generators: StructDefinition, StructMutualRef, strip_comment_markers
65

76
include("rewriter.jl")
@@ -11,6 +10,7 @@ include("rewriter.jl")
1110
CLANG_C_DIR = joinpath(INCLUDE_DIR, "clang-c")
1211

1312
options = load_options(joinpath(@__DIR__, "test.toml"))
13+
options["general"]["output_file_path"] = joinpath(@__DIR__, "LibClang.jl")
1414

1515
# add compiler flags
1616
args = get_default_args()

test/runtests.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using Clang
2-
using Test
1+
import ReTest: retest
2+
import Clang
33

44
# Temporary hack to make @doc work in 1.11 for the documentation tests. See:
55
# https://github.com/JuliaLang/julia/issues/54664
66
using REPL
77

8-
include("jllenvs.jl")
9-
include("file.jl")
10-
include("generators.jl")
8+
include("ClangTests.jl")
119

12-
include("test_mpi.jl")
13-
include("test_bitfield.jl")
10+
retest(Clang, ClangTests; stats=true)

test/test.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[general]
22
library_name = "libclang"
3-
output_file_path = "./LibClang.jl"
43
module_name = "LibClang"
54
jll_pkg_name = "Clang_jll"
65
extract_c_comment = "doxygen"

test/test_bitfield.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ function build_libbitfield()
6565
headers = joinpath(@__DIR__, "build", "include", "bitfield.h")
6666
options = load_options(joinpath(@__DIR__, "bitfield", "generate.toml"))
6767
lib_path = joinpath(@__DIR__, "build", "lib", Sys.iswindows() ? "bitfield.dll" : "libbitfield")
68+
output_path = joinpath(@__DIR__, "LibBitField.jl")
6869
options["general"]["library_name"] = "\"$(escape_string(lib_path))\""
69-
options["general"]["output_file_path"] = joinpath(@__DIR__, "LibBitField.jl")
70+
options["general"]["output_file_path"] = output_path
7071
ctx = create_context(headers, args, options)
7172
build!(ctx)
7273

7374
# Call a function to ensure build is successful
74-
include("LibBitField.jl")
75+
include(output_path)
76+
7577
m = Base.@invokelatest LibBitField.Mirror(10, 1.5, 1e6, -4, 7, 3)
7678
Base.@invokelatest LibBitField.toBitfield(Ref(m))
7779
catch e

0 commit comments

Comments
 (0)