Skip to content

Commit b2d234a

Browse files
committed
Add an example to the test intro
1 parent 5d623f8 commit b2d234a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/attributes/testing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ r[attributes.testing.test.enabled]
1515
These functions are only compiled when in test mode.
1616
The *`test` [attribute][attributes]* marks a function to be executed as a test.
1717

18+
> [!EXAMPLE]
19+
> ```rust
20+
> # pub fn add(left: u64, right: u64) -> u64 { left + right }
21+
>
22+
> #[test]
23+
> fn it_works() {
24+
> let result = add(2, 2);
25+
> assert_eq!(result, 4);
26+
> }
27+
> ```
28+
1829
r[attributes.testing.test.allowed-positions]
1930
Test functions must be free, monomorphic functions that take no arguments, and the return type must implement the [`Termination`] trait, for example:
2031

0 commit comments

Comments
 (0)