File: cond.t

package info (click to toggle)
perl 5.32.1-4%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,408 kB
  • sloc: ansic: 641,443; perl: 491,650; sh: 70,967; pascal: 8,354; cpp: 4,103; xml: 2,428; makefile: 2,237; yacc: 1,173; lisp: 1
file content (31 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (4)
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
#!./perl

BEGIN {
    chdir 't' if -d 't';
    require './test.pl';
    set_up_inc('../lib');
}

is( 1 ? 1 : 0, 1, 'compile time, true' );
is( 0 ? 0 : 1, 1, 'compile time, false' );

$x = 1;
is(  $x ? 1 : 0, 1, 'run time, true');
is( !$x ? 0 : 1, 1, 'run time, false');

# This used to SEGV due to deep recursion in Perl_scalar().
# (Actually it only SEGVed with the depth being about 100_000; but
# compiling the nested condition goes quadratic in some way, so I've
# reduced to the count to a manageable size. So this is not so much a
# proper test, as it is a comment on the sort of thing that used to break)

{
    my $e = "1";
    $e = "(\$x ? 1 : $e)" for 1..20_000;
    $e = "\$x = $e";
    eval $e;
    is $@, "", "SEGV in Perl_scalar";
}


done_testing();