Skip to content

Commit 6f4c4e3

Browse files
authored
Merge pull request #441 from control-toolbox/feat/test-orthogonality
Refactor test suite for orthogonality
2 parents 84ed889 + 636f0c9 commit 6f4c4e3

28 files changed

Lines changed: 2508 additions & 2706 deletions

test/suite/core/test_core.jl

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/suite/core/test_core_types.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module TestCoreTypes
2+
3+
import Test
4+
import CTBase.Core
5+
6+
const VERBOSE = isdefined(Main, :TestOptions) ? Main.TestOptions.VERBOSE : true
7+
const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING : true
8+
9+
function test_types()
10+
Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "Type aliases" begin
11+
Test.@test Core.ctNumber == Real
12+
Test.@test Core.ctNumber === Real
13+
Test.@test 1 isa Core.ctNumber
14+
Test.@test 1.0 isa Core.ctNumber
15+
end
16+
return nothing
17+
end
18+
19+
end # module
20+
21+
test_core_types() = TestCoreTypes.test_types()

test/suite/core/test_utils.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module TestCoreUtils
2+
3+
import Test
4+
import CTBase.Core
5+
6+
const VERBOSE = isdefined(Main, :TestOptions) ? Main.TestOptions.VERBOSE : true
7+
const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING : true
8+
9+
function test_utils()
10+
Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "Default value of the display during resolution" begin
11+
Test.@test Core.__display()
12+
end
13+
return nothing
14+
end
15+
16+
end # module
17+
18+
test_utils() = TestCoreUtils.test_utils()

test/suite/descriptions/test_display_description.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module TestDisplayDescription
22

33
import Test
4+
import CTBase.Descriptions: Descriptions
45

56
const VERBOSE = isdefined(Main, :TestOptions) ? Main.TestOptions.VERBOSE : true
67
const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING : true

test/suite/exceptions/test_exception_display.jl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,73 @@ function test_exception_display()
413413
Test.@test contains(output, "Suggestion:")
414414
Test.@test contains(output, "Increase max iterations")
415415
end
416+
417+
Test.@testset "IncorrectArgument - got without expected" begin
418+
io = IOBuffer()
419+
e = Exceptions.IncorrectArgument("wrong value", got="bad_value")
420+
Test.@test_nowarn showerror(io, e)
421+
output = String(take!(io))
422+
423+
Test.@test contains(output, "Got:")
424+
Test.@test contains(output, "bad_value")
425+
Test.@test !contains(output, "Expected:")
426+
end
427+
428+
Test.@testset "AmbiguousDescription - diagnostic rendering" begin
429+
# "empty catalog" branch
430+
io = IOBuffer()
431+
e = Exceptions.AmbiguousDescription(
432+
(:a,); diagnostic="empty catalog"
433+
)
434+
Test.@test_nowarn showerror(io, e)
435+
output = String(take!(io))
436+
Test.@test contains(output, "Diagnostic:")
437+
Test.@test contains(output, "Empty catalog")
438+
439+
# "unknown symbols" branch
440+
io = IOBuffer()
441+
e = Exceptions.AmbiguousDescription(
442+
(:z,); diagnostic="unknown symbols"
443+
)
444+
Test.@test_nowarn showerror(io, e)
445+
output = String(take!(io))
446+
Test.@test contains(output, "Diagnostic:")
447+
Test.@test contains(output, "Unknown symbols")
448+
449+
# "no complete match" branch
450+
io = IOBuffer()
451+
e = Exceptions.AmbiguousDescription(
452+
(:a, :z); diagnostic="no complete match"
453+
)
454+
Test.@test_nowarn showerror(io, e)
455+
output = String(take!(io))
456+
Test.@test contains(output, "Diagnostic:")
457+
Test.@test contains(output, "No complete match")
458+
459+
# else branch — arbitrary diagnostic value
460+
io = IOBuffer()
461+
e = Exceptions.AmbiguousDescription(
462+
(:a,); diagnostic="custom diagnostic"
463+
)
464+
Test.@test_nowarn showerror(io, e)
465+
output = String(take!(io))
466+
Test.@test contains(output, "Diagnostic:")
467+
Test.@test contains(output, "custom diagnostic")
468+
end
469+
470+
Test.@testset "AmbiguousDescription - closest-matches inline suggestion" begin
471+
io = IOBuffer()
472+
e = Exceptions.AmbiguousDescription(
473+
(:b, :f);
474+
candidates=["(:a, :b, :c)", "(:a, :d, :e)", "(:x, :y, :z)"],
475+
suggestion="Try one of the closest matches:",
476+
)
477+
Test.@test_nowarn showerror(io, e)
478+
output = String(take!(io))
479+
480+
Test.@test contains(output, "closest matches")
481+
Test.@test contains(output, "(:a, :b, :c)")
482+
end
416483
end
417484
end
418485

test/suite/exceptions/test_types.jl renamed to test/suite/exceptions/test_exception_types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,4 @@ end
262262

263263
end # module
264264

265-
test_types() = TestExceptionTypes.test_exception_types()
265+
test_exception_types() = TestExceptionTypes.test_exception_types()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module TestExtensionError
2+
3+
import Test
4+
import CTBase.Exceptions
5+
6+
const VERBOSE = isdefined(Main, :TestOptions) ? Main.TestOptions.VERBOSE : true
7+
const SHOWTIMING = isdefined(Main, :TestOptions) ? Main.TestOptions.SHOWTIMING : true
8+
9+
function test_extension_error()
10+
Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "ExtensionError Contract Implementation" begin
11+
# Test constructor throws if no dependencies provided
12+
Test.@test_throws Exceptions.PreconditionError Exceptions.ExtensionError()
13+
14+
# Test enriched ExtensionError creation
15+
e = Exceptions.ExtensionError(
16+
:Documenter,
17+
:Markdown;
18+
message="to generate documentation",
19+
feature="automatic documentation",
20+
context="reference generation",
21+
)
22+
23+
Test.@test e isa Exceptions.ExtensionError
24+
Test.@test e.weakdeps == (:Documenter, :Markdown)
25+
Test.@test e.msg == "missing dependencies to generate documentation"
26+
Test.@test e.feature == "automatic documentation"
27+
Test.@test e.context == "reference generation"
28+
end
29+
30+
Test.@testset verbose = VERBOSE showtiming = SHOWTIMING "ExtensionError Constructor Validation" begin
31+
Test.@testset "No dependencies provided" begin
32+
Test.@test_throws Exceptions.PreconditionError Exceptions.ExtensionError()
33+
34+
try
35+
Exceptions.ExtensionError()
36+
Test.@test false # Should not reach here
37+
catch e
38+
Test.@test e isa Exceptions.PreconditionError
39+
Test.@test occursin("weak dependence", e.msg)
40+
Test.@test occursin("ExtensionError called without dependencies", e.reason)
41+
end
42+
end
43+
44+
Test.@testset "Single dependency" begin
45+
e = Exceptions.ExtensionError(:MyExt)
46+
Test.@test e isa Exceptions.ExtensionError
47+
Test.@test e.weakdeps == (:MyExt,)
48+
Test.@test e.msg == "missing dependencies"
49+
end
50+
51+
Test.@testset "Multiple dependencies with message" begin
52+
e = Exceptions.ExtensionError(:Ext1, :Ext2; message="to enable feature X")
53+
Test.@test e isa Exceptions.ExtensionError
54+
Test.@test e.weakdeps == (:Ext1, :Ext2)
55+
Test.@test e.msg == "missing dependencies to enable feature X"
56+
end
57+
end
58+
59+
return nothing
60+
end
61+
62+
end # module
63+
64+
test_extension_error() = TestExtensionError.test_extension_error()

0 commit comments

Comments
 (0)