Replies: 2 comments 4 replies
-
|
Would code located in Would the |
Beta Was this translation helpful? Give feedback.
-
|
This looks awesome! Im curious, is Go historically lacks assertions, so you end up with just having The assert failure diagnostic looks good (i like the But having said that, one thing to note is that the compiler wont be able to force the fact that the assert is positional. Meaning Without knowing the assert implementation, these are just cases that came to mind The user reversed the order
would yield:
Also, it can lead to confusion in computed values:
would yield:
Also this can be confusing:
would yield:
So i propose changing the terminology to something more general like As an example: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tip
This is the first iteration I have in mind for a test runner, in the form of user-facing documentation. Scoped as foundations: writing and running test files and functions, assertions, and the test context. Later iterations might tackle test coverage, test labels, snapshot testing, etc. as needed. Open for feedback!
Testing
Lisette's test runner invokes
#[test]functions in test files via thelis testcommand.On success:
On failure:
Test types
All test files are suffixed with
.test.lisInternal tests sit in the same module as the file under test, so they can access private symbols in the module.
External tests sit in a
testsdirectory at project root, so they can only exercise modules through public APIs. Integration tests typically live here.src/ ├── main.lis └── math/ ├── math.lis # file under test └── math.test.lis # internal tests tests/ └── arithmetic.test.lis # external testslis testruns all tests, internal and external.lis buildexcludes all test files from the binary.lis checkincludes all files, production and tests.Test functions
In a test file, a function marked
#[test]will be found and invoked by the test runner. A test function usually takes no parameters and omits the return type annotation.Optionally, a test can carry a title and description:
In the report, the title replaces the function name, and the description follows beneath:
The
--filterflag inlis testmatches strings in both function names and function titles.Test assertions
In a test function,
assertchecks if a boolean expression istrueor fails the test.Diagnostic on failure:
For types that cannot be natively compared, use the
#[equality]attribute and theequalsmethod:Diagnostic on failure:
Use
let assertto assert by pattern matching:To assert that an operation panics,
recoverfrom it and match theErr:Use
Resultto assert via the?operator:Test context
Optionally, Go's
testing.Tis available as atparameter in every test function.tis of typeTestContext(from Lisette's prelude) and works like Go'stesting.T.tis also available as a lambda parameter. In the following example, the test function'stcreates subtests, and each lambda'stmakes the subtest run concurrently.Beta Was this translation helpful? Give feedback.
All reactions