|
1 | 1 | module TestSetExtensions
|
2 | 2 |
|
3 |
| -export DottedTestSet, @includetests |
4 |
| - |
5 |
| -if VERSION >= v"0.5.0-dev+7720" |
6 |
| - using Base.Test |
7 |
| - import Base.Test: record, finish |
8 |
| - using Base.Test: DefaultTestSet, AbstractTestSet, Pass, get_testset_depth |
9 |
| -else |
10 |
| - using BaseTestNext |
11 |
| - import BaseTestNext: record, finish |
12 |
| - using BaseTestNext: DefaultTestSet, AbstractTestSet, Pass, get_testset_depth |
13 |
| -end |
| 3 | +export ExtendedTestSet, @includetests |
| 4 | + |
| 5 | +using Base.Test |
| 6 | +import Base.Test: record, finish |
| 7 | +using Base.Test: DefaultTestSet, AbstractTestSet |
| 8 | +using Base.Test: get_testset_depth, scrub_backtrace |
| 9 | +using Base.Test: Result, Pass, Fail, Error |
| 10 | + |
| 11 | +using Base: @deprecate |
| 12 | +@deprecate DottedTestSet ExtendedTestSet |
| 13 | + |
| 14 | +using DeepDiffs |
14 | 15 |
|
15 | 16 | """
|
16 | 17 | Includes the given test files, given as a list without their ".jl" extensions.
|
@@ -44,25 +45,65 @@ macro includetests(testarg...)
|
44 | 45 | end
|
45 | 46 | end
|
46 | 47 |
|
47 |
| -type DottedTestSet{T<:AbstractTestSet} <: AbstractTestSet |
| 48 | +struct ExtendedTestSet{T<:AbstractTestSet} <: AbstractTestSet |
48 | 49 | wrapped::T
|
49 | 50 |
|
50 |
| - DottedTestSet(desc) = new(T(desc)) |
| 51 | + ExtendedTestSet{T}(desc) where {T} = new(T(desc)) |
| 52 | +end |
| 53 | + |
| 54 | +struct FailDiff <: Result |
| 55 | + result::Fail |
| 56 | +end |
| 57 | + |
| 58 | +function ExtendedTestSet(desc; wrap=DefaultTestSet) |
| 59 | + ExtendedTestSet{wrap}(desc) |
51 | 60 | end
|
52 | 61 |
|
53 |
| -function DottedTestSet(desc; wrap=DefaultTestSet) |
54 |
| - DottedTestSet{wrap}(desc) |
| 62 | +function record(ts::ExtendedTestSet, res::Fail) |
| 63 | + if myid() == 1 |
| 64 | + println("\n=====================================================") |
| 65 | + print_with_color(:white, ts.wrapped.description, ": ") |
| 66 | + if res.test_type == :test && isa(res.data,Expr) && res.data.head == :comparison |
| 67 | + dd = deepdiff(res.data.args[1], res.data.args[3]) |
| 68 | + if !isa(dd, DeepDiffs.SimpleDiff) |
| 69 | + # The test was an comparison between things we can diff, |
| 70 | + # so display the diff |
| 71 | + print_with_color(Base.error_color(), "Test Failed\n"; bold = true) |
| 72 | + println(" Expression: ", res.orig_expr) |
| 73 | + print_with_color(Base.info_color(), "\nDiff:\n") |
| 74 | + display(dd) |
| 75 | + println() |
| 76 | + else |
| 77 | + # fallback to the default printing if we don't have a pretty diff |
| 78 | + print(res) |
| 79 | + end |
| 80 | + else |
| 81 | + # fallback to the default printing for non-comparisons |
| 82 | + print(res) |
| 83 | + end |
| 84 | + Base.show_backtrace(STDOUT, scrub_backtrace(backtrace())) |
| 85 | + # show_backtrace doesn't print a trailing newline |
| 86 | + println("\n=====================================================") |
| 87 | + end |
| 88 | + push!(ts.wrapped.results, res) |
| 89 | + res, backtrace() |
| 90 | +end |
| 91 | + |
| 92 | +function record(ts::ExtendedTestSet, res::Error) |
| 93 | + println("\n=====================================================") |
| 94 | + record(ts.wrapped, res) |
| 95 | + print("=====================================================\n") |
55 | 96 | end
|
56 | 97 |
|
57 |
| -function record(ts::DottedTestSet, res::Pass) |
| 98 | +function record(ts::ExtendedTestSet, res::Pass) |
58 | 99 | print_with_color(:green, ".")
|
59 | 100 | record(ts.wrapped, res)
|
60 | 101 | res
|
61 | 102 | end
|
62 | 103 |
|
63 |
| -record(ts::DottedTestSet, res) = record(ts.wrapped, res) |
| 104 | +record(ts::ExtendedTestSet, res) = record(ts.wrapped, res) |
64 | 105 |
|
65 |
| -function finish(ts::DottedTestSet) |
| 106 | +function finish(ts::ExtendedTestSet) |
66 | 107 | get_testset_depth() == 0 && print("\n\n")
|
67 | 108 | finish(ts.wrapped)
|
68 | 109 | end
|
|
0 commit comments