Qang Test
The qang test command discovers and runs test functions in QangLang projects.
qang test <path>Arguments
Section titled “Arguments”<path>- Path to a test file or directory containing tests (required)- If a directory is provided, all
.qlfiles will be discovered and run recursively
- If a directory is provided, all
Writing Tests
Section titled “Writing Tests”QangLang tests are regular .ql files that contain:
- Test Description (optional): A top-level variable named
test_description - Test Functions: Functions with names starting with
test_
Example Test File
Section titled “Example Test File”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.");}Assertion Functions
Section titled “Assertion Functions”QangLang provides built-in assertion functions for testing:
assert(condition, message)- Assert that a condition is truthyassert_eq(actual, expected, message)- Assert that two values are equalassert_not_nil(value)- Assert that a value is not nilassert_throws(fn)- Assert that a function throws an error when called
Test Discovery
Section titled “Test Discovery”The test runner automatically:
- Finds all functions whose names start with
test_ - Executes each test function independently
- Reports results for each test
Examples
Section titled “Examples”Run a Single Test File
Section titled “Run a Single Test File”qang test tests/test_math.qlRun All Tests in a Directory
Section titled “Run All Tests in a Directory”qang test tests/Test Output
Section titled “Test Output”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_descriptionmessage if defined
Exit Codes
Section titled “Exit Codes”0- All tests passed successfully1- One or more tests failed or encountered errors