minigrace
Version:
A compiler for the Grace programming language
941 lines (940 loc) • 262 kB
JavaScript
let gracecode_gUnit_sourceFile = "/Users/black/Development/mg/gracelang/minigrace/modules/gUnit.grace";
let gracecode_gUnit_sha256 = "40e0131e9bd63eeefedebf1c32db4d84dc63b0ed7ce2b17c03da8aa7932c2eea";
let gracecode_gUnit_minigraceRevision = "b57591d29fc5ee5270d114920bf671367b8c3ecb";
let gracecode_gUnit_minigraceGeneration = "5171";
if (typeof gctCache !== "undefined")
gctCache["gUnit"] = "dialect:\n standard\nfreshScopes:\n $100 trait\n $104\n $105\n $106\n $108\nmethodTypes:$100:\n assert(bb:Boolean) \u2192 Unknown\n assert(bb:Boolean)description(str:Unknown) \u2192 Unknown\n assert(block0:Procedure0)shouldRaise(desiredException:Pattern)matchedBy(regexStr:Unknown) \u2192 Unknown\n assert(block0:Procedure0)shouldRaise(desiredException:Pattern)mentioning(error1:String)and(error2:String) \u2192 Unknown\n assert(n1:Number)shouldEqual(n2:Number)within(epsilon:Number) \u2192 Unknown\n assert(s1:Object)shouldBe(s2:Object) \u2192 Unknown\n assert(s1:Object)shouldntBe(s2:Object) \u2192 Unknown\n assert(value:Unknown)hasType(Desired:Type) \u2192 Unknown\n assertType(T:Type)describes(value:Unknown) \u2192 Unknown\n assertType(T:Type)exactlyDescribes(anObject:Unknown) \u2192 Unknown\n deny(bb:Boolean) \u2192 Unknown\n deny(bb:Boolean)description(str:Unknown) \u2192 Unknown\n deny(s1:Object)shouldBe(s2:Object) \u2192 Unknown\n deny(value:Unknown)hasType(Undesired:Type) \u2192 Unknown\nmethodTypes:$103:\n testCaseNamed(name':Unknown) \u2192 TestCase\nmodules:\n collections\n mirror\n regularExpression\n standard\n sys\npath:\n /Users/black/Development/mg/gracelang/minigrace/modules/gUnit.grace\nscope:$100:\n AssertionFailure Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n assert(1) Unknown (mth) $scope_done\n assert(1)description(1) Unknown (mth) $scope_done\n assert(1)hasType(1) Unknown (mth) $scope_done\n assert(1)shouldBe(1) Unknown (mth) $scope_done\n assert(1)shouldEqual(1)within(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)matchedBy(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)mentioning(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)mentioning(1)and(1) Unknown (mth) $scope_done\n assert(1)shouldntBe(1) Unknown (mth) $scope_done\n assert(1)shouldntRaise(1) Unknown (mth) $scope_done\n assertType(1)describes(1) Unknown (mth) $scope_done\n assertType(1)exactlyDescribes(1) Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n countOneAssertion Unknown (mth) $scope_done\n deny(1) Unknown (mth) $scope_done\n deny(1)description(1) Unknown (mth) $scope_done\n deny(1)hasType(1) Unknown (mth) $scope_done\n deny(1)shouldBe(1) Unknown (mth) $scope_done\n failBecause(1) Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n methodsIn(1)missingFrom(1) String (mth) $scope_done confidential\n myIdentityHash Number (go) $scope_number\n protocolOf(1)notCoveredBy(1) String (mth) $scope_done confidential\nscope:$103:\n Assertion type\n TestCase type\n TestRecord type\n TestResult type\n TestSuite type\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n assertion Unknown (mth) $100\n basicAsString String (go) $scope_string\n className(1) Unknown (mth) $scope_done\n exit Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n numberOfErrorsToRerun Unknown (var) $scopeEmpty public\n numberOfErrorsToRerun:=(1) Unknown (var) $scopeEmpty public\n testCaseNamed(1) TestCase (mth) $104\n testRecordFor(1)message(1) Unknown (mth) $106\n testResult Unknown (mth) $105\n testSuite Unknown (def) $107 public\nscope:$104:\n AssertionFailure Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n assert(1) Unknown (mth) $scope_done\n assert(1)description(1) Unknown (mth) $scope_done\n assert(1)hasType(1) Unknown (mth) $scope_done\n assert(1)shouldBe(1) Unknown (mth) $scope_done\n assert(1)shouldEqual(1)within(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)matchedBy(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)mentioning(1) Unknown (mth) $scope_done\n assert(1)shouldRaise(1)mentioning(1)and(1) Unknown (mth) $scope_done\n assert(1)shouldntBe(1) Unknown (mth) $scope_done\n assert(1)shouldntRaise(1) Unknown (mth) $scope_done\n assertType(1)describes(1) Unknown (mth) $scope_done\n assertType(1)exactlyDescribes(1) Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n countOneAssertion Unknown (mth) $scope_done\n currentResult Unknown (var) $scopeEmpty\n currentResult:=(1) Unknown (var) $scopeEmpty\n debug(1) Unknown (mth) $scope_done\n debugAndPrintResults Unknown (mth) $scope_done\n deny(1) Unknown (mth) $scope_done\n deny(1)description(1) Unknown (mth) $scope_done\n deny(1)hasType(1) Unknown (mth) $scope_done\n deny(1)shouldBe(1) Unknown (mth) $scope_done\n failBecause(1) Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n methodsIn(1)missingFrom(1) String (mth) $scope_done confidential\n myIdentityHash Number (go) $scope_number\n name Unknown (mth) $scope_done\n printBackTrace(1)limitedTo(1) Unknown (mth) $scope_done\n protocolOf(1)notCoveredBy(1) String (mth) $scope_done confidential\n run(1) Unknown (mth) $scope_done\n runAndPrintResults Unknown (mth) $scope_done\n runTest Unknown (mth) $scope_done\n setup Unknown (mth) $scope_done\n size Unknown (def) $scope_number public\n teardown Unknown (mth) $scope_done\nscope:$105:\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n countOneAssertion Unknown (mth) $scope_done\n currentCountOfAssertions Unknown (var) $scopeEmpty\n currentCountOfAssertions:=(1) Unknown (var) $scopeEmpty\n detailedSummary Unknown (mth) $scope_done\n errorSet Unknown (var) $scopeEmpty\n errorSet:=(1) Unknown (var) $scopeEmpty\n erroredTestNames Unknown (mth) $scope_done\n errors Unknown (mth) $scope_done\n failSet Unknown (var) $scopeEmpty\n failSet:=(1) Unknown (var) $scopeEmpty\n failedTestNames Unknown (mth) $scope_done\n failures Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n numberOfErrors Unknown (mth) $scope_done\n numberOfFailures Unknown (mth) $scope_done\n numberRun Unknown (mth) $scope_done\n runCount Unknown (var) $scopeEmpty\n runCount:=(1) Unknown (var) $scopeEmpty\n summary Unknown (mth) $scope_done\n testErrored(1)withMessage(1) Unknown (mth) $scope_done\n testFailed(1)withMessage(1) Unknown (mth) $scope_done\n testFinished(1) Unknown (mth) $scope_done\n testStarted(1) Unknown (mth) $scope_done\nscope:$106:\n ::(1) Unknown (mth) $scope_done\n <(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >(1) Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n compare(1) Unknown (mth) $scope_done\n hash Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n message Unknown (def) $scopeEmpty public\n myIdentityHash Number (go) $scope_number\n name Unknown (def) $scopeEmpty public\n prefix== Unknown (mth) $scope_done\n prefix\u2260 Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\n \u2264(1) Unknown (mth) $scope_done\n \u2265(1) Unknown (mth) $scope_done\nscope:$107:\n asDebugString String (go) $scope_string\n asString String (go) $scope_string\n basicAsString String (go) $scope_string\n empty Unknown (mth) $scope_done\n fromTestMethodsIn(1) Unknown (mth) $scope_done\n fromTestMethodsIn(1)named(1) Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n myIdentityHash Number (go) $scope_number\n withAll(1) Unknown (mth) $108\nscope:$108:\n ++(1) Unknown (mth) $scope_done\n <<(1) Unknown (mth) $scope_done\n ==(1) Unknown (mth) $scope_done\n >>(1) Unknown (mth) $scope_done\n add(1) Unknown (mth) $scope_done\n addAll(1) Unknown (mth) $scope_done\n allSatisfy(1) Unknown (mth) $scope_done\n anySatisfy(1) Unknown (mth) $scope_done\n asDebugString String (go) $scope_string\n asString Unknown (mth) $scope_done\n basicAsString String (go) $scope_string\n contains(1) Unknown (mth) $scope_done\n debug(1) Unknown (mth) $scope_done\n debugAndPrintResults Unknown (mth) $scope_done\n do(1) Unknown (mth) $scope_done\n do(1)separatedBy(1) Unknown (mth) $scope_done\n doNotRerunErrors Unknown (mth) $scope_done\n doRerunErrors Unknown (mth) $scope_done\n errorsToBeRerun Unknown (var) $scopeEmpty\n errorsToBeRerun:=(1) Unknown (var) $scopeEmpty\n filter(1) Enumerable (mth) $scope_done\n first Unknown (mth) $scope_done\n fold(1)startingWith(1) R (mth) $scope_done\n isEmpty Unknown (mth) $scope_done\n isMe(1) Boolean (go) $scope_boolean\n iterator Unknown (mth) $scope_done\n keysAndValuesDo(1) Done (mth) $scope_done\n map(1) Unknown (mth) $scope_done\n myIdentityHash Number (go) $scope_number\n name Unknown (var) $scopeEmpty public\n name:=(1) Unknown (var) $scopeEmpty public\n rerunErrors(1) Unknown (mth) $scope_done\n run(1) Unknown (mth) $scope_done\n runAndPrintResults Unknown (mth) $scope_done\n size Unknown (mth) $scope_done\n sizeIfUnknown(1) Unknown (mth) $scope_done\n sorted List (mth) $scope_done\n sortedBy(1) List (mth) $scope_done\n testAt(1) Unknown (mth) $scope_done\n testNames Unknown (def) $scopeUniv\n tests Unknown (def) $scope_done\n values Collection (mth) $scope_done\n while(1)do(1) Unknown (mth) $scope_done\n \u2260(1) Unknown (mth) $scope_done\nself:\n $103\ntypedec:$103.Assertion:\n type Assertion = interface {\n assert(bb:Boolean)description(str:String) \u2192 Done\n deny(bb:Boolean)description(str:String) \u2192 Done\n assert(bb:Boolean) \u2192 Done\n deny(bb:Boolean) \u2192 Done\n assert(s1:Object)shouldBe(s2:Object) \u2192 Done\n assert(s1:Object)shouldntBe(s2:Object) \u2192 Done\n assert(n1:Number)shouldEqual(n2:Number)within(epsilon:Number) \u2192 Done\n assert(b:Procedure0)shouldRaise(desireed:ExceptionKind) \u2192 Done\n assert(b:Procedure0)shouldntRaise(undesired:ExceptionKind) \u2192 Done\n assert(s:Object)hasType(t:Type) \u2192 Done\n deny(s:Object)hasType(t:Type) \u2192 Done\n assertType(T:Type)describes(value) \u2192 Done\n failBecause(Message:String) \u2192 Done}\ntypedec:$103.TestCase:\n type TestCase = Assertion & interface {\n run(_:TestResult) \u2192 Done\n debug(_:TestResult) \u2192 Done\n size \u2192 Number\n name \u2192 String}\ntypedec:$103.TestRecord:\n type TestRecord = interface {\n name \u2192 String\n message \u2192 String}\ntypedec:$103.TestResult:\n type TestResult = interface {\n testStarted(name:String) \u2192 Done\n testFailed(name:String) \u2192 Done\n testErrored(name:String) \u2192 Done\n testFinished(name:String) \u2192 Done\n erroredTestNames \u2192 List\u27e6String\u27e7\n failedTestNames \u2192 List\u27e6String\u27e7\n summary \u2192 String\n detailedSummary \u2192 String\n numberOfErrors \u2192 Number\n errors \u2192 List\u27e6TestRecord\u27e7\n numberOfFailures \u2192 Number\n failures \u2192 List\u27e6TestRecord\u27e7\n numberRun \u2192 Number\n doNotRerunErrors \u2192 Done\n doRerunErrors \u2192 Done}\ntypedec:$103.TestSuite:\n type TestSuite = TestCase & interface {\n add(t:TestCase) \u2192 Done\n rerunErrors(r:TestResult) \u2192 Done}\ntypes:\n $103.Assertion\n $103.TestCase\n $103.TestRecord\n $103.TestResult\n $103.TestSuite\n";
if (typeof originalSourceLines !== "undefined") {
originalSourceLines["gUnit"] = [
"dialect \"standard\"",
"// GUnit.grace",
"// GUnit project",
"//",
"// Created by Andrew Black on 6/26/12.",
"",
"import \"collections\" as collections",
"import \"mirror\" as mirror",
"import \"sys\" as sys",
"import \"regularExpression\" as regularExpression",
"",
"type Assertion = interface { ",
" assert(bb:Boolean) description(str:String) -> Done",
" deny(bb:Boolean) description (str:String) -> Done",
" assert(bb:Boolean) -> Done",
" deny(bb:Boolean) -> Done",
" assert(s1:Object) shouldBe(s2:Object) -> Done",
" assert(s1:Object) shouldntBe(s2:Object) -> Done",
" assert(n1:Number) shouldEqual(n2:Number) within(epsilon:Number) -> Done",
" assert(b:Procedure0) shouldRaise(desireed:ExceptionKind) -> Done",
" assert(b:Procedure0) shouldntRaise(undesired:ExceptionKind) -> Done",
" assert(s:Object) hasType(t:Type) -> Done",
" deny(s:Object) hasType(t:Type) -> Done",
" assertType(T:Type) describes (value) -> Done",
" failBecause(Message:String) -> Done",
"}",
" ",
"type TestCase = Assertion & interface {",
" run(_:TestResult) -> Done",
" debug(_:TestResult) -> Done",
" size -> Number",
" name -> String",
"}",
"",
"type TestRecord = interface {",
" name -> String",
" message -> String",
"}",
"",
"type TestResult = interface {",
" testStarted(name:String) -> Done",
" testFailed(name:String) -> Done",
" testErrored(name:String) -> Done",
" testFinished(name:String) -> Done",
" erroredTestNames -> List⟦String⟧",
" failedTestNames -> List⟦String⟧",
" summary -> String",
" detailedSummary -> String",
" numberOfErrors -> Number",
" errors -> List⟦TestRecord⟧",
" numberOfFailures -> Number",
" failures -> List⟦TestRecord⟧",
" numberRun -> Number",
" doNotRerunErrors -> Done",
" doRerunErrors -> Done",
"}",
"",
"type TestSuite = TestCase & interface {",
" add(t:TestCase) -> Done",
" rerunErrors(r:TestResult) -> Done",
"}",
"",
"var numberOfErrorsToRerun is public := 10",
"var someTestDidNotPass := false",
"",
"trait assertion {",
" once method AssertionFailure {",
" Exception.refine \"AssertionFailure\"",
" }",
" method countOneAssertion { abstract }",
" ",
" method failBecause(str) {",
" assert (false) description (str)",
" }",
" method assert(bb: Boolean) description(str) {",
" countOneAssertion",
" if (! bb) then { AssertionFailure.raise(str) }",
" }",
" method deny(bb: Boolean) description (str) {",
" assert (! bb) description (str)",
" }",
" method assert(bb: Boolean) {",
" assert (bb) description \"Assertion failed!\"",
" }",
" method deny(bb: Boolean) {",
" assert (! bb)",
" }",
" method assert(s1:Object) shouldBe (s2:Object) {",
" assert (s1 == s2)",
" description \"‹{s1.asDebugString}› should be ‹{s2.asDebugString}›\"",
" }",
" method assert(s1:Object) shouldntBe (s2:Object) {",
" assert ((s1 == s2).not)",
" description \"‹{s1.asDebugString}› should not be ‹{s2.asDebugString}›\"",
" }",
" method deny(s1:Object) shouldBe (s2:Object) {",
" assert ((s1 == s2).not)",
" description \"‹{s1.asDebugString}› should not be ‹{s2.asDebugString}›\"",
" }",
" method assert(n1:Number) shouldEqual (n2:Number) within (epsilon:Number) {",
" assert ((n1 - n2).abs ≤ epsilon)",
" description \"‹{n1.asDebugString}› should be approximately ‹{n2.asDebugString}›\"",
" }",
" method assert(block0) shouldRaise (desiredException) {",
" assert(block0) shouldRaise (desiredException) mentioning \"\" and \"\"",
" }",
" method assert(block0) shouldRaise (desiredException) mentioning (error) {",
" assert(block0) shouldRaise (desiredException) mentioning (error) and \"\"",
" }",
" method assert(block0:Procedure0) shouldRaise (desiredException:Pattern)",
" mentioning (error1:String) and (error2:String) {",
" var completedNormally := true",
" countOneAssertion",
" try {",
" block0.apply",
" } catch { raisedException:desiredException ->",
" completedNormally := false",
" if (raisedException.message.contains(error1).not) then {",
" failBecause(\"code raised exception {raisedException.exception} as expected,\"",
" ++ \" but the message was\\n\\\"{raisedException.message}\\\",\"",
" ++ \" which does not mention\\n\\\"{error1}\\\"\")",
" }",
" if (raisedException.message.contains(error2).not) then {",
" failBecause(\"code raised exception {raisedException.exception} as expected,\"",
" ++ \" but the message was\\n\\\"{raisedException.message}\\\",\"",
" ++ \" which does not mention\\n\\\"{error2}\\\"\")",
" }",
" } catch { raisedException ->",
" completedNormally := false",
" failBecause(\"code raised exception {raisedException.exception}\" ++",
" \": \\\"{raisedException.message}\\\" instead of {desiredException}\")",
" } finally {",
" if (completedNormally) then {",
" failBecause \"code did not raise an exception\"",
" }",
" }",
" }",
" method assert(block0:Procedure0) shouldRaise (desiredException:Pattern)",
" matchedBy (regexStr) {",
" var completedNormally := true",
" countOneAssertion",
" try {",
" block0.apply",
" } catch { raisedException:desiredException ->",
" completedNormally := false",
" if (regularExpression.fromString(regexStr).matches(raisedException.message).not) then {",
" failBecause(\"code raised exception {raisedException.exception} as expected,\"",
" ++ \" but the message was\\n\\\"{raisedException.message}\\\",\"",
" ++ \" which is not matched by \\\"{regexStr}\\\"\")",
" }",
" } catch { raisedException ->",
" completedNormally := false",
" failBecause(\"code raised exception {raisedException.exception}\" ++",
" \": \\\"{raisedException.message}\\\" instead of {desiredException}\")",
" } finally {",
" if (completedNormally) then {",
" failBecause \"code did not raise an exception\"",
" }",
" }",
" }",
"",
" method assert(block0) shouldntRaise (undesiredException) {",
" countOneAssertion",
" try {",
" block0.apply",
" } catch { raisedException:undesiredException ->",
" failBecause \"code raised exception {raisedException.exception}\"",
" } catch { _ -> ",
" // do nothing; it's OK to raise a different exception.",
" }",
" }",
" method assert(value) hasType (Desired:Type) {",
" if (Desired.matches(value)) then {",
" countOneAssertion",
" } else {",
" def m = methodsIn(Desired) missingFrom (value)",
" def s = if (m.contains \" \") then { \"s\" } else { \"\" }",
" failBecause \"{value.asDebugString} does not have {Desired}; it's missing method{s} {m}.\"",
" }",
" }",
" method assertType(T:Type) describes (value) {",
" def missingFromT = protocolOf(value) notCoveredBy(T)",
" assert (missingFromT.isEmpty) description (missingFromT)",
" }",
"",
" method assertType(T:Type) exactlyDescribes (anObject) {",
" assert(anObject) hasType (T)",
" assertType(T) describes (anObject)",
" }",
"",
" method methodsIn(DesiredType) missingFrom (value) -> String is confidential {",
" def vMirror = mirror.reflect(value)",
" def allMethods = vMirror.methodNames",
" def publicMethods = allMethods.filter{ each ->",
" vMirror.onMethod(each).isPublic} >> set",
" def tMethods = DesiredType.methodNames >> set",
" def missing = tMethods -- publicMethods",
" if (missing.isEmpty) then {",
" ProgrammingError.raise \"{value.asDebugString} seems to have all the methods of {DesiredType}\"",
" } else {",
" var s := \"\"",
" missing.do { each -> s := s ++ each } ",
" separatedBy { s := s ++ \", \" }",
" s",
" }",
" }",
" method protocolOf(value) notCoveredBy (Q:Type) -> String is confidential {",
" var s := \"\"",
" def vMirror = mirror.reflect(value)",
" def allMethods = vMirror.methodNames",
" def publicMethods = allMethods.filter{ each ->",
" vMirror.onMethod(each).isPublic} >> set",
" def qMethods = Q.methodNames >> set",
" def missing = publicMethods -- qMethods",
" if (missing.isEmpty.not) then {",
" s := \"{Q} is missing \"",
" missing.do { each -> s := s ++ each } ",
" separatedBy { s := s ++ \", \" }",
" }",
" return s",
" }",
" method deny(value) hasType (Undesired:Type) {",
" if (Undesired.matches(value)) then {",
" failBecause \"{value.asDebugString} has type {Undesired}\"",
" } else { ",
" countOneAssertion ",
" }",
" }",
"}",
"",
"class testCaseNamed(name') -> TestCase {",
" use assertion",
"",
" def size is public = 1",
" var currentResult",
" method name {name'}",
"",
" method setup { }",
" method teardown { }",
" method countOneAssertion {",
" currentResult.countOneAssertion",
" }",
"",
" method run (result) {",
" currentResult := result",
" result.testStarted(name)",
" try {",
" try {",
" setup",
" runTest",
" } finally { teardown }",
" } catch {e: self.AssertionFailure ->",
" result.testFailed(name)withMessage(e.message)",
" } catch {e: Exception ->",
" result.testErrored(name)withMessage \"{e.exception}: {e.message}\"",
" }",
" result.testFinished(name)",
" }",
"",
" method debug (result) {",
" currentResult := result",
" result.testStarted(name)",
" try {",
" print \"\\ndebugging method {name} ...\"",
" try {",
" setup",
" runTest",
" } finally { teardown }",
" } catch {e: Exception ->",
" result.testErrored(name)withMessage(e.message)",
" printBackTrace(e) limitedTo(name)",
" }",
" result.testFinished(name)",
" }",
" ",
" method runTest {",
" def methodImage = mirror.reflect(self).onMethod(name)",
" methodImage.requestWithArgs []",
" }",
"",
" method printBackTrace(exceptionPacket) limitedTo(testName) {",
" def ex = exceptionPacket.exception",
" def msg = exceptionPacket.message",
" def lineNr = exceptionPacket.line",
" def modName = exceptionPacket.moduleName",
" if (lineNr == 0) then {",
" if (modName == \"native code\") then {",
" print \"{ex}: {msg}\"",
" } else {",
" print \"{ex} in {modName}: {msg}\"",
" }",
" } else {",
" print \"{ex} on line {lineNr} of {modName}: {msg}\"",
" }",
" def bt = exceptionPacket.backtrace",
" bt.reversed.do { frameDescription ->",
" print(\" requested from \" ++ frameDescription)",
" if (frameDescription.contains(testName)) then { return }",
" if (frameDescription.contains \"test(_)by(_)\") then { ",
" // this is for minitest, where testName won't be on the stack",
" return",
" }",
" }",
" }",
"",
" method runAndPrintResults {",
" def result = testResult",
" self.run(result)",
" if (name == \"\") then {",
" print \"{result.detailedSummary}\"",
" } else {",
" print \"{self.name}: {result.detailedSummary}\"",
" }",
" }",
" ",
" method debugAndPrintResults {",
" def result = testResult",
" self.debug(result)",
" if (name == \"\") then {",
" print \"{result.detailedSummary}\"",
" } else {",
" print \"{self.name}: {result.detailedSummary}\"",
" }",
" }",
"}",
"",
"",
"class testResult {",
" var failSet := set.empty",
" var errorSet := set.empty",
" var runCount := 0",
" var currentCountOfAssertions := 0",
"",
" method countOneAssertion {",
" currentCountOfAssertions := currentCountOfAssertions + 1",
" }",
"",
" method testStarted(name) {",
" runCount := runCount + 1",
" currentCountOfAssertions := 0",
" }",
"",
" method testFinished(name) {",
" if(currentCountOfAssertions == 0) then {",
" failSet.add(testRecordFor(name)message(\"no assertions were checked in this test\"))",
" }",
" }",
" ",
" method testFailed(name)withMessage(msg) {",
" failSet.add(testRecordFor(name)message(msg))",
" someTestDidNotPass := true",
" }",
" ",
" method testErrored(name)withMessage(msg) {",
" errorSet.add(testRecordFor(name)message(msg))",
" someTestDidNotPass := true",
" currentCountOfAssertions := 1 // to prevent the \"no assertions\" failure",
" }",
" ",
" method summary {",
" def s = if (numberOfErrors == 1) then {\"\"} else {\"s\"}",
" \"{runCount} run, {numberOfFailures} failed, {numberOfErrors} error{s}\"",
" }",
" ",
" method detailedSummary {",
" var output := summary",
" if (numberOfFailures > 0) then {",
" output := output ++ \"\\nFailures:\"",
" for (list.withAll(failSet).sort) do { each ->",
" output := output ++ \"\\n \" ++ each",
" }",
" }",
" if (numberOfErrors > 0) then {",
" output := output ++ \"\\nErrors:\"",
" for (list.withAll(errorSet).sort) do { each ->",
" output := output ++ \"\\n \" ++ each",
" }",
" }",
" output",
" }",
" ",
" method numberOfErrors {",
" errorSet.size",
" }",
" ",
" method errors {",
" list.withAll(errorSet).sort",
" }",
" ",
" method erroredTestNames {",
" list.withAll(errorSet.map{each -> each.name}).sort",
" }",
" ",
" method numberOfFailures {",
" failSet.size",
" }",
" ",
" method failures {",
" list.withAll(failSet).sort",
" }",
" ",
" method failedTestNames {",
" list.withAll(failSet.map{each -> each.name}).sort",
" }",
" ",
" method numberRun {",
" runCount",
" }",
"}",
"",
"class testRecordFor(testName)message(testMsg) {",
" use equality",
" def name is public = testName",
" def message is public = testMsg",
" method asString {\"{name}: {testMsg}\"}",
" method hash {name.hash}",
" method compare(other) { name.compare(other.name) }",
" method < (other) { name < other.name }",
" method ≤ (other) { name ≤ other.name }",
" method == (other) { name == other.name }",
" method > (other) { name < other.name }",
" method ≥ (other) { name ≥ other.name }",
"}",
"",
"def testSuite is public = object {",
"",
" class withAll(initialContents) {",
" use collections.enumerable",
" var name is public := \"\"",
" def tests = list [ ]",
" def testNames = set.empty",
" var errorsToBeRerun := true",
"",
" method doNotRerunErrors { errorsToBeRerun := false }",
" method doRerunErrors { errorsToBeRerun := true }",
" for (initialContents) do { each -> self.add(each) }",
" ",
" method add(e) {",
" def eName = e.name",
" if (testNames.contains (eName)) then {",
" print \"Warning: more than one test named \\\"{eName}\\\"\"",
" } else {",
" testNames.add(eName)",
" }",
" tests.push(e)",
" }",
"",
" method testAt(index) {",
" tests.at(index)",
" }",
" ",
" method run(result) {",
" for (tests) do { each -> each.run(result) }",
" }",
" ",
" method debug(result) {",
" for (tests) do { each -> each.debug(result) }",
" }",
"",
" method size { tests.size }",
" ",
" method runAndPrintResults {",
" def result = testResult",
" self.run(result)",
" if (name == \"\") then {",
" print \"{result.detailedSummary}\"",
" } else {",
" print \"{self.name}: {result.detailedSummary}\"",
" }",
" if ((result.numberOfErrors > 0) && errorsToBeRerun) then {",
" rerunErrors(result)",
" }",
" }",
" ",
" method debugAndPrintResults {",
" def result = testResult",
" self.debug(result)",
" if (name == \"\") then {",
" print \"{result.detailedSummary}\"",
" } else {",
" print \"{self.name}: {result.detailedSummary}\"",
" }",
" }",
" ",
" method iterator { tests.iterator }",
" method do (aBlock) { tests.do (aBlock) }",
" method addAll(anotherSuite) {",
" anotherSuite.do { each -> self.add(each) }",
" self",
" }",
" method ++ (anotherSuite) {",
" outer.withAll(tests).addAll(anotherSuite)",
" }",
" method rerunErrors(result) {",
" if (numberOfErrorsToRerun ≤ 0) then { return }",
" var n := min(result.numberOfErrors, numberOfErrorsToRerun)",
" if (n == 1) then {",
" print \"\\nRe-running 1 error.\"",
" } else {",
" print \"\\nRe-running {n} errors.\"",
" }",
" def newResult = testResult",
" def errors = result.erroredTestNames",
" tests.do { each ->",
" if (errors.contains(each.name)) then {",
" each.debug(newResult)",
" n := n - 1",
" if (n == 0) then { return }",
" }",
" }",
" }",
" }",
" ",
" method empty { withAll [] }",
" ",
" method fromTestMethodsIn(aTestClass) named (aName) {",
" def newSuite = self.empty",
" def example = aTestClass.forMethod(\"null\")",
" newSuite.name := aName",
" for (mirror.reflect(example).methods) do { each ->",
" if (each.name.startsWith \"test\") then {",
" if (! each.name.contains \"$\") then {",
" // we should also check that there are no arguments",
" // but the C-backend needs to emit the metadata",
" newSuite.add(aTestClass.forMethod(each.name))",
" }",
" }",
" }",
" newSuite",
" }",
" ",
" method fromTestMethodsIn(aTestClass) {",
" fromTestMethodsIn(aTestClass) named (className(aTestClass))",
" }",
"}",
"",
"method className(testClass) {",
" def cName = testClass.asString",
" if (cName.startsWith \"class \") then {",
" cName.substringFrom 7 to (cName.size)",
" } elseif { cName.startsWith \"trait \" } then {",
" cName.substringFrom 7 to (cName.size)",
" } elseif { cName.startsWith \"a \" } then {",
" cName.substringFrom 3 to (cName.size)",
" } elseif { cName.startsWith \"an \" } then {",
" cName.substringFrom 4 to (cName.size)",
" } else {",
" \"un-named\"",
" }",
"}",
"",
"method exit {",
" // exit the program with a a return code",
" // Exit code zero means that all tests passed;",
" // exit code 1 means that at least one test did not pass.",
" if (someTestDidNotPass.not) then { print \"all tests passed\" }",
" sys.exit(if (someTestDidNotPass) then {1} else {10})",
"}" ];
}
function gracecode_gUnit() {
importedModules["gUnit"] = this;
const var_$module = this;
this.definitionModule = "gUnit";
this.definitionLine = 1;
setLineNumber(1); // compilenode dialect
// Dialect "standard"
const var_$dialect = do_import("standard", gracecode_standard);
this.outer = var_$dialect;
setLineNumber(7); // compilenode import
// Import of "collections" as collections
if (typeof gracecode_collections == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module collections"));
var var_collections = do_import("collections", gracecode_collections);
var func0 = function(argcv) { // accessor method collections, line 7
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("collections", 0, numArgs - 0);
return var_collections;
}; // end of method collections
this.methods["collections"] = func0;
func0.methodName = "collections";
func0.paramCounts = [0];
func0.paramNames = [];
func0.definitionLine = 7;
func0.definitionModule = "gUnit";
func0.debug = "import";
func0.confidential = true;
setLineNumber(8); // compilenode import
// Import of "mirror" as mirror
if (typeof gracecode_mirror == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module mirror"));
var var_mirror = do_import("mirror", gracecode_mirror);
var func1 = function(argcv) { // accessor method mirror, line 8
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("mirror", 0, numArgs - 0);
return var_mirror;
}; // end of method mirror
this.methods["mirror"] = func1;
func1.methodName = "mirror";
func1.paramCounts = [0];
func1.paramNames = [];
func1.definitionLine = 8;
func1.definitionModule = "gUnit";
func1.debug = "import";
func1.confidential = true;
setLineNumber(9); // compilenode import
// Import of "sys" as sys
if (typeof gracecode_sys == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module sys"));
var var_sys = do_import("sys", gracecode_sys);
var func2 = function(argcv) { // accessor method sys, line 9
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("sys", 0, numArgs - 0);
return var_sys;
}; // end of method sys
this.methods["sys"] = func2;
func2.methodName = "sys";
func2.paramCounts = [0];
func2.paramNames = [];
func2.definitionLine = 9;
func2.definitionModule = "gUnit";
func2.debug = "import";
func2.confidential = true;
setLineNumber(10); // compilenode import
// Import of "regularExpression" as regularExpression
if (typeof gracecode_regularExpression == "undefined")
throw new GraceExceptionPacket(EnvironmentExceptionObject,
new GraceString("could not find module regularExpression"));
var var_regularExpression = do_import("regularExpression", gracecode_regularExpression);
var func3 = function(argcv) { // accessor method regularExpression, line 10
const numArgs = arguments.length - 1;
if (numArgs > 0) raiseTypeArgError("regularExpression", 0, numArgs - 0);
return var_regularExpression;
}; // end of method regularExpression
this.methods["regularExpression"] = func3;
func3.methodName = "regularExpression";
func3.paramCounts = [0];
func3.paramNames = [];
func3.definitionLine = 10;
func3.definitionModule = "gUnit";
func3.debug = "import";
func3.confidential = true;
this.closureKeys = this.closureKeys || [];
this.closureKeys.push("outer_gUnit_1");
this.outer_gUnit_1 = var_$dialect;
setLineNumber(12); // compilenode typedec
// Type decl Assertion
var func5 = function(argcv) { // method Assertion, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(12); // compilenode interfaceliteral
// interface literal
var iface6 = new GraceInterface("Assertion");
sig7 = () => {
setLineNumber(13); // compilenode member
var call8 = selfRequest(var_$dialect, "Boolean", [0]);
var call9 = selfRequest(var_$dialect, "String", [0]);
var call10 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)description(1)", ["bb", "str"], [], [call8, call9], call10);
}
sig11 = () => {
setLineNumber(14); // compilenode member
var call12 = selfRequest(var_$dialect, "Boolean", [0]);
var call13 = selfRequest(var_$dialect, "String", [0]);
var call14 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("deny(1)description(1)", ["bb", "str"], [], [call12, call13], call14);
}
sig15 = () => {
setLineNumber(15); // compilenode member
var call16 = selfRequest(var_$dialect, "Boolean", [0]);
var call17 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)", ["bb"], [], [call16], call17);
}
sig18 = () => {
setLineNumber(16); // compilenode member
var call19 = selfRequest(var_$dialect, "Boolean", [0]);
var call20 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("deny(1)", ["bb"], [], [call19], call20);
}
sig21 = () => {
setLineNumber(17); // compilenode member
var call22 = selfRequest(var_$dialect, "Object", [0]);
var call23 = selfRequest(var_$dialect, "Object", [0]);
var call24 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)shouldBe(1)", ["s1", "s2"], [], [call22, call23], call24);
}
sig25 = () => {
setLineNumber(18); // compilenode member
var call26 = selfRequest(var_$dialect, "Object", [0]);
var call27 = selfRequest(var_$dialect, "Object", [0]);
var call28 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)shouldntBe(1)", ["s1", "s2"], [], [call26, call27], call28);
}
sig29 = () => {
setLineNumber(19); // compilenode member
var call30 = selfRequest(var_$dialect, "Number", [0]);
var call31 = selfRequest(var_$dialect, "Number", [0]);
var call32 = selfRequest(var_$dialect, "Number", [0]);
var call33 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)shouldEqual(1)within(1)", ["n1", "n2", "epsilon"], [], [call30, call31, call32], call33);
}
sig34 = () => {
setLineNumber(20); // compilenode member
var call35 = selfRequest(var_$dialect, "Procedure0", [0]);
var call36 = selfRequest(var_$dialect, "ExceptionKind", [0]);
var call37 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)shouldRaise(1)", ["b", "desireed"], [], [call35, call36], call37);
}
sig38 = () => {
setLineNumber(21); // compilenode member
var call39 = selfRequest(var_$dialect, "Procedure0", [0]);
var call40 = selfRequest(var_$dialect, "ExceptionKind", [0]);
var call41 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)shouldntRaise(1)", ["b", "undesired"], [], [call39, call40], call41);
}
sig42 = () => {
setLineNumber(22); // compilenode member
var call43 = selfRequest(var_$dialect, "Object", [0]);
var call44 = selfRequest(var_$dialect, "Type", [0]);
var call45 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assert(1)hasType(1)", ["s", "t"], [], [call43, call44], call45);
}
sig46 = () => {
setLineNumber(23); // compilenode member
var call47 = selfRequest(var_$dialect, "Object", [0]);
var call48 = selfRequest(var_$dialect, "Type", [0]);
var call49 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("deny(1)hasType(1)", ["s", "t"], [], [call47, call48], call49);
}
sig50 = () => {
setLineNumber(24); // compilenode member
var call51 = selfRequest(var_$dialect, "Type", [0]);
var call52 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("assertType(1)describes(1)", ["T", "value"], [], [call51, type_Unknown], call52);
}
sig53 = () => {
setLineNumber(25); // compilenode member
var call54 = selfRequest(var_$dialect, "String", [0]);
var call55 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("failBecause(1)", ["Message"], [], [call54], call55);
}
iface6.typeMethods = {
"assert(1)description(1)": sig7
, "deny(1)description(1)": sig11
, "assert(1)": sig15
, "deny(1)": sig18
, "assert(1)shouldBe(1)": sig21
, "assert(1)shouldntBe(1)": sig25
, "assert(1)shouldEqual(1)within(1)": sig29
, "assert(1)shouldRaise(1)": sig34
, "assert(1)shouldntRaise(1)": sig38
, "assert(1)hasType(1)": sig42
, "deny(1)hasType(1)": sig46
, "assertType(1)describes(1)": sig50
, "failBecause(1)": sig53
};
return iface6;
}; // end of method Assertion
function memofunc5(argcv) {
if (! this.data["memo$Assertion"]) // parameterless memo function
this.data["memo$Assertion"] = func5.call(this, argcv);
return this.data["memo$Assertion"];
};
this.methods["Assertion"] = memofunc5;
memofunc5.methodName = "Assertion";
memofunc5.paramCounts = [0];
memofunc5.paramNames = [];
memofunc5.definitionLine = 1;
memofunc5.definitionModule = "gUnit";
func5.methodName = "Assertion";
func5.paramCounts = [0];
func5.paramNames = [];
func5.definitionLine = 1;
func5.definitionModule = "gUnit";
setLineNumber(28); // compilenode typedec
// Type decl TestCase
var func57 = function(argcv) { // method TestCase, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(1); // compilenode string
var string59 = new GraceString("TestCase");
// call case 4: other requests
setLineNumber(28); // compilenode interfaceliteral
// interface literal
var iface61 = new GraceInterface("\u2039anon\u203a");
sig62 = () => {
setLineNumber(29); // compilenode member
var call63 = selfRequest(var_$module, "TestResult", [0]);
var call64 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("run(1)", ["__1"], [], [call63], call64);
}
sig65 = () => {
setLineNumber(30); // compilenode member
var call66 = selfRequest(var_$module, "TestResult", [0]);
var call67 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("debug(1)", ["__2"], [], [call66], call67);
}
sig68 = () => {
setLineNumber(31); // compilenode member
var call69 = selfRequest(var_$dialect, "Number", [0]);
return new GraceSignature("size", [], [], [], call69);
}
sig70 = () => {
setLineNumber(32); // compilenode member
var call71 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("name", [], [], [], call71);
}
iface61.typeMethods = {
"run(1)": sig62
, "debug(1)": sig65
, "size": sig68
, "name": sig70
};
// call case 4: other requests
setLineNumber(28); // compilenode member
var call72 = selfRequest(var_$module, "Assertion", [0]);
var term60 = request(call72, "&(1)", [1], iface61);
var call58 = selfRequest(term60, "setTypeName(1)", [1], string59);
return call58;
}; // end of method TestCase
function memofunc57(argcv) {
if (! this.data["memo$TestCase"]) // parameterless memo function
this.data["memo$TestCase"] = func57.call(this, argcv);
return this.data["memo$TestCase"];
};
this.methods["TestCase"] = memofunc57;
memofunc57.methodName = "TestCase";
memofunc57.paramCounts = [0];
memofunc57.paramNames = [];
memofunc57.definitionLine = 1;
memofunc57.definitionModule = "gUnit";
func57.methodName = "TestCase";
func57.paramCounts = [0];
func57.paramNames = [];
func57.definitionLine = 1;
func57.definitionModule = "gUnit";
setLineNumber(35); // compilenode typedec
// Type decl TestRecord
var func74 = function(argcv) { // method TestRecord, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(35); // compilenode interfaceliteral
// interface literal
var iface75 = new GraceInterface("TestRecord");
sig76 = () => {
setLineNumber(36); // compilenode member
var call77 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("name", [], [], [], call77);
}
sig78 = () => {
setLineNumber(37); // compilenode member
var call79 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("message", [], [], [], call79);
}
iface75.typeMethods = {
"name": sig76
, "message": sig78
};
return iface75;
}; // end of method TestRecord
function memofunc74(argcv) {
if (! this.data["memo$TestRecord"]) // parameterless memo function
this.data["memo$TestRecord"] = func74.call(this, argcv);
return this.data["memo$TestRecord"];
};
this.methods["TestRecord"] = memofunc74;
memofunc74.methodName = "TestRecord";
memofunc74.paramCounts = [0];
memofunc74.paramNames = [];
memofunc74.definitionLine = 1;
memofunc74.definitionModule = "gUnit";
func74.methodName = "TestRecord";
func74.paramCounts = [0];
func74.paramNames = [];
func74.definitionLine = 1;
func74.definitionModule = "gUnit";
setLineNumber(40); // compilenode typedec
// Type decl TestResult
var func81 = function(argcv) { // method TestResult, line 1
var returnTarget = invocationCount;
invocationCount++;
setLineNumber(40); // compilenode interfaceliteral
// interface literal
var iface82 = new GraceInterface("TestResult");
sig83 = () => {
setLineNumber(41); // compilenode member
var call84 = selfRequest(var_$dialect, "String", [0]);
var call85 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("testStarted(1)", ["name"], [], [call84], call85);
}
sig86 = () => {
setLineNumber(42); // compilenode member
var call87 = selfRequest(var_$dialect, "String", [0]);
var call88 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("testFailed(1)", ["name"], [], [call87], call88);
}
sig89 = () => {
setLineNumber(43); // compilenode member
var call90 = selfRequest(var_$dialect, "String", [0]);
var call91 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("testErrored(1)", ["name"], [], [call90], call91);
}
sig92 = () => {
setLineNumber(44); // compilenode member
var call93 = selfRequest(var_$dialect, "String", [0]);
var call94 = selfRequest(var_$dialect, "Done", [0]);
return new GraceSignature("testFinished(1)", ["name"], [], [call93], call94);
}
sig95 = () => {
setLineNumber(45); // compilenode member
var call96 = selfRequest(var_$dialect, "List", [0]);
return new GraceSignature("erroredTestNames", [], [], [], call96);
}
sig97 = () => {
setLineNumber(46); // compilenode member
var call98 = selfRequest(var_$dialect, "List", [0]);
return new GraceSignature("failedTestNames", [], [], [], call98);
}
sig99 = () => {
setLineNumber(47); // compilenode member
var call100 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("summary", [], [], [], call100);
}
sig101 = () => {
setLineNumber(48); // compilenode member
var call102 = selfRequest(var_$dialect, "String", [0]);
return new GraceSignature("detailedSummary", [], [], [], call102);
}
sig103 = () => {
setLineNumber(49); // compilenode member