diff --git a/Cargo.toml b/Cargo.toml index 7d3596a..6b65102 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/venndb-usage/Cargo.toml b/venndb-usage/Cargo.toml index 4de52af..38942da 100644 --- a/venndb-usage/Cargo.toml +++ b/venndb-usage/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" [dependencies] venndb = { path = ".." } + +[dev-dependencies] +trybuild = "1" diff --git a/venndb-usage/tests/compilation_tests.rs b/venndb-usage/tests/compilation_tests.rs new file mode 100644 index 0000000..a414ace --- /dev/null +++ b/venndb-usage/tests/compilation_tests.rs @@ -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"); +} diff --git a/venndb-usage/tests/compiles/derive_struct.rs b/venndb-usage/tests/compiles/derive_struct.rs new file mode 100644 index 0000000..c1dbadd --- /dev/null +++ b/venndb-usage/tests/compiles/derive_struct.rs @@ -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() {} diff --git a/venndb-usage/tests/fails/derive_enum.rs b/venndb-usage/tests/fails/derive_enum.rs new file mode 100644 index 0000000..7e60538 --- /dev/null +++ b/venndb-usage/tests/fails/derive_enum.rs @@ -0,0 +1,9 @@ +use venndb::VennDB; + +#[derive(VennDB)] +enum MyEnum { + A, + B, +} + +fn main() {} diff --git a/venndb-usage/tests/fails/derive_enum.stderr b/venndb-usage/tests/fails/derive_enum.stderr new file mode 100644 index 0000000..215cd37 --- /dev/null +++ b/venndb-usage/tests/fails/derive_enum.stderr @@ -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 | | } + | |_^ diff --git a/venndb-usage/tests/fails/derive_tuple_struct.rs b/venndb-usage/tests/fails/derive_tuple_struct.rs new file mode 100644 index 0000000..60c35d4 --- /dev/null +++ b/venndb-usage/tests/fails/derive_tuple_struct.rs @@ -0,0 +1,6 @@ +use venndb::VennDB; + +#[derive(VennDB)] +struct MyStruct(u32); + +fn main() {} diff --git a/venndb-usage/tests/fails/derive_tuple_struct.stderr b/venndb-usage/tests/fails/derive_tuple_struct.stderr new file mode 100644 index 0000000..6a04b7f --- /dev/null +++ b/venndb-usage/tests/fails/derive_tuple_struct.stderr @@ -0,0 +1,5 @@ +error: Only Structs with named fields are supported + --> tests/fails/derive_tuple_struct.rs:4:1 + | +4 | struct MyStruct(u32); + | ^^^^^^^^^^^^^^^^^^^^^