chaos
chaos copied to clipboard
[RFC] Unit Testing
Add assert
and tests
keyword to the grammar. Add -t/--test
CLI option. Consider the above Chaos program file:
dev.kaos:
num def sum(num a, num b)
num c = a + b
return c
end
print "hello world"
tests:
assert sum(3, 5) == 8
When you run it with chaos dev.kaos
it prints hello world
. But when you run it with chaos -t dev.kaos
it does not print hello world
but instead executes the code below the tests:
tag. If the assertion fails exits with a non-zero code.
Optionally; warn user if there are no assertions on sum
function when they run chaos dev.kaos
like:
$ chaos dev.kaos
Chaos Warning: `sum` function is untested!
hello world
Add a CLI option to suppress these warnings.
I really like this idea:
$ chaos --test/-t <file>
I say let's get this in. It reminds me of how Zig programmers code (tests in the same file, and can be invoked via the CLI). I really like this.
$ chaos dev.kaos
Chaos Warning: `sum` function is not tested!
hello world
We can also change the wording to function is unused or untested!
. I feel like this is better, because Chaos is built to encourage testing, but not everyone will want to write tests, especially for small programs. Adding unused
seems a bit more semantically appropriate for certain cases.
@naltun I've updated the description to <FUNCTION_NAME> function is untested!
format. Do you suggest to add another keyword like unused
to ignore untested function warnings? Like a function decorator:
@unused
num def sum(num a, num b)
num c = a + b
return c
end
such that the Chaos Warning: sum function is not tested!
message will be suppressed?