Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Unit Testing #93

Open
mertyildiran opened this issue Dec 29, 2020 · 2 comments
Open

[RFC] Unit Testing #93

mertyildiran opened this issue Dec 29, 2020 · 2 comments
Assignees
Labels
feature request New feature or request
Projects

Comments

@mertyildiran
Copy link
Member

mertyildiran commented Dec 29, 2020

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.

@mertyildiran mertyildiran added the feature request New feature or request label Dec 29, 2020
@mertyildiran mertyildiran self-assigned this Dec 29, 2020
@mertyildiran mertyildiran added this to To do in Chaos via automation Dec 29, 2020
@naltun
Copy link
Member

naltun commented Dec 29, 2020

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.

@mertyildiran
Copy link
Member Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
2 participants