Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact output #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ before_install:
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
script:
# - julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("FactCheck"))`); Pkg.pin("FactCheck"); Pkg.resolve()'
- julia -e 'Pkg.clone("git://github.com/zachallaun/FactCheck.jl"); run(`ln -s $(pwd()) $(Pkg.dir("FactCheck"))`); Pkg.pin("FactCheck"); Pkg.resolve()'
- julia ~/.julia/FactCheck/test/test_factcheck.jl
- julia -e 'Pkg.init()'
- julia -e 'run(`ln -s $(pwd()) $(Pkg.dir("FactCheck"))`)'
- julia -e 'Pkg.pin("FactCheck"); Pkg.resolve()'
- julia ~/.julia/v0.3/FactCheck/test/test_factcheck.jl
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ julia> @runtest Stats means variability
# these tests pass silently
```

## Configuration

FactCheck has a configuration dictionary at `FactCheck.config`. Currently the
only option is `:compact`, which can be `true` or `false` to turn on or off
more compact output. The default is `false`, so to enable compact output simply
put `FactCheck.config[:compact] = true` before your tests.

## Travis

If you want to use FactCheck tests on Travis, you can emit the overall result of the tests like this:
Expand Down
55 changes: 45 additions & 10 deletions src/FactCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ export @fact,
anything,
irrelevant,
exactly,
roughly,
roughly,
@runtest

# this configuration block isn't exported but is intended to be accessed by
# users with "FactCheck.config"
config = {:compact => false}

allresults = {}

# HACK: get the current line number
Expand Down Expand Up @@ -68,6 +72,10 @@ type Error <: Result
meta::Dict
end

print_compact(io::IO, res::Success) = print(io, green("."))
print_compact(io::IO, res::Failure) = print(io, red("F"))
print_compact(io::IO, res::Error) = print(io, red("E"))

# Taken from Base.Test
#
# Allows Errors to be passed to `rethrow`:
Expand Down Expand Up @@ -190,10 +198,13 @@ function show(io::IO, suite::TestSuite)
end
end

function format_suite(suite::TestSuite)
s = suite.desc != nothing ? "$(suite.desc) " : ""
s = string(s, suite.filename != nothing ? "($(suite.filename))" : "")
bold(string(s, "\n"))
import Base.print
function print(io::IO, suite::TestSuite)
s = suite.desc != nothing ? "$(suite.desc)" : ""
if suite.filename != nothing
s = string(s, ": ($(suite.filename))")
end
print(io, s)
end

# FactCheck core functions and macros
Expand Down Expand Up @@ -224,6 +235,9 @@ function do_fact(thunk::Function, factex::Expr, meta::Dict)
Error(factex, err, catch_backtrace(), meta)
end

if config[:compact]
print_compact(STDOUT, result)
end
!isempty(handlers) && handlers[end](result)
push!(allresults, result)
result
Expand Down Expand Up @@ -290,11 +304,15 @@ function make_handler(suite::TestSuite)
end
function delayed_handler(r::Failure)
push!(suite.failures, r)
println(r)
if !config[:compact]
println(r)
end
end
function delayed_handler(r::Error)
push!(suite.errors, r)
println(r)
if !config[:compact]
println(r)
end
end
delayed_handler
end
Expand All @@ -320,12 +338,29 @@ function facts(f::Function, desc)
test_handler = make_handler(suite)
push!(handlers, test_handler)

println()
println(format_suite(suite))
print(suite)
if(config[:compact])
print(": ")
else
println()
end

f()

println(suite)
if(config[:compact])
println()
for res in suite.failures
show(res)
println()
end
for result in suite.errors
show(res)
println()
end
else
show(suite)
println()
end

pop!(handlers)
end
Expand Down
7 changes: 7 additions & 0 deletions test/test_factcheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ facts("FactCheck assertion helper functions") do

end

facts("Suite Printing") do
context("print shows suite name") do
suite = FactCheck.TestSuite("testfile.jl", "A Sweet Suite")
@fact string(suite) => "A Sweet Suite: (testfile.jl)"
end
end

exitstatus()

end # module
Expand Down