From 5e288022d677c3f6d7eb26712c4927f40e5a652d Mon Sep 17 00:00:00 2001 From: Aaron Peikert Date: Thu, 6 Mar 2025 22:28:24 +0100 Subject: [PATCH 1/2] allow partial execution of unit tests --- test/unit_tests/unit_tests.jl | 47 +++++++++++++++-------- test/unit_tests/unit_tests_interactive.jl | 10 +++++ 2 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 test/unit_tests/unit_tests_interactive.jl diff --git a/test/unit_tests/unit_tests.jl b/test/unit_tests/unit_tests.jl index a638b991d..4b87be582 100644 --- a/test/unit_tests/unit_tests.jl +++ b/test/unit_tests/unit_tests.jl @@ -1,21 +1,36 @@ using Test, SafeTestsets -@safetestset "Multithreading" begin - include("multithreading.jl") -end - -@safetestset "Matrix algebra helper functions" begin - include("matrix_helpers.jl") -end +# Define available test sets +available_tests = Dict( + "multithreading" => "Multithreading", + "matrix_helpers" => "Matrix algebra helper functions", + "data_input_formats" => "SemObserved", + "specification" => "SemSpecification", + "model" => "Sem model", + "StatsAPI" => "Stats API", + "test" => "True" +) -@safetestset "SemObserved" begin - include("data_input_formats.jl") -end - -@safetestset "SemSpecification" begin - include("specification.jl") -end +# Determine which tests to run based on command-line arguments +selected_tests = isempty(ARGS) ? collect(keys(available_tests)) : ARGS -@safetestset "Sem model" begin - include("model.jl") +@testset "All Tests" begin + for file in selected_tests + if haskey(available_tests, file) + let file_ = file, test_name = available_tests[file] + # Compute the literal values + test_sym = Symbol(file_) + file_jl = file_ * ".jl" + # Build the expression with no free variables: + ex = quote + @safetestset $(Symbol(test_sym)) = $test_name begin + include($file_jl) + end + end + eval(ex) + end + else + @warn "Test file '$file' not found in available tests. Skipping." + end + end end diff --git a/test/unit_tests/unit_tests_interactive.jl b/test/unit_tests/unit_tests_interactive.jl new file mode 100644 index 000000000..cf082fa60 --- /dev/null +++ b/test/unit_tests/unit_tests_interactive.jl @@ -0,0 +1,10 @@ +# requires: TestEnv to be installed globally, and the StructuralEquationModels package `]dev`ed +# example: julia test/unit_tests/unit_tests_interactive.jl matrix_helpers + +try + import TestEnv + TestEnv.activate("StructuralEquationModels") +catch e + @warn "Error initializing Test Env" exception=(e, catch_backtrace()) +end +include("unit_tests.jl") \ No newline at end of file From 9cd445eaae5f4190768a306ce6d243658b45e45c Mon Sep 17 00:00:00 2001 From: Aaron Peikert Date: Thu, 6 Mar 2025 22:39:14 +0100 Subject: [PATCH 2/2] remove non existing tests --- test/unit_tests/unit_tests.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unit_tests/unit_tests.jl b/test/unit_tests/unit_tests.jl index 4b87be582..7bdf23d7c 100644 --- a/test/unit_tests/unit_tests.jl +++ b/test/unit_tests/unit_tests.jl @@ -6,9 +6,7 @@ available_tests = Dict( "matrix_helpers" => "Matrix algebra helper functions", "data_input_formats" => "SemObserved", "specification" => "SemSpecification", - "model" => "Sem model", - "StatsAPI" => "Stats API", - "test" => "True" + "model" => "Sem model" ) # Determine which tests to run based on command-line arguments