in reply to Running specific test files with sudo

Why rerun your test through prove instead of simply rerunning your test program? That way, whatever harness the user uses will just receive the output from your restarted program...

Also, there is a skip command in Test::More, which is a bit cumbersome to use but outputs a nicer message than a passing test:

use Test::More; plan tests => 10; if( $> != 0 ) { # re-exec as root: # hope we didn't have -Ilib or -Mblib on the invocation line exec 'sudo', $0, @ARGV; # Also see Devel::PL_origargv }; if( $> != 0 ) { SKIP: { skip "Must be root", 10; }; exit; }; ... run tests as root ...

Replies are listed 'Best First'.
Re^2: Running specific test files with sudo
by stevieb (Canon) on Mar 19, 2017 at 17:07 UTC

    Thanks Corion.

    I do already use the skip feature of Test::More in certain cases. Below is an example so that if a user isn't on a Pi, certain test files will skip. This prevents needless test failures on the CPAN:

    if (! $ENV{PI_BOARD}){ plan skip_all => "not on a pi board (PI_BOARD env var not set)\n"; }

    I will give using exec a go.