Skip to content
Francis Hagan edited this page Oct 30, 2026 · 4 revisions

Tests

Table of Contents

CupidScript tests are plain .cs scripts under tests/ plus a native C test binary.

Running Tests

make test

The runner executes each tests/*.cs file in lexical order and prints PASS/FAIL. It also runs the C API test binary bin/c_api_tests.

Writing Script Tests

  1. Create a new file in tests/ (e.g. tests/my_feature.cs).
  2. Use assert(condition, "message") for checks.
  3. Optionally print a success marker at the end.

Example:

// tests/my_feature.cs
let x = 1 + 2;
assert(x == 3, "basic math");
print("my_feature ok");

Negative Tests (Expected Failures)

If a test should fail, add this header at the top:

// EXPECT_FAIL

Example:

// tests/negative_example.cs
// EXPECT_FAIL
assert(false, "should fail");

Helper Files

Files starting with _ are ignored by the test runner. Use these for shared fixtures or helper modules.

C API Tests

tests/c_api_tests.c is compiled into bin/c_api_tests and run by make test. It exercises the embedding API directly (lists, maps, error handling, etc.).

Sanitizer builds

make -j2 test OBJDIR=obj-asan BINDIR=bin-asan CFLAGS='-std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer' LDFLAGS='-fsanitize=address,undefined'

make test runs the corpus and C API binary, an HTTP parser/transport binary, and Python loopback HTTP/TLS tests. Install Python 3 and the OpenSSL command-line tool for the TLS test certificate. No public network service is required. Both valid and malformed responses are tested, including binary bodies, peer-name verification, and a closed peer during a write.

To check both TLS modes in the same output directories:

make -j2 test CS_NO_TLS=1
make -j2 test

The build detects compiler/feature/flag changes and rebuilds affected objects. The runner checks sanitizer diagnostics and signals even for EXPECT_FAIL scripts. Coverage includes tuple host ownership, tuple comprehension bindings, container cycles, pending async tasks, nested interpolation, binary string patterns, and cleanup error/control-flow precedence.

Clone this wiki locally