From ad3b0b7d057214cabeaec7744f6c1c7d4e613f8a Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 20 Oct 2024 13:38:02 -0400 Subject: [PATCH] rework the tests to use TestItems (probably should have been a separate PR) --- test/Project.toml | 2 +- test/runtests.jl | 40 ++++++++++++------------------------ test/test_aqua.jl | 7 +++++++ test/test_doctests.jl | 4 ++++ test/test_jet.jl | 4 ++++ test/test_quantikz.jl | 4 ++++ test/test_quantumclifford.jl | 4 ++++ 7 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 test/test_aqua.jl diff --git a/test/Project.toml b/test/Project.toml index ccf8fc1..6d52923 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -9,7 +9,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Quantikz = "b0d11df0-eea3-4d79-b4a5-421488cbf74b" QuantumClifford = "0525e862-1e90-11e9-3e4d-1b39d7109de1" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" diff --git a/test/runtests.jl b/test/runtests.jl index 5eb00ca..c62ca1e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,34 +1,20 @@ -using SafeTestsets using BPGates +using TestItemRunner -function doset(descr) - if length(ARGS) == 0 - return true - end - for a in ARGS - if occursin(lowercase(a), lowercase(descr)) - return true - end - end - return false -end +# filter for the test +testfilter = ti -> begin + exclude = Symbol[] + if get(ENV,"JET_TEST","")!="true" + push!(exclude, :jet) + end + if !(VERSION >= v"1.10") + push!(exclude, :doctests) + push!(exclude, :aqua) + end -macro doset(descr) - quote - if doset($descr) - @safetestset $descr begin include("test_"*$descr*".jl") end - end - end + return all(!in(exclude), ti.tags) end println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...") -@doset "quantumclifford" -@doset "quantikz" -get(ENV,"JET_TEST","")=="true" && @doset "jet" -@doset "doctests" - -using Aqua -doset("aqua") && begin - Aqua.test_all(BPGates) -end +@run_package_tests filter=testfilter diff --git a/test/test_aqua.jl b/test/test_aqua.jl new file mode 100644 index 0000000..3fbf9f7 --- /dev/null +++ b/test/test_aqua.jl @@ -0,0 +1,7 @@ +@testitem "Aqua analysis" begin + +using Aqua, BPGates + +Aqua.test_all(BPGates) + +end diff --git a/test/test_doctests.jl b/test/test_doctests.jl index 742f238..e5dda80 100644 --- a/test/test_doctests.jl +++ b/test/test_doctests.jl @@ -1,5 +1,9 @@ +@testitem "doctests" begin + using Documenter using BPGates DocMeta.setdocmeta!(BPGates, :DocTestSetup, :(using QuantumClifford, BPGates); recursive=true) doctest(BPGates) + +end diff --git a/test/test_jet.jl b/test/test_jet.jl index 0ee511b..ef1a9a6 100644 --- a/test/test_jet.jl +++ b/test/test_jet.jl @@ -1,3 +1,5 @@ +@testitem "JET analysis" begin + using JET using Test using BPGates @@ -9,3 +11,5 @@ rep = report_package("BPGates"; ) @show rep @test length(JET.get_reports(rep)) == 0 + +end diff --git a/test/test_quantikz.jl b/test/test_quantikz.jl index 3a18b90..12288ac 100644 --- a/test/test_quantikz.jl +++ b/test/test_quantikz.jl @@ -1,3 +1,5 @@ +@testitem "Quantikz circuit plotting" begin + using BPGates using Quantikz using Test @@ -6,3 +8,5 @@ using Test quantikz_circ = Quantikz.QuantikzOp.([BellSinglePermutation(2,2), BellDoublePermutation(1,2,3), BellPauliPermutation(4,1), BellMeasure(3,1), BellGate(1,1,1,1,1,1,2), CNOTPerm(1,2,3,4), GoodSingleQubitPerm(1,2), PauliNoiseOp(1,0.0,0.0,0.0), PauliNoiseBellGate(CNOTPerm(1,2,3,4),0.0,0.0,0.0), NoisyBellMeasure(BellMeasure(1,2),0.0), NoisyBellMeasureNoisyReset(BellMeasure(1,2),0.0,0.0,0.0,0.0)]) img = Quantikz.circuit2image(quantikz_circ) end + +end diff --git a/test/test_quantumclifford.jl b/test/test_quantumclifford.jl index 77e6677..5d939e1 100644 --- a/test/test_quantumclifford.jl +++ b/test/test_quantumclifford.jl @@ -1,3 +1,5 @@ +@testitem "QuantumClifford comparisons" begin + using BPGates, QuantumClifford using QuantumClifford.Experimental.NoisyCircuits using Random @@ -59,3 +61,5 @@ end @test_throws ArgumentError BellState(S"ZX") @test_throws ArgumentError BellState(S"XXII ZZII IIXX Y_ZZ") # this is not really a valid stabilizer tableau anyway @test_throws ArgumentError BellState(ghz(4)) + +end