Skip to content

Commit 9615367

Browse files
committed
chore(stackable-versioned): Update testing README
1 parent c7a1fed commit 9615367

File tree

1 file changed

+42
-26
lines changed
  • crates/stackable-versioned-macros/tests

1 file changed

+42
-26
lines changed

crates/stackable-versioned-macros/tests/README.md

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
# Testing the `#[versioned]` macro
22

3+
This folder contains both snapshot and compile (trybuild) tests. Both types of tests use the same
4+
set of input files to both ensure the macro generates the expected code and either compiles or
5+
produces the expected compile error.
6+
7+
Tests are currently separated into two folders: `default` and `k8s`. The default test cases don't
8+
require any additional features to be activated. The Kubernetes specific tests require the `k8s`
9+
feature to be enabled. These tests can be run with `cargo test --all-features`.
10+
311
## Snapshot Testing
412

513
> [!NOTE]
614
> Please have `rust-src` installed, e.g. using `rustup component add rust-src`.
715
>
8-
> Also see the compile-fail tests, described [here](../tests/README.md).
16+
> Also see the compile-fail tests, described [here](#compile-fail-testing).
917
10-
This folder contains fixtures for snapshot testing the `#[versioned()]` macro. Snapshot testing is
11-
done using the [insta] crate. It provides a [CLI tool][insta-cli] called `cargo-insta` and a
12-
[VS Code extension][insta-ext].
18+
Snapshot testing is done using the [insta] crate. It provides a [CLI tool][insta-cli] calle
19+
`cargo-insta` and a [VS Code extension][insta-ext].
1320

14-
Test inputs and snapshots of the expected output are located in the `fixtures` folder. There are two
15-
inputs to the `#[versioned()]` macro because it is an attribute macro:
21+
Test inputs and snapshots of the expected output are located in the `inputs` and `snapshots` folder
22+
respectively. Each Rust attribute macro expects two inputs as a token stream:
1623

1724
> The first TokenStream is the delimited token tree following the attribute’s name, not including
1825
> the outer delimiters. If the attribute is written as a bare attribute name, the attribute
@@ -21,11 +28,13 @@ inputs to the `#[versioned()]` macro because it is an attribute macro:
2128
>
2229
> _(Taken from the [Rust reference][rust-ref])_
2330
24-
Because of that, a special delimiter is used in the input files which separates the two inputs while
25-
still enabling developers to write valid Rust code. The delimiter is `// ---\n`. Most of the inner
26-
workings are located in [this file](../src/test_utils.rs).
31+
Because of that, a special delimiter is used in the input files which separates different sections
32+
of the input file while still enabling developers to write valid Rust code. The delimiter is
33+
`// ---\n`. Most of the inner workings are located in [this file](../src/test_utils.rs).
2734

2835
```rust
36+
use stackable_versioned::versioned;
37+
// --- <- See here!
2938
#[versioned(
3039
version(name = "v1alpha1"),
3140
version(name = "v1beta1"),
@@ -40,36 +49,43 @@ pub(crate) struct Foo {
4049
bar: usize,
4150
baz: bool,
4251
}
52+
// --- <- See here!
53+
fn main() {}
54+
55+
// Rest of code ...
4356
```
4457

58+
Input files must include **three** separators which produce **four** distinct sections:
59+
60+
- Imports, like `stackable_versioned::versioned`
61+
- The attribute macro
62+
- The item the macro is applied to
63+
- The rest of the code, like the `main` function
64+
4565
### Recommended Workflow
4666

47-
First, add new input files (which automatically get picked up by `insta`) to the `fixtures/inputs`
48-
folder. Make sure the delimiter is placed correctly between the attribute and the container
49-
definition. Doc comments on the container have to be placed after the delimiter. Next, generate the
50-
snapshot files (initially not accepted) by running
67+
First, add new input files (which automatically get picked up by `insta`) to the `inputs`
68+
folder. Make sure the delimiter is placed correctly between the different sections. Doc comments on
69+
the container have to be placed after the delimiter. Next, generate the snapshot files (initially
70+
not accepted) by running
5171

5272
```shell
53-
cargo insta test -p stackable-versioned-macros
73+
cargo insta test -p stackable-versioned-macros --all-features
5474
```
5575

56-
This command will place the new snapshot files (with a `.new` extension) in the `fixtures/snapshots`
57-
folder. These new snapshot files must not appear on `main`, but can be shared on branches for
58-
collaboration. To review them, run the `cargo insta review` command, then accept or fix the
59-
snapshots. Once all are accepted (ie: no `.new` files remaining), check in the files.
76+
This command will place the new snapshot files (with a `.new` extension) in the `snapshots` folder.
77+
These new snapshot files must not appear on `main`, but can be shared on branches for collaboration.
78+
To review them, run the `cargo insta review` command, then accept or fix the snapshots. Once all are
79+
accepted (ie: no `.new` files remaining), check in the files.
6080

6181
## Compile-Fail Testing
6282

6383
> [!NOTE]
64-
> Also see the snapshot tests, described [here](../fixtures/README.md).
65-
66-
This type of testing is part of UI testing. These tests assert two things: First, the code should
67-
**not** compile and secondly should also produce the expected rustc (compiler) error message. For
68-
this type of testing, we use the [`trybuild`][trybuild] crate.
84+
> Also see the snapshot tests, described [here](#snapshot-testing).
6985
70-
Tests are currently separated into two folders: `default` and `k8s`. The default test cases don't
71-
require any additional features to be activated. The Kubernetes specific tests require the `k8s`
72-
feature to be enabled. These tests can be run with `cargo test --all-features`.
86+
This type of testing is part of UI testing. These tests assert two things: First, some code should
87+
compile without errors and secondly other code should produce the expected rustc (compiler) error
88+
message. For this type of testing, we use the [`trybuild`][trybuild] crate.
7389

7490
Further information about the workflow are described [here][workflow].
7591

0 commit comments

Comments
 (0)