forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sway Reference: Section 9 Annotations: Testing (FuelLabs#4622)
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
docs/reference/src/documentation/language/annotations/attributes/test.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# Test | ||
|
||
Sway provides the `#[test]` attribute which enables unit tests to be written in Sway. | ||
|
||
## Success case | ||
|
||
The `#[test]` attribute indicates that a test has passed if it did not revert. | ||
|
||
```sway | ||
{{#include ../../../../code/language/annotations/src/main.sw:success_test}} | ||
``` | ||
|
||
## Revert Case | ||
|
||
To test a case where code should revert we can use the `#[test(should_revert)]` annotation. If the test reverts then it will be reported as a passing test. | ||
|
||
```sway | ||
{{#include ../../../../code/language/annotations/src/main.sw:revert_test}} | ||
``` | ||
|
||
We may specify a code to specifically test against. | ||
|
||
```sway | ||
{{#include ../../../../code/language/annotations/src/main.sw:revert_code_test}} | ||
``` |