From da077497a2be5f455f4905ed0ef323604a091aca Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Fri, 30 Apr 2021 14:53:49 +0200 Subject: [PATCH] Add trybuild tests to test error message reported when matrix dims mismatch --- nalgebra-macros/Cargo.toml | 1 + nalgebra-macros/tests/tests.rs | 16 ++++++++++++++++ .../trybuild/dmatrix_mismatched_dimensions.rs | 6 ++++++ .../dmatrix_mismatched_dimensions.stderr | 5 +++++ .../trybuild/matrix_mismatched_dimensions.rs | 6 ++++++ .../trybuild/matrix_mismatched_dimensions.stderr | 5 +++++ 6 files changed, 39 insertions(+) create mode 100644 nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.rs create mode 100644 nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.stderr create mode 100644 nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.rs create mode 100644 nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.stderr diff --git a/nalgebra-macros/Cargo.toml b/nalgebra-macros/Cargo.toml index 1f27b572..5ebef960 100644 --- a/nalgebra-macros/Cargo.toml +++ b/nalgebra-macros/Cargo.toml @@ -17,3 +17,4 @@ proc-macro2 = "1.0" [dev-dependencies] nalgebra = { version = "0.26.1", path = ".." } +trybuild = "1.0.42" diff --git a/nalgebra-macros/tests/tests.rs b/nalgebra-macros/tests/tests.rs index c97ae103..c9d64d91 100644 --- a/nalgebra-macros/tests/tests.rs +++ b/nalgebra-macros/tests/tests.rs @@ -114,4 +114,20 @@ fn dvector_small_dims_exhaustive() { assert_eq_and_type!(dvector![1, 2, 3, 4], DVector::from_column_slice(&[1, 2, 3, 4])); assert_eq_and_type!(dvector![1, 2, 3, 4, 5], DVector::from_column_slice(&[1, 2, 3, 4, 5])); assert_eq_and_type!(dvector![1, 2, 3, 4, 5, 6], DVector::from_column_slice(&[1, 2, 3, 4, 5, 6])); +} + +#[test] +fn matrix_trybuild_tests() { + let t = trybuild::TestCases::new(); + + // Verify error message when we give a matrix with mismatched dimensions + t.compile_fail("tests/trybuild/matrix_mismatched_dimensions.rs"); +} + +#[test] +fn dmatrix_trybuild_tests() { + let t = trybuild::TestCases::new(); + + // Verify error message when we give a matrix with mismatched dimensions + t.compile_fail("tests/trybuild/dmatrix_mismatched_dimensions.rs"); } \ No newline at end of file diff --git a/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.rs b/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.rs new file mode 100644 index 00000000..786b5849 --- /dev/null +++ b/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.rs @@ -0,0 +1,6 @@ +use nalgebra_macros::dmatrix; + +fn main() { + dmatrix![1, 2, 3; + 4, 5]; +} \ No newline at end of file diff --git a/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.stderr b/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.stderr new file mode 100644 index 00000000..eaedc650 --- /dev/null +++ b/nalgebra-macros/tests/trybuild/dmatrix_mismatched_dimensions.stderr @@ -0,0 +1,5 @@ +error: Unexpected number of entries in row 1. Expected 3, found 2 entries. + --> $DIR/dmatrix_mismatched_dimensions.rs:5:13 + | +5 | 4, 5]; + | ^ diff --git a/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.rs b/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.rs new file mode 100644 index 00000000..c5eb87b7 --- /dev/null +++ b/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.rs @@ -0,0 +1,6 @@ +use nalgebra_macros::matrix; + +fn main() { + matrix![1, 2, 3; + 4, 5]; +} \ No newline at end of file diff --git a/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.stderr b/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.stderr new file mode 100644 index 00000000..c83e8d0c --- /dev/null +++ b/nalgebra-macros/tests/trybuild/matrix_mismatched_dimensions.stderr @@ -0,0 +1,5 @@ +error: Unexpected number of entries in row 1. Expected 3, found 2 entries. + --> $DIR/matrix_mismatched_dimensions.rs:5:13 + | +5 | 4, 5]; + | ^