From: Thomas Lamprecht Date: Fri, 18 Oct 2019 18:28:59 +0000 (+0200) Subject: tests: add map_expect_to_param_id feature for checking side-effects X-Git-Url: https://git.proxmox.com/?p=pve-guest-common.git;a=commitdiff_plain;h=975e60d986579b6fa30dcda793b79348ab6619c9 tests: add map_expect_to_param_id feature for checking side-effects Signed-off-by: Thomas Lamprecht --- diff --git a/tests/abstract-config-tests.pl b/tests/abstract-config-tests.pl index d807623..8f58e42 100755 --- a/tests/abstract-config-tests.pl +++ b/tests/abstract-config-tests.pl @@ -15,6 +15,9 @@ use PVE::AbstractConfig; # tests need to specify the method, the parameter and expected result # for neatly doing more tests per single method you can specifiy a subtests # array, which then only has params and expected result +# sometimes the return value is less interesting to check than a parameter +# reference, so one can use "map_expect_to_param_id" to tell the test system to +# use that as expected result. # note that the indentaion level below is "wrong" by design my $tests = [ @@ -133,6 +136,15 @@ sub do_test($$;$) { my ($params, $expect) = $test->@{qw(params expect)}; my $res = eval { PVE::AbstractConfig->$method(@$params) }; + + if (defined(my $param_id = $test->{map_expect_to_param_id})) { + # it's a /cool/ hack, sometimes we have the interesting result in + # "call-by-reference" param, and the return value is just some "I did + # someting" or plain undef value. So allow to map the result to one of + # the parameters + $res = $params->[$param_id]; + } + if (my $err = $@) { is ($err, $expect, $name); } else {