packages feed

zeolite-lang-0.6.0.0: tests/tracing.0rt

/* -----------------------------------------------------------------------------
Copyright 2020 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 Test$run()
  require "message"
  require "Test\.run"
  require "Test\.error"
  exclude "Test\.noTrace"
}

define Test {
  run () {
    \ noTrace()
  }

  @type noTrace () -> ()
  noTrace () { $NoTrace$
    \ error()
  }

  @type error () -> ()
  error () {
    fail("message")
  }
}

concrete Test {
  @type run () -> ()
}


testcase "TraceCreation captures trace" {
  crash Test$run()
  require "message"
  require "Type.+created at"
}

concrete Type {
  @type create () -> (Type)
  @value call () -> ()
}

define Type {
  create () {
    return Type{ }
  }

  call ()  { $TraceCreation$
    fail("message")
  }
}

define Test {
  run () {
    Type value <- Type$create()
    \ value.call()
  }
}

concrete Test {
  @type run () -> ()
}


testcase "TraceCreation ignored in @type" {
  success Test$run()
  require compiler "tracing ignored"
}

define Test {
  run () { $TraceCreation$ }
}

concrete Test {
  @type run () -> ()
}


testcase "TraceCreation still works with NoTrace" {
  crash Test$run()
  require "message"
  require "Type.+created at"
  exclude "Type\.call"
}

concrete Type {
  @type create () -> (Type)
  @value call () -> ()
}

define Type {
  create () {
    return Type{ }
  }

  call ()  { $NoTrace$ $TraceCreation$
    fail("message")
  }
}

define Test {
  run () {
    Type value <- Type$create()
    \ value.call()
  }
}

concrete Test {
  @type run () -> ()
}


testcase "TraceCreation only uses the latest" {
  crash Test$run()
  require "message"
  require "Type1.+created at"
  exclude "Type2.+created at"
}

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()
  }
}

define Test {
  run () {
    Type2 value <- Type2$create()
    \ value.call()
  }
}

concrete Test {
  @type run () -> ()
}