Lcl · Core · Packages · Libraries


Test

Test Framework for LCL

A simple but capable test framework written in pure LCL.

Usage:

  load lib/Test.lcl

  Test::suite "My Feature" {
      Test::before {
          ;; Setup code runs before each test
      }

      Test::case "should do something" {
          let result [my_func 1 2]
          Test::eq $result 3
      }

      Test::case "should fail on bad input" {
          Test::raises {
              my_func "bad" "input"
          }
      }
  }

  Test::run  ;;; Run all suites and print results

namespace Test

proc Test::suite name body

Register a test suite

proc Test::case name body

Register a test case within the current suite

proc Test::before body

proc Test::after body

Set up code to run after each test in the current suite

proc Test::eq actual expected (msg {})

Assertion: two values are equal (with optional message)

proc Test::neq actual unexpected (msg {})

Assertion: two values are not equal (with optional message)

proc Test::assert cond (msg {})

Assertion: condition is true (with optional message)

proc Test::true cond (msg {})

Alias for assert

proc Test::false cond (msg {})

Assertion: condition is false (with optional message)

proc Test::empty val

Assertion: value is empty (empty string or empty list)

proc Test::not_empty val

proc Test::opaque val

Assertion: value is opaque

proc Test::not_opaque val

Assertion: value is not opaque

proc Test::raises body

Assertion: code raises an error

proc Test::raises_with body expected_text

Assertion: code raises an error containing specific text

proc Test::gt actual expected

Assertion: value is greater than expected

proc Test::lt actual expected

Assertion: value is less than expected

proc Test::gte actual expected

Assertion: value is greater than or equal to expected

proc Test::lte actual expected

Assertion: value is less than or equal to expected

proc Test::contains lst elem

Assertion: list contains element

proc Test::str_contains haystack needle

Assertion: string contains substring

proc Test::len_eq lst expected

Assertion: list has expected length

proc Test::skip reason

Skip the current test with a reason

proc Test::run

Run all registered test suites

proc Test::reset

Clear all registered suites (useful for testing the framework itself)