Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the rest of the formatting needed for icheck

  • Loading branch information...
commit eb49a00e72c0b8d37282472f2bfc10ba2b90c38e 1 parent 718540e
@olabini authored
View
6 docs/quickcheck
@@ -1,6 +0,0 @@
-STEPS LEFT:
-- Integrate with ISpec
- - Running them
- - Failing on exhaustion
- - Naming in some way
- - Check error messages
View
22 lib/ioke/icheck.ik
@@ -25,7 +25,7 @@ ICheck forAll = macro("takes zero or more generator arguments, zero or more guar
name: cc arguments[0] name,
predicate: LexicalBlock createFrom(argNames + [cc next], call ground)))
- Property with(block: block, generators: generators, guards: guards, classifiers: classifiers, fullDescription: fullDescription)
+ Property with(block: block, generators: generators, guards: guards, classifiers: classifiers, fullDescription: fullDescription, callMessage: call message, argumentNames: argNames map(name))
)
ICheck aliasMethod("forAll", "forEvery")
@@ -45,19 +45,26 @@ ICheck Property computeSize = method(maxSuccess, maxSize, successful, discarded,
maxMod == 0, (successful % maxSize),
(successful % maxSize) * (maxSize div(maxMod))) + discarded div(10))
-ICheck Property check! = method(maxSuccess: 100, maxDiscard: 500, maxSize: 100,
- result = Origin with(classifier: {} withDefault(0), succeeded: 0, discarded: 0)
+ICheck Property createResult = method(Origin with(classifier: {} withDefault(0), succeeded: 0, discarded: 0))
+
+ICheck Property check! = method(maxSuccess: 100, maxDiscard: 500, maxSize: 100, result: createResult,
while(result succeeded < maxSuccess && result discarded < maxDiscard,
- size = computeSize(maxSuccess, maxDiscard, result succeeded, result discarded)
+ size = computeSize(maxSuccess, maxSize, result succeeded, result discarded)
values = let(ICheck Property currentSize, size,
valuesFromGenerators)
if(!(guards all?(call(*values))),
result discarded += 1,
classify(values, result)
- block call(*values)
+ bind(
+ handle(Ground Condition,
+ fn(c, c currentValues = argumentNames zip(values))),
+ block call(*values)
+ )
result succeeded += 1)
)
result exhausted? = result succeeded < maxSuccess
+ if(result exhausted?,
+ result exhaustionStackTrace = "#{callMessage filename}:#{callMessage line}:#{callMessage position}")
result
)
@@ -143,8 +150,9 @@ ICheck Generators do(
Origin with(next: element))
sized(size,
result = Ground list
- choose(0, size) times(
- result << element next
+ val = choose(0, size)
+ val times(
+ result << element next
)
result
))
View
54 lib/ioke/ispec/formatter.ik
@@ -17,23 +17,42 @@ ISpec do(
println("#{counter})")
if(failure mimics?(ISpec Reporter Failure),
println(red("#{failure header}"))
+ if(failure condition cell?(:currentValues),
+ println(red(" Failing values:"))
+ failure condition currentValues each(v,
+ println(red(" #{v[0]}: #{v[1] inspect}"))))
println(red("#{failure condition report}"))
println(" #{failure condition example stackTraceAsText(failure condition)}"),
println(magenta("#{failure header}"))
- )
+ println("\n #{failure result exhaustionStackTrace}")
+ )
+
+ if(failure cell?(:propertyResult),
+ println("\n #{formatPropertyResult(failure propertyResult)}")
+ )
)
- dumpSummary = method(duration, exampleCount, failureCount, pendingCount,
+ dumpSummary = method(duration, exampleCount, failureCount, pendingCount, propertyCount, exhaustedCount, propertyInstanceCount, discardedCount,
println("")
println("Finished in #{duration} seconds")
println("")
summary = "#{exampleCount} example#{if(exampleCount == 1, "", "s")}, "
summary += "#{failureCount} failure#{if(failureCount == 1, "", "s")}"
+
if(pendingCount > 0,
summary += ", #{pendingCount} pending")
+ if(propertyCount > 0,
+ summary += " - #{propertyCount} propert#{if(propertyCount == 1, "y", "ies")}"
+ summary += ", #{propertyInstanceCount} succeeded"
+ if(exhaustedCount > 0,
+ summary += ", #{exhaustedCount} exhausted")
+ if(discardedCount > 0,
+ summary += ", #{discardedCount} discarded")
+ )
+
if(failureCount == 0,
if(pendingCount > 0,
println(yellow(summary)),
@@ -47,6 +66,14 @@ ISpec do(
pendingExamples each(pe,
println("#{pe[0]} (#{pe[1]})"))))
+ formatPropertyResult = method(result,
+ classifiers = if(result classifier empty?,
+ "",
+ " -%:[ %s: %s%]" % result classifier)
+
+ "#{result succeeded} succeeded, #{result discarded} discarded#{classifiers}"
+ )
+
colour = method(
"outputs text with colour if possible",
text, colour_code,
@@ -72,10 +99,22 @@ ISpec do(
println(red("- #{example description} (FAILED - #{counter})"))
)
+ propertyExampleFailed = method(example, counter, failure,
+ println(red("- #{example description} (FAILED - #{counter}) [#{formatPropertyResult(failure propertyResult)}]"))
+ )
+
+ propertyExampleExhausted = method(example, counter, result,
+ println(magenta("- #{example description} (EXHAUSTED - #{counter}) [#{formatPropertyResult(result)}]"))
+ )
+
examplePassed = method(example,
println(green("- #{example description}"))
)
+ propertyExamplePassed = method(example, result,
+ println(green("- #{example description} [#{formatPropertyResult(result)}]"))
+ )
+
examplePending = method(example, message,
super(example, message)
println(yellow("- #{example description} (PENDING: #{message})"))
@@ -104,7 +143,7 @@ ISpec do(
print(magenta("X"))
)
- propertyExampleFailed = method(example, counter, failure, result,
+ propertyExampleFailed = method(example, counter, failure,
print(red("@"))
)
@@ -184,7 +223,7 @@ ISpec do(
html div(class: "pending spec", "#{example description} (PENDING: #{message})") println
)
- dumpSummary = method(duration, exampleCount, failureCount, pendingCount, nil)
+ dumpSummary = method(duration, exampleCount, failureCount, pendingCount, propertyCount, exhaustedCount, propertyInstanceCount, discardedCount, nil)
dumpFailure = method(counter, failure, nil)
dumpPending = method(nil)
)
@@ -196,12 +235,17 @@ ISpec do(
examplePassed = method(example, nil)
examplePending = method(example, message, nil)
dumpFailure = method(counter, failure, nil)
- dumpSummary = method(duration, exampleCount, failureCount, pendingCount, nil)
+ dumpSummary = method(duration, exampleCount, failureCount, pendingCount, propertyCount, exhaustedCount, propertyInstanceCount, discardedCount, nil)
dumpPending = method(nil)
startDump = method(nil)
output = System out mimic do(close = nil)
close = method(output close)
println = method(a, output println(a))
print = method(a, output print(a))
+
+ propertyExampleStarted = method(example, nil)
+ propertyExamplePassed = method(example, result, nil)
+ propertyExampleExhausted = method(example, counter, result, nil)
+ propertyExampleFailed = method(example, counter, failure, nil)
)
)
View
9 lib/ioke/ispec/property_example.ik
@@ -5,8 +5,8 @@ ISpec do(
initialize = method(context, property,
self context = context mimic
self property = property
- self description = property fullDescription
- self fullDescription = property fullDescription
+ self description = property fullDescription replaceAll("\n", "\n ")
+ self fullDescription = property fullDescription replaceAll("\n", "")
)
fail? = false
@@ -19,7 +19,8 @@ ISpec do(
executionError = nil
reporter propertyExampleStarted(self)
- result = bind(
+ result = ICheck Property createResult
+ bind(
rescue(Ground Condition Error,
fn(c, executionError ||= c)),
rescue(ISpec Condition,
@@ -27,7 +28,7 @@ ISpec do(
handle(Ground Condition,
fn(c, c example = self)),
- property check!
+ property check!(result: result)
)
reporter propertyExampleFinished(self, executionError, result)
View
17 lib/ioke/ispec/reporter.ik
@@ -22,6 +22,7 @@ ISpec do(
newFailure = self mimic
newFailure example = example
newFailure result = result
+ newFailure propertyResult = result
newFailure)
header = method(
@@ -39,11 +40,16 @@ ISpec do(
@exampleGroups = []
@failures = []
@pendingCount = 0
+ @propertyCount = 0
+ @exhaustedCount = 0
+ @propertyInstanceCount = 0
+ @discardedCount = 0
@examples = []
@startTime = nil
@endTime = nil
)
+
formatters = method(options formatters)
addExampleGroup = method(exampleGroup,
@@ -54,7 +60,7 @@ ISpec do(
formatters each( exampleStarted(example) ))
propertyExampleStarted = method(example,
- formatters each( propertyExampleStarted(example) ))
+ formatters each(propertyExampleStarted(example) ))
exampleFinished = method(example, error nil,
examples << example
@@ -65,6 +71,9 @@ ISpec do(
exampleFailed(example, error))))
propertyExampleFinished = method(example, error, result,
+ @propertyCount += 1
+ @propertyInstanceCount += result succeeded
+ @discardedCount += result discarded
examples << example
if(error nil?,
if(result exhausted?,
@@ -81,8 +90,9 @@ ISpec do(
propertyExampleFailed = method(example, error, result,
failure = Failure create(example, error)
+ failure propertyResult = result
failures << failure
- formatters each(propertyExampleFailed(example, failures length, failure, result)))
+ formatters each(propertyExampleFailed(example, failures length, failure)))
start = method(numberOfExamples,
clear!
@@ -97,7 +107,7 @@ ISpec do(
dumpPending
dumpFailures
formatters each(f,
- f dumpSummary(duration, examples length, failures length, pendingCount)
+ f dumpSummary(duration, examples length, failures length, pendingCount, propertyCount, exhaustedCount, propertyInstanceCount, discardedCount)
f close)
failures length)
@@ -114,6 +124,7 @@ ISpec do(
examplePassed = method(example, formatters each(examplePassed(example)))
propertyExamplePassed = method(example, result, formatters each(propertyExamplePassed(example, result)))
propertyExampleExhausted = method(example, result,
+ @exhaustedCount += 1
failure = Exhaustion create(example, result)
failures << failure
formatters each(propertyExampleExhausted(example, failures length, result)))
View
12 test/icheck_spec.ik
@@ -588,7 +588,7 @@ describe(ICheck,
it("can take generators as well as constant values",
g1 = ICheck Generators oneOfFrequency(ICheck Generators boolean => 2, "one" => 1, "two" => 1, "three" => 1, ICheck Generators oneOf(4, 5) => 3)
got = #{}
- 50 times(got << g1 next)
+ 150 times(got << g1 next)
got should == #{"one", "two", "three", true, false, 4, 5}
)
)
@@ -1079,9 +1079,9 @@ describe(ICheck,
[x,y] sort should == [y,x] sort)
- ; this should fail
- forAll(int x, int y,
- [x,y] sort should == [x,y])
+ ; ; this should fail
+ ; forAll(int x, int y,
+ ; [x,y] sort should == [x,y])
forAll([] sort should == [])
forAll(int x,
@@ -1093,7 +1093,7 @@ describe(ICheck,
forEvery(integer x, integer y,
[x, y] max should >= [x, y] min)
- forAll(int x, where: x > 1000000000000000,
- x should == x)
+ ; forAll(int x, where: x > 1000000000000000,
+ ; x should == x)
)
)
Please sign in to comment.
Something went wrong with that request. Please try again.