zeolite-lang-0.24.0.0: lib/testing/test/checker.0rt
/* -----------------------------------------------------------------------------
Copyright 2023 Kevin P. Barry
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----------------------------------------------------------------------------- */
// Author: Kevin P. Barry [ta0kira@gmail.com]
testcase "TestChecker.isFailing fails if not started" {
failure
require "not started"
}
unittest test {
\ TestChecker.isFailing()
}
testcase "TestChecker.finish fails if not started" {
failure
require "not started"
}
unittest test {
\ TestChecker.finish()
}
testcase "TestChecker.checkNow fails if not started" {
failure
require "not started"
}
unittest test {
\ TestChecker.checkNow()
}
testcase "TestChecker.start fails if already started" {
failure
require "already started"
}
unittest test {
\ TestChecker.start()
\ TestChecker.start()
}
testcase "TestChecker.newReport fails if not started" {
failure
require "not started"
}
unittest test {
\ TestChecker.newReport(title: "title", context: empty)
}
testcase "TestChecker explicit start and finish" {
success
}
unittest test {
\ TestChecker.start()
\ TestChecker.newReport(title: "title", context: empty)
\ TestChecker.newReport(title: "title", context: empty).newSection(title: "subtitle")
\ Testing.checkEquals(TestChecker.isFailing(), false)
\ TestChecker.checkNow()
\ TestChecker.finish()
}
testcase "TestChecker succeeds by default" {
success TestChecker
}
unittest test { }
testcase "TestChecker fails when error added to report" {
failure TestChecker
require "context1"
require "context2"
require "title1"
require "message1"
require "title2"
require "message2"
exclude "testError"
}
unittest testError {
ValueList<String> context <- ValueList<String>.new()
.append("context1")
.append("context2")
\ TestChecker.newReport(title: "title1", context: context.defaultOrder()).addError(message: "message1")
\ TestChecker.newReport(title: "title2", context: empty).addError(message: "message2")
}
testcase "TestChecker fails when error added to child" {
failure TestChecker
require "title"
require "child"
require "message"
exclude "testError"
}
unittest testError {
TestReport report <- TestChecker.newReport(title: "title", context: empty)
TestReport child <- report.newSection(title: "child")
\ child.addError(message: "message")
}
testcase "TestChecker ignores discarded errors" {
success TestChecker
}
unittest topLevel {
TestReport report <- TestChecker.newReport(title: "title", context: empty)
\ Testing.checkEquals(report.hasError(), false)
\ report.addError(message: "message")
\ Testing.checkEquals(report.hasError(), true)
\ report.discardReport()
\ Testing.checkEquals(report.hasError(), false)
}
unittest recursive {
TestReport report <- TestChecker.newReport(title: "title", context: empty)
TestReport child <- report.newSection(title: "child")
\ Testing.checkEquals(report.hasError(), false)
\ Testing.checkEquals(child.hasError(), false)
\ child.addError(message: "message")
\ Testing.checkEquals(report.hasError(), true)
\ Testing.checkEquals(child.hasError(), true)
\ report.discardReport()
\ Testing.checkEquals(report.hasError(), false)
\ Testing.checkEquals(child.hasError(), true)
}