laserpants/coal-micro-test
1
0
Fork
You've already forked coal-micro-test
0
Minimal test framework for the Coal programming language
2026年07月15日 13:35:58 +02:00
src Add assert_with_remark 2026年05月06日 23:08:52 +03:00
test Use Spec module as entry point 2026年07月15日 13:35:58 +02:00
.gitignore Add files 2026年01月18日 15:28:50 +03:00
coal.json Use Spec module as entry point 2026年07月15日 13:35:58 +02:00
LICENSE Add files 2026年01月18日 15:28:50 +03:00
README.md Update README.md 2026年05月06日 07:50:12 +02:00

coal-micro-test

A lightweight, minimal testing framework for the Coal programming language.

Overview

coal-micro-test provides a simple and elegant way to write and run tests in Coal. It offers a functional approach to testing with assertion functions, test composition, and pretty-printed test results.

Features

  • Simple assertions: assert and assert_eq for common test cases
  • 🔧 Composable tests: Build complex test suites from simple test cases
  • 📊 Clear output: Color-coded test results with pass/fail summaries
  • 🎯 Functional design: Leverages Coal's functional programming features
  • 🪶 Lightweight: Minimal dependencies and straightforward API

Installation

Add coal-micro-test to your coal.json dependencies:

{
 "name": "your-project",
 "version": "0.1.0",
 "modules": [
 "YourModule"
 ],
 "dependencies": {
 "coal-micro-test": {
 "version": "*",
 "git": "ssh://git@codeberg.org/laserpants/coal-micro-test.git"
 }
 }
}

Quick start

Here's a simple example to get you started:

module Main {
 import Test(type Test, assert, check, suite, run)
 import IO(return)
 let
 test : Test =
 suite([
 check(1 + 1 == 2),
 check(2 * 3 == 6),
 check("hello" <> " world" == "hello world")
 ])
 fun main() = do {
 run(test);
 return();
 }
}

API reference

Types

TestResult

Represents the result of a single assertion:

  • Pass: Test assertion succeeded
  • Fail(string): Test assertion failed with an error message

Test

Type alias for List<TestResult>. Represents a collection of test results.

Summary

A record type containing test execution summary:

{ passed : int32
, failed : List<string>
}

ExitCode

  • Success: All tests passed
  • Failure: One or more tests failed

Assertion functions

assert(condition : bool) : TestResult

Creates a test result based on a boolean condition.

assert(1 + 1 == 2) // Pass
assert(false) // Fail("Assertion failed")

assert_eq(x : a, y : a) : TestResult

Asserts that two values are equal.

assert_eq(1 + 1, 2)
assert_eq([1, 2, 3], [1, 2, 3])

Test composition

check(b : bool) : Test

Converts a boolean assertion into a Test (List of TestResults).

check(1 + 1 == 2)

suite(tests : List<Test>) : Test

Combines multiple tests into a single test suite.

let my_suite = suite([
 check(condition1),
 check(condition2),
 my_other_test
])

Test execution

run(test : Test) : IO<ExitCode>

Executes a test suite and prints results to the console. Returns an exit code indicating success or failure.

fun main() = do {
 run(my_test_suite);
 return();
}

Example output

When you run your tests, you'll see output like this:

✓ All 5 tests passed

Or if there are failures:

✗ Assertion failed
✗ Assertion failed
✗ 2 test(s) failed, 3 passed

Writing tests

Basic test

module MyTests {
 import Test(check, suite, run)
 
 let simple_tests = suite([
 check(1 > 0),
 check([] == []),
 check("test" != "")
 ])
}

Organized test suite

module MyTests {
 import Test(type Test, assert, check, suite, run)
 import List(length, head, tail)
 
 fun test_list_operations() : Test =
 suite([
 check(length([1, 2, 3]) == 3),
 check(length([]) == 0)
 ])
 
 fun test_arithmetic() : Test =
 suite([
 check(1 + 1 == 2),
 check(5 - 3 == 2),
 check(2 * 3 == 6)
 ])
 
 let all_tests : Test =
 suite([
 test_list_operations(),
 test_arithmetic()
 ])
 
 fun main() = do {
 run(all_tests);
 return();
 }
}

Custom test functions

fun test_custom_logic() : Test =
 suite([
 check(my_function(5) > 0),
 check(my_function(0) == 0)
 ])

Project structure

coal-micro-test/
├── coal.json # Project configuration
├── coal.lock.json # Dependency lock file
├── LICENSE # License information
├── README.md # This file
└── src/
 ├── Main.coal # Example usage
 └── MicroTest.coal # Testing framework implementation

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

See LICENSE for details.