File: readonly.t

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (49 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!perl

# Test script to reproduce error:
#   Modification of a read-only value attempted at //ms/dist/perl5/PROJ/IPC-Run/0.79/lib/perl5/IPC/Run.pm line 1695
#
# Global $_ is set to a Readonly value when IPC::run() is called.
# Note that in test below, $value (which is $_) is not actually passed to IPC::run()
#

use strict;
use warnings;

use IPC::Run 'run';
use Test::More;

$] > 5.014 or plan skip_all => q{IPC::Run doesn't support Readonly below 5.14};

BEGIN {
    eval 'use Readonly';
    $INC{'Readonly.pm'} or plan skip_all => "Readonly is required for this test to work.";
}

my @lowercase = 'a' .. 'c';
Readonly::Array my @UPPERCASE => 'A' .. 'C';
Readonly my @MIXEDCASE        => qw( X y Z );

run_echo($_) for ( @lowercase, @UPPERCASE, @MIXEDCASE );

done_testing();
exit;

sub run_echo {
    my $value = shift;

    #   my @args = ( '/bin/echo', $value );
    my @args = ( '/bin/echo', 'hello' );
    if ($^O eq 'MSWin32') {
        @args = ( $^X, '-e', 'print "hello\n"' );
    }

    my $t = "test case '$value': '@args'";
    note("Running $t");

    my ( $in, $out, $err );
    my $rv = run( [@args], \$in, \$out, \$err )
      or die "Cannot run @args: $err";
    ok( $rv, "Ran $t: OK" );
    note($out);
}