add unit tests (#60)

also, flatten the workspace into a single crate. I forget what the original reason for the workspace
was -- I think it was added because `cargo t -p testsuite` is nicer than running
`cargo t --test $filename` N times. However, a single crate removes the need to repeat the list of
dependencies in `testsuite/Cargo.toml`

also, document the two sets of tests included with the template and how to run them in the README
file
This commit is contained in:
Jorge Aparicio
2022-01-03 11:29:08 +01:00
committed by GitHub
parent d82fad8c96
commit 47277bbf9d
7 changed files with 72 additions and 55 deletions
+31 -2
View File
@@ -139,7 +139,7 @@ $ echo $?
```
If you're running out of memory (`flip-link` bails with an overflow error), you can decrease the size of the device memory buffer by setting the `DEFMT_RTT_BUFFER_SIZE` environment variable. The default value is 1024 bytes, and powers of two should be used for optimal performance:
``` console
$ DEFMT_RTT_BUFFER_SIZE=64 cargo rb hello
```
@@ -154,12 +154,41 @@ If you are using [rust-analyzer] with VS Code for IDE-like features you can add
"Cargo.toml",
"firmware/Cargo.toml",
]
}
}
```
[RA docs]: https://rust-analyzer.github.io/manual.html#configuration
[rust-analyzer]: https://rust-analyzer.github.io/
## Running tests
The template comes configured for running unit tests and integration tests on the target.
Unit tests reside in the library crate and can test private API; the initial set of unit tests are in `src/lib.rs`.
`cargo test --lib` will run those unit tests.
``` console
$ cargo test --lib
(1/1) running `it_works`...
└─ app::unit_tests::__defmt_test_entry @ src/lib.rs:33
all tests passed!
└─ app::unit_tests::__defmt_test_entry @ src/lib.rs:28
```
Integration tests reside in the `tests` directory; the initial set of integration tests are in `tests/integration.rs`.
`cargo test --test integration` will run those integration tests.
Note that the argument of the `--test` flag must match the name of the test file in the `tests` directory.
``` console
$ cargo test --test integration
(1/1) running `it_works`...
└─ integration::tests::__defmt_test_entry @ tests/integration.rs:13
all tests passed!
└─ integration::tests::__defmt_test_entry @ tests/integration.rs:8
```
Note that to add a new test file to the `tests` directory you also need to add a new `[[test]]` section to `Cargo.toml`.
## Trying out the git version of defmt
This template is configured to use the latest crates.io release (the "stable" release) of the `defmt` framework.