zeolite-lang-0.16.0.0: tests/tracing.0rt
/* -----------------------------------------------------------------------------
Copyright 2020-2021 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 "NoTrace skips tracing" {
crash
require "message"
require "Test\.error"
exclude "Test\.noTrace"
}
unittest test {
\ Test.noTrace()
}
concrete Test {
@type noTrace () -> ()
}
define Test {
noTrace () { $NoTrace$
\ error()
}
@type error () -> ()
error () {
fail("message")
}
}
testcase "NoTrace works in cleanup" {
crash
require "message"
require "Test\.error"
exclude "Test\.noTrace"
}
unittest test {
\ Test.noTrace()
}
concrete Test {
@type noTrace () -> ()
}
define Test {
noTrace () { $NoTrace$
\ error()
}
@type error () -> ()
error () {
cleanup {
fail("message")
} in {}
}
}
testcase "TraceCreation captures trace" {
crash
require "message"
require "Type.+created at"
}
unittest test {
Type value <- Type.create()
\ value.call()
}
concrete Type {
@type create () -> (Type)
@value call () -> ()
}
define Type {
create () {
return Type{ }
}
call () { $TraceCreation$
fail("message")
}
}
testcase "TraceCreation ignored in @type" {
compiles
require compiler "tracing ignored"
}
concrete Test {}
define Test {
@type run () -> ()
run () { $TraceCreation$ }
}
testcase "TraceCreation still works with NoTrace" {
crash
require "message"
require "Type.+created at"
exclude "Type\.call"
}
unittest test {
Type value <- Type.create()
\ value.call()
}
concrete Type {
@type create () -> (Type)
@value call () -> ()
}
define Type {
create () {
return Type{ }
}
call () { $NoTrace$ $TraceCreation$
fail("message")
}
}
testcase "TraceCreation only uses the latest" {
crash
require "message"
require "Type1.+created at"
exclude "Type2.+created at"
}
unittest test {
Type2 value <- Type2.create()
\ value.call()
}
concrete Type1 {
@type create () -> (Type1)
@value call () -> ()
}
define Type1 {
create () {
return Type1{ }
}
call () { $TraceCreation$
fail("message")
}
}
concrete Type2 {
@type create () -> (Type2)
@value call () -> ()
}
define Type2 {
@value Type1 value
create () {
return Type2{ Type1.create() }
}
call () { $TraceCreation$
\ value.call()
}
}
testcase "correct function name used for non-merged function" {
crash
require "message"
require "Type\.call"
exclude "Base"
}
unittest test {
\ Type.call()
}
@type interface Base {
call () -> ()
}
concrete Type {
defines Base
}
define Type {
call () {
fail("message")
}
}