Skip to content

Qang Test

The qang test command discovers and runs test functions in QangLang projects.

Terminal window
qang test <path>
  • <path> - Path to a test file or directory containing tests (required)
    • If a directory is provided, all .ql files will be discovered and run recursively

QangLang tests are regular .ql files that contain:

  1. Test Description (optional): A top-level variable named test_description
  2. Test Functions: Functions with names starting with test_
var test_description = "Testing math expressions and their precedence.";
fn test_addition() {
assert_eq(1 + 1, 2, "Expected 1 + 1 to equal 2.");
assert_eq(1 + -1, 0, "Expected 1 + -1 to equal 0.");
}
fn test_subtraction() {
assert_eq(5 - 3, 2, "Expected 5 - 3 to equal 2.");
}

QangLang provides built-in assertion functions for testing:

  • assert(condition, message) - Assert that a condition is truthy
  • assert_eq(actual, expected, message) - Assert that two values are equal
  • assert_not_nil(value) - Assert that a value is not nil
  • assert_throws(fn) - Assert that a function throws an error when called

The test runner automatically:

  • Finds all functions whose names start with test_
  • Executes each test function independently
  • Reports results for each test
Terminal window
qang test tests/test_math.ql
Terminal window
qang test tests/

The test runner provides:

  • Individual test results (pass/fail) for each test function
  • Error messages for failed assertions
  • Summary statistics (total tests, passed, failed)
  • The test_description message if defined
  • 0 - All tests passed successfully
  • 1 - One or more tests failed or encountered errors