Skip to content

Commit b834428

Browse files
authored
Use trybuild for testing macros (#423)
1 parent 482b89f commit b834428

File tree

90 files changed

+969
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+969
-46
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ indent_style = unset
4646
[HELP.md]
4747
max_line_length = 400
4848
trim_trailing_whitespace = false
49+
50+
[*.stderr]
51+
indent_size = unset
52+
max_line_length = unset

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,16 @@ jobs:
121121
run: cd butane_test_helper && cargo +stable test --all-features
122122
- name: Test Core
123123
run: cd butane_core && cargo +stable test --all-features
124-
- name: Test Codegen
125-
run: cd butane_codegen && cargo +stable test --all-features
126124
- name: Test CLI
127125
run: cd butane_cli && cargo +stable test --all-features
128126
- name: Test
129127
run: cargo +stable test -p butane_tests --all-features
128+
- name: Test using trybuild
129+
run: cargo +stable test -p trybuild_tests
130+
- name: Test doctests
131+
run: |
132+
cargo +stable test -p butane_codegen --all-features
133+
cargo +stable test -p butane --all-features
130134
- name: Check example migrations have been updated
131135
run: |
132136
set -ex

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ butane.code_workspace.code-workspace
77
.vscode/tasks.json
88
butane_codegen/.butane
99
butane/tests/.butane
10+
trybuild_tests/tests/Cargo.toml
1011
db.sqlite
1112
tmp_pg
1213
*.db

CONTRIBUTING.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,23 @@ cargo test
9494
Run tests for a specific package:
9595

9696
```bash
97-
cargo test -p butane
9897
cargo test -p butane_core
98+
cargo test -p butane # doctests only
99+
cargo test -p butane_tests
100+
cargo test -p trybuild_tests
99101
```
100102

103+
If you are enhancing `butane_codegen`, please create tests in [`trybuild_tests`](trybuild_tests/)
104+
instead of `butane_codegen`.
105+
106+
## Development notes
107+
108+
There is a cyclic test dependency between `butane_test_helper` and `butane_core`.
109+
110+
`butane_test_helper` uses `butane_core` in its library.
111+
112+
`butane_core` uses `butane_test_helper` in its tests.
113+
101114
## Code Quality
102115

103116
Before submitting a PR, you may use the following commands locally to ensure that your code passes all checks:

Cargo.lock

Lines changed: 132 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
"examples/getting_started",
1515
"examples/getting_started_async",
1616
"examples/reserved-words",
17+
"trybuild_tests",
1718
]
1819

1920
[workspace.package]

butane_codegen/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ syn = { workspace = true }
2424

2525
[lib]
2626
proc-macro = true
27+
# When `cargo test` & `cargo nextest run` are run at the top of the workspace,
28+
# they fail if `test = true` here.
29+
# See https://github.com/Electron100/butane/issues/419
30+
test = false

butane_codegen/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use syn::{Expr, Ident};
1717

1818
mod filter;
1919

20-
#[cfg(test)]
21-
mod test_field_type;
20+
// Note: butane_codegen is a proc-macro crate and cannot have unit tests
21+
// Tests for derive macros should be in butane_core or integration tests
2222

2323
/// Attribute macro which marks a struct as being a data model and
2424
/// generates an implementation of [`DataObject`](butane_core::DataObject). This

butane_codegen/src/test_field_type.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

trybuild_tests/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This project member only contains tests that built using `trybuild`.
2+
# These tests allow snapshotting of compiler errors and warnings to ensure that
3+
# incorrect usage of macros fails as expected, and provides useful error messages.
4+
# See the README.md in this directory for more information.
5+
[package]
6+
name = "trybuild_tests"
7+
edition.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
version.workspace = true
11+
rust-version.workspace = true
12+
autobenches = false
13+
autobins = false
14+
autoexamples = false
15+
16+
[lib]
17+
doctest = false
18+
test = false
19+
20+
[dependencies]
21+
22+
[dev-dependencies]
23+
butane.workspace = true
24+
serde = { workspace = true, features = ["derive"] }
25+
serde_json.workspace = true
26+
trybuild = "1.0"

0 commit comments

Comments
 (0)