Skip to content

Commit fd4b80c

Browse files
authored
Merge branch 'master' into updated_ci_url
2 parents 4344fea + 7ed7cff commit fd4b80c

File tree

10 files changed

+143
-40
lines changed

10 files changed

+143
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.jl.cov
22
*.jl.*.cov
33
*.jl.mem
4+
coverage

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.4
8-
- 0.5
7+
- 0.6
98
notifications:
109
email: false
1110
# uncomment the following lines to override the default test script

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The DottedTestSets.jl package is licensed under the MIT "Expat" License:
1+
The TestSetExtensions.jl package is licensed under the MIT "Expat" License:
22

33
> Copyright (c) 2016: Spencer Russell.
44
>

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
[![Build status](https://ci.appveyor.com/api/projects/status/79m2ru7o3upt86ds/branch/master?svg=true)](https://ci.appveyor.com/project/ssfrr/testsetextensions-jl/branch/master)
55
[![codecov.io](http://codecov.io/github/ssfrr/TestSetExtensions.jl/coverage.svg?branch=master)](http://codecov.io/github/ssfrr/TestSetExtensions.jl?branch=master)
66

7-
![TestSetExtensions example gif](http://ssfrr.github.io/TestSetExtensions.jl/DottedTestSet.gif)
7+
![TestSetExtensions example gif](http://ssfrr.github.io/TestSetExtensions.jl/ExtendedTestSet.gif)
88

99
This package collects some extensions and convenience utilities to maximize your testing enjoyment. It builds on the new `Base.Test` infrastructure in Julia v0.5 (also available in v0.4 with the `BaseTestNext` package). It's designed so that you shouldn't need to modify your tests at all if you're already using `@testset` and `@test` - all the interactions with this package happen at the top-level of your tests.
1010

11-
## `DottedTestSet`
11+
## `ExtendedTestSet`
1212

13-
This is a simple TestSet type that outputs green dots as your tests pass, so you can have a sense of progress. To use it, simply add `DottedTestSet` as a custom testset type to your top-level `@testset`, and then use `Base.Test` as usual. All nested testsets will use it as well.
13+
The `ExtendedTestSet` type makes your test output more readable. It outputs green dots as your tests pass, so you can have a sense of progress. It also displays diffs on test failure using the [`DeepDiffs`](https://github.com/ssfrr/DeepDiffs.jl) package. To use it, simply add `ExtendedTestSet` as a custom testset type to your top-level `@testset`, and then use `Base.Test` functions as usual. All nested testsets will use it automatically.
1414

1515
```julia
1616
using Base.Test
1717
using TestSetExtensions
1818

19-
@testset DottedTestSet "All the tests" begin
19+
@testset ExtendedTestSet "All the tests" begin
2020
@testset "2nd-level tests 1" begin
2121
@test true
2222
@test 1 == 1
@@ -28,6 +28,10 @@ using TestSetExtensions
2828
end
2929
```
3030

31+
### Diff output example
32+
33+
![After diff output](http://ssfrr.github.io/TestSetExtensions.jl/diff_after.png)
34+
3135
## `@includetests`
3236
TestSetExtensions also provides a `@includetests` macro that makes it easy to selectively run your tests, for cases when your full test suite is large and you only need to run a subset of your tests to test a feature you're working on. The macro takes a list of test files, so you can pass it `ARGS` to allow the user to specify which tests to run from the command line.
3337

@@ -48,6 +52,6 @@ $ julia test/runtests.jl footests bartests
4852

4953
Which will run `footests.jl` and `bartests.jl`.
5054

51-
`@includetests` will print out each test module name as it goes (here in combination with `DottedTestSet`):
55+
`@includetests` will print out each test module name as it goes (here in combination with `ExtendedTestSet`):
5256

5357
![includetests output](http://ssfrr.github.io/TestSetExtensions.jl/includetests.png)

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
julia 0.4
2-
BaseTestNext
1+
julia 0.6.0-pre
2+
DeepDiffs

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
5-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
6-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
75

86
notifications:
97
- provider: Email

diffdemo.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Base.Test
2+
using TestSetExtensions
3+
4+
@testset ExtendedTestSet "Nice Diffs" begin
5+
@test [3, 5, 6, 1, 6, 8] == [3, 5, 6, 1, 9, 8]
6+
@test """Lorem ipsum dolor sit amet,
7+
consectetur adipiscing elit, sed do
8+
eiusmod tempor incididunt ut
9+
labore et dolore magna aliqua.
10+
Ut enim ad minim veniam, quis nostrud
11+
exercitation ullamco aboris.""" ==
12+
"""Lorem ipsum dolor sit amet,
13+
consectetur adipiscing elit, sed do
14+
eiusmod temper incididunt ut
15+
labore et dolore magna aliqua.
16+
Ut enim ad minim veniam, quis nostrud
17+
exercitation ullamco aboris."""
18+
@test Dict(:foo => "bar", :baz => [1, 4, 5], :biz => nothing) ==
19+
Dict(:baz => [1, 7, 5], :biz => 42)
20+
end

runtests.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Runs the SampledSignals tests including generating an lcov.info file
4+
5+
# abort on failure
6+
set -e
7+
8+
julia -e 'using Coverage; clean_folder(".");'
9+
julia --color=yes --inline=no --code-coverage=user test/runtests.jl
10+
mkdir -p coverage
11+
julia -e 'using Coverage; res=process_folder(); LCOV.writefile("coverage/lcov.info", res)'

src/TestSetExtensions.jl

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
module TestSetExtensions
22

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
1415

1516
"""
1617
Includes the given test files, given as a list without their ".jl" extensions.
@@ -44,25 +45,65 @@ macro includetests(testarg...)
4445
end
4546
end
4647

47-
type DottedTestSet{T<:AbstractTestSet} <: AbstractTestSet
48+
struct ExtendedTestSet{T<:AbstractTestSet} <: AbstractTestSet
4849
wrapped::T
4950

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)
5160
end
5261

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")
5596
end
5697

57-
function record(ts::DottedTestSet, res::Pass)
98+
function record(ts::ExtendedTestSet, res::Pass)
5899
print_with_color(:green, ".")
59100
record(ts.wrapped, res)
60101
res
61102
end
62103

63-
record(ts::DottedTestSet, res) = record(ts.wrapped, res)
104+
record(ts::ExtendedTestSet, res) = record(ts.wrapped, res)
64105

65-
function finish(ts::DottedTestSet)
106+
function finish(ts::ExtendedTestSet)
66107
get_testset_depth() == 0 && print("\n\n")
67108
finish(ts.wrapped)
68109
end

test/runtests.jl

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
using TestSetExtensions
22
using Suppressor
33

4-
if VERSION >= v"0.5.0-dev+7720"
5-
using Base.Test
6-
else
7-
using BaseTestNext
8-
end
4+
using Base.Test
95

106
orig_color = Base.have_color
117

128
eval(Base, :(have_color = true))
139
output_color = @capture_out begin
14-
@testset DottedTestSet "top-level tests" begin
10+
@testset ExtendedTestSet "top-level tests" begin
1511
@testset "2nd-level tests 1" begin
1612
@test true
1713
@test 1 == 1
@@ -25,7 +21,7 @@ end
2521

2622
eval(Base, :(have_color = false))
2723
output_nocolor = @capture_out begin
28-
@testset DottedTestSet "top-level tests" begin
24+
@testset ExtendedTestSet "top-level tests" begin
2925
@testset "2nd-level tests 1" begin
3026
@test true
3127
@test 1 == 1
@@ -39,7 +35,32 @@ end
3935

4036
eval(Base, :(have_color = $orig_color))
4137

42-
@testset DottedTestSet "TextSetExtensions Tests" begin
38+
39+
try
40+
info("You should see 3 failing tests with pretty diffs...")
41+
include(joinpath("..", "diffdemo.jl"))
42+
catch
43+
end
44+
try
45+
info("These 4 failing tests don't have pretty diffs to display")
46+
@testset ExtendedTestSet "not-pretty" begin
47+
@testset "No pretty diff for matrices" begin
48+
@test [1 2; 3 4] == [1 4; 3 4]
49+
end
50+
@testset "don't diff non-equality" begin
51+
@test 1 > 2
52+
end
53+
@testset "don't diff non-comparisons" begin
54+
@test iseven(7)
55+
end
56+
@testset "errors don't have diffs either" begin
57+
throw(ErrorException("This test is supposed to throw an error"))
58+
end
59+
end
60+
catch
61+
end
62+
63+
@testset ExtendedTestSet "TextSetExtensions Tests" begin
4364
@testset "check output" begin
4465
if VERSION <= v"0.6.0-"
4566
@test split(output_color, '\n')[1] == "\e[1m\e[32m.\e[0m\e[1m\e[32m.\e[0m\e[1m\e[32m.\e[0m\e[1m\e[32m.\e[0m"
@@ -49,6 +70,14 @@ eval(Base, :(have_color = $orig_color))
4970
@test split(output_nocolor, '\n')[1] == "...."
5071
end
5172

73+
74+
@testset "DottedTestSet is deprecated" begin
75+
@test_warn "DottedTestSet is deprecated, use ExtendedTestSet instead." @testset DottedTestSet "testing" begin
76+
@test true
77+
end
78+
end
79+
80+
5281
@testset "Auto-run test files" begin
5382
global file1_run = false
5483
global file2_run = false

0 commit comments

Comments
 (0)