Skip to content

Commit

Permalink
Context change
Browse files Browse the repository at this point in the history
  • Loading branch information
IainNZ committed Nov 7, 2014
1 parent d6f25fa commit 9b619b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* NEW: helper `anyof`: fact passes if expression matches any of the arguments to `anyof`.
* CHANGE: `roughly` now has a two-argument, no keyword, form where the second argument is taken to be `atol`.
* CHANGE: `context` didn't really do anything. Now, if not in compact mode, it'll print the context description indented. Gives a nice indication of progress when running a large number of tests inside a facts block.

## v0.2.0

Expand Down
13 changes: 8 additions & 5 deletions src/FactCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export @fact, @fact_throws, @pending,
roughly,
anyof

const INDENT = " "

# Global configuration for FactCheck
CONFIG = [:compact => false] # Compact output off by default
# Not exported: sets output style
Expand Down Expand Up @@ -72,26 +74,26 @@ format_line(r::Result) = string(

# Define printing functions for the result types
function Base.show(io::IO, f::Failure)
indent = isempty(handlers) ? "" : " "
indent = isempty(handlers) ? "" : INDENT
print_with_color(:red, io, indent, "Failure")
println(io, indent, format_line(f), " :: got ", f.val)
print(io, indent^2, format_assertion(f.expr))
end
function Base.show(io::IO, e::Error)
indent = isempty(handlers) ? "" : " "
indent = isempty(handlers) ? "" : INDENT
print_with_color(:red, io, indent, "Error")
println(io, indent, format_line(e))
println(io, indent^2, format_assertion(e.expr))
Base.showerror(io, e.err, e.backtrace)
print(io)
end
function Base.show(io::IO, s::Success)
indent = isempty(handlers) ? "" : " "
indent = isempty(handlers) ? "" : INDENT
print_with_color(:green, io, indent, "Success")
print(io, " :: $(format_assertion(s.expr))")
end
function Base.show(io::IO, p::Pending)
indent = isempty(handlers) ? "" : " "
indent = isempty(handlers) ? "" : INDENT
print_with_color(:yellow, io, indent, "Pending")
end

Expand Down Expand Up @@ -271,9 +273,10 @@ facts(f::Function) = facts(f, nothing)

# context
# Executes a battery of tests in some descriptive context, intended
# for use inside of facts
# for use inside of `facts`. Displays the string in default mode.
function context(f::Function, desc::String)
push!(contexts, desc)
!CONFIG[:compact] && println(INDENT, desc)
f()
pop!(contexts)
end
Expand Down

0 comments on commit 9b619b4

Please sign in to comment.