-
Notifications
You must be signed in to change notification settings - Fork 22
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
Proposal: Test framework #78
Comments
Looks very useful and simple, but I have some questions/suggestions. Since (deftest) is the same as (defn) which is the same as (def) why can't we add (deftest) macro in the core and thus avoid adding :refer to the (ns)? As an alternative, why not just use (defn) and tell people to add metadata @{:test true} for writing tests? Could we add a command for |
I see the
Sure! |
I see. Makes sense now. Thank you for explaining the use case a little bit more. |
I really like the idea of using I think it would be pretty useful to print the expected value on test failure. It would help developers to understand what is going on without having to manually print the test's parameters. Quasi-quotation could help here. Here is an example of what I'm thinking about:
And the output of this would be Then I have a question about |
@paullaffitte Thanks for your input. I will add more details in the report section, on how failure and error message should look like (with examples). Regarding |
I updated the Report section. What do you think? |
Current Status:
What is left:
|
This is now completed! All test of the core library can now be executed by |
Great work! Really loving how the language is turning out. Sorry I can't contribute more to the code. I have my hands full atm... but testing and experimenting is what I love to do in the morning, so I will give it a go and report back. |
Motivation
Phel should provide a default testing framework to test Phel code.
Concept
The code for the Phel's testing library is bundled in the namespace
phel.test
.Assertions
The core of the library is the
is
macro to define assertions. For exampleThe
is
macro supports following forms:(predicate expected actual)
like(= 4 (+ 2 2))
(predicate value)
like(true? (or true false))
(not (predicate expected actual))
like(not (= 4 (+ 2 3)))
(not (predicate value))
like(not (true? false))
(thrown? exception-symbol body)
like(thrown? Exception (/ 1 0))
(thrown-with-msg? exception-symbol exception-msg body)
like(thrown? Exception "Division by zero" (/ 1 0))
(output-string expected-string body)
like(output-string "test" (php/echo "test"))
The
is
macro supports an additional second string argument to document the test caseAn assertion can lead to the three states:
Defining tests
To define a test the
deftest
macro can be usedInternally
deftest
is adefn
with zero arguments. As metadata thedefn
has a:test
attribute. Sodeftest
is equivalent toRunning tests
The function
run-tests
can be used to executes tests in one or more namespacesReporting
When executing the tests a reporter should print the current status of the test suite. While running it should print a
.
for a successful test aF
for a failed test and aE
for an error test. Afterwards it prints a list with details about all failures and errors. At the end a summary is printed (tests executed, tests passed, tests failed, tests with error).Failure examples
Error examples
Additional information
To make the API look nice, the namespace macro needs to be extended to support direct imports. Currently, it works the following way
But it would be nice if we can omit the
test/
prefix. Therefore, I would propose following additionThe text was updated successfully, but these errors were encountered: