|
1 | 1 | # SPDX-FileCopyrightText: 2022, 2024, 2025 Uwe Fechner |
2 | 2 | # SPDX-License-Identifier: MIT |
3 | 3 |
|
| 4 | +using Pkg |
| 5 | +if ! ("Test" ∈ keys(Pkg.project().dependencies)) |
| 6 | + Pkg.activate("test") |
| 7 | +end |
| 8 | + |
4 | 9 | using Test |
5 | 10 | using KiteModels |
6 | | -using Pkg |
7 | 11 |
|
8 | | -@testset "Testing helper functions..." begin |
9 | | - path=pwd() |
10 | | - tmpdir=mktempdir() |
11 | | - mkpath(tmpdir) |
12 | | - cd(tmpdir) |
13 | | - KiteModels.copy_examples() |
14 | | - @test isfile(joinpath(tmpdir, "examples", "bench.jl")) |
15 | | - @test isfile(joinpath(tmpdir, "examples", "compare_kps3_kps4.jl")) |
16 | | - @test isfile(joinpath(tmpdir, "examples", "menu.jl")) |
17 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_1p.jl")) |
18 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_4p.jl")) |
19 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_4p_torque_control.jl")) |
20 | | - @test isfile(joinpath(tmpdir, "examples", "simulate_simple.jl")) |
21 | | - @test isfile(joinpath(tmpdir, "examples", "simulate_steering.jl")) |
22 | | - if ! Sys.iswindows() |
23 | | - rm(tmpdir, recursive=true) |
24 | | - end |
25 | | - cd(path) |
26 | | - path=pwd() |
27 | | - tmpdir=mktempdir() |
28 | | - mkpath(tmpdir) |
29 | | - cd(tmpdir) |
30 | | - KiteModels.install_examples(false) |
31 | | - @test isfile(joinpath(tmpdir, "examples", "bench.jl")) |
32 | | - @test isfile(joinpath(tmpdir, "examples", "compare_kps3_kps4.jl")) |
33 | | - @test isfile(joinpath(tmpdir, "examples", "menu.jl")) |
34 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_1p.jl")) |
35 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_4p.jl")) |
36 | | - @test isfile(joinpath(tmpdir, "examples", "reel_out_4p_torque_control.jl")) |
37 | | - @test isfile(joinpath(tmpdir, "examples", "simulate_simple.jl")) |
38 | | - @test isfile(joinpath(tmpdir, "examples", "simulate_steering.jl")) |
39 | | - if ! Sys.iswindows() |
40 | | - rm(tmpdir, recursive=true) |
41 | | - end |
42 | | - cd(path) |
| 12 | +function run_helper_tests() |
| 13 | + @testset "Testing helper functions..." begin |
| 14 | + original_dir = pwd() |
| 15 | + tmpdirs = [] # Collect temp directories to clean up at the end |
| 16 | + |
| 17 | + try |
| 18 | + # Test 1: copy_examples |
| 19 | + tmpdir1 = mktempdir() |
| 20 | + push!(tmpdirs, tmpdir1) |
| 21 | + cd(tmpdir1) |
| 22 | + KiteModels.copy_examples() |
| 23 | + @test isfile(joinpath(tmpdir1, "examples", "bench.jl")) |
| 24 | + @test isfile(joinpath(tmpdir1, "examples", "compare_kps3_kps4.jl")) |
| 25 | + @test isfile(joinpath(tmpdir1, "examples", "menu.jl")) |
| 26 | + @test isfile(joinpath(tmpdir1, "examples", "reel_out_1p.jl")) |
| 27 | + @test isfile(joinpath(tmpdir1, "examples", "reel_out_4p.jl")) |
| 28 | + @test isfile(joinpath(tmpdir1, "examples", "reel_out_4p_torque_control.jl")) |
| 29 | + @test isfile(joinpath(tmpdir1, "examples", "simulate_simple.jl")) |
| 30 | + @test isfile(joinpath(tmpdir1, "examples", "simulate_steering.jl")) |
| 31 | + cd(original_dir) |
| 32 | + |
| 33 | + # Test 2: install_examples |
| 34 | + # Reset DATA_PATH to default so it doesn't reference a deleted temp directory |
| 35 | + KiteUtils.set_data_path() |
| 36 | + tmpdir2 = mktempdir() |
| 37 | + push!(tmpdirs, tmpdir2) |
| 38 | + cd(tmpdir2) |
| 39 | + KiteModels.install_examples(false) |
| 40 | + @test isfile(joinpath(tmpdir2, "examples", "bench.jl")) |
| 41 | + @test isfile(joinpath(tmpdir2, "examples", "compare_kps3_kps4.jl")) |
| 42 | + @test isfile(joinpath(tmpdir2, "examples", "menu.jl")) |
| 43 | + @test isfile(joinpath(tmpdir2, "examples", "reel_out_1p.jl")) |
| 44 | + @test isfile(joinpath(tmpdir2, "examples", "reel_out_4p.jl")) |
| 45 | + @test isfile(joinpath(tmpdir2, "examples", "reel_out_4p_torque_control.jl")) |
| 46 | + @test isfile(joinpath(tmpdir2, "examples", "simulate_simple.jl")) |
| 47 | + @test isfile(joinpath(tmpdir2, "examples", "simulate_steering.jl")) |
| 48 | + cd(original_dir) |
43 | 49 |
|
44 | | - @test ! ("TestEnv" ∈ keys(Pkg.project().dependencies)) |
45 | | - @test ! ("Revise" ∈ keys(Pkg.project().dependencies)) |
46 | | - @test ! ("Plots" ∈ keys(Pkg.project().dependencies)) |
47 | | - # # ensure that BenchmarkTools is not in the main environment |
48 | | - # oldprpath = Pkg.project().path |
49 | | - # if ! Pkg.project().ispackage |
50 | | - # Pkg.activate(".") |
51 | | - # end |
52 | | - # hasbm = ("BenchmarkTools" ∈ keys(Pkg.project().dependencies)) |
53 | | - # Pkg.activate(oldprpath) |
54 | | - # @test ! hasbm |
| 50 | + @test ! ("TestEnv" ∈ keys(Pkg.project().dependencies)) |
| 51 | + @test ! ("Revise" ∈ keys(Pkg.project().dependencies)) |
| 52 | + @test ! ("Plots" ∈ keys(Pkg.project().dependencies)) |
| 53 | + # # ensure that BenchmarkTools is not in the main environment |
| 54 | + # oldprpath = Pkg.project().path |
| 55 | + # if ! Pkg.project().ispackage |
| 56 | + # Pkg.activate(".") |
| 57 | + # end |
| 58 | + # hasbm = ("BenchmarkTools" ∈ keys(Pkg.project().dependencies)) |
| 59 | + # Pkg.activate(oldprpath) |
| 60 | + # @test ! hasbm |
| 61 | + finally |
| 62 | + # Always restore original directory and reset DATA_PATH |
| 63 | + cd(original_dir) |
| 64 | + KiteUtils.set_data_path() |
| 65 | + # Clean up all temp directories |
| 66 | + if ! Sys.iswindows() |
| 67 | + for tmpdir in tmpdirs |
| 68 | + isdir(tmpdir) && rm(tmpdir, recursive=true) |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + end |
55 | 73 | end |
| 74 | + |
| 75 | +# Run the tests |
| 76 | +run_helper_tests() |
| 77 | + |
| 78 | +nothing |
0 commit comments