From 0044cdcef495beea96acf6cb195a8cb99e68373a Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 25 Nov 2021 10:17:33 +0100 Subject: [PATCH] test trailing-optional parameters we'll need proper tests to check that too few and too many parameters actually trigger errors Signed-off-by: Wolfgang Bumiller --- perlmod-test/src/pkg142.rs | 5 +++++ test.pl | 6 ++++++ test.pl.expected | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/perlmod-test/src/pkg142.rs b/perlmod-test/src/pkg142.rs index 2c9d212..7839eb1 100644 --- a/perlmod-test/src/pkg142.rs +++ b/perlmod-test/src/pkg142.rs @@ -70,6 +70,11 @@ mod export { _ => bail!("invalid"), }) } + + #[export] + fn test_trailing_optional(first: u32, second: Option) { + println!("{:?}, {:?}", first, second); + } } #[perlmod::package(name = "RSPM::EnvVarLibrary", lib = "x-${CARGO_PKG_NAME}-y")] diff --git a/test.pl b/test.pl index d182514..87baec6 100644 --- a/test.pl +++ b/test.pl @@ -105,7 +105,13 @@ test_unsafe_clone(Storable::dclone($magic)); print("Testing unsafe clone\n"); test_unsafe_clone(Clone::clone($magic)); +undef $magic; print("Testing enum deserialization\n"); my $ra = RSPM::Foo142::test_enums("something"); die "unexpected result from test_enums: $ra\n" if $ra ne 'result-a'; + +print("Testing optional parameters\n"); +RSPM::Foo142::test_trailing_optional(1, 99); +RSPM::Foo142::test_trailing_optional(2, undef); +RSPM::Foo142::test_trailing_optional(3); diff --git a/test.pl.expected b/test.pl.expected index 34ba871..25465f9 100644 --- a/test.pl.expected +++ b/test.pl.expected @@ -37,5 +37,9 @@ Testing unsafe dclone unsafe dclone dropped Testing unsafe clone unsafe dclone dropped -Testing enum deserialization Dropping blessed magic with content "magic test" +Testing enum deserialization +Testing optional parameters +1, Some(99) +2, None +3, None