Skip to content

Commit

Permalink
add first derive compilation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Mar 31, 2024
1 parent ef1ee2f commit 91bc602
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
quote = "1"
syn = "2"
quote = "1.0"
syn = "2.0"

[lib]
proc-macro = true
3 changes: 3 additions & 0 deletions venndb-usage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ edition = "2021"

[dependencies]
venndb = { path = ".." }

[dev-dependencies]
trybuild = "1"
11 changes: 11 additions & 0 deletions venndb-usage/tests/compilation_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[test]
fn should_compile() {
let t = trybuild::TestCases::new();
t.pass("tests/compiles/*.rs");
}

#[test]
fn should_not_compile() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/fails/*.rs");
}
21 changes: 21 additions & 0 deletions venndb-usage/tests/compiles/derive_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use venndb::VennDB;

#[derive(Debug, VennDB)]
struct Employee {
id: u32,
name: String,
is_manager: bool,
is_admin: bool,
is_active: bool,
department: Department,
}

#[derive(Debug)]
pub enum Department {
Engineering,
Sales,
Marketing,
HR,
}

fn main() {}
9 changes: 9 additions & 0 deletions venndb-usage/tests/fails/derive_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use venndb::VennDB;

#[derive(VennDB)]
enum MyEnum {
A,
B,
}

fn main() {}
8 changes: 8 additions & 0 deletions venndb-usage/tests/fails/derive_enum.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: Only Structs with named fields are supported
--> tests/fails/derive_enum.rs:4:1
|
4 | / enum MyEnum {
5 | | A,
6 | | B,
7 | | }
| |_^
6 changes: 6 additions & 0 deletions venndb-usage/tests/fails/derive_tuple_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use venndb::VennDB;

#[derive(VennDB)]
struct MyStruct(u32);

fn main() {}
5 changes: 5 additions & 0 deletions venndb-usage/tests/fails/derive_tuple_struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Only Structs with named fields are supported
--> tests/fails/derive_tuple_struct.rs:4:1
|
4 | struct MyStruct(u32);
| ^^^^^^^^^^^^^^^^^^^^^

0 comments on commit 91bc602

Please sign in to comment.