1#!./perl 2 3BEGIN { 4 require Config; 5 if (($Config::Config{'extensions'} !~ /\bre\b/) ){ 6 print "1..0 # Skip -- Perl configured without re module\n"; 7 exit 0; 8 } 9} 10 11use strict; 12 13my $re_taint_bit = 0x00100000; 14my $re_eval_bit = 0x00200000; 15 16use Test::More tests => 16; 17require_ok( 're' ); 18 19# setcolor 20$INC{ 'Term/Cap.pm' } = 1; 21local $ENV{PERL_RE_TC}; 22re::setcolor(); 23is( $ENV{PERL_RE_COLORS}, "md\tme\tso\tse\tus\tue", 24 'setcolor() should provide default colors' ); 25$ENV{PERL_RE_TC} = 'su,n,ny'; 26re::setcolor(); 27is( $ENV{PERL_RE_COLORS}, "su\tn\tny", '... or use $ENV{PERL_RE_COLORS}' ); 28 29# bits 30# get on 31my $warn; 32local $SIG{__WARN__} = sub { 33 $warn = shift; 34}; 35#eval { re::bits(1) }; 36#like( $warn, qr/Useless use/, 'bits() should warn with no args' ); 37 38delete $ENV{PERL_RE_COLORS}; 39re::bits(0, 'debug'); 40is( $ENV{PERL_RE_COLORS}, undef, 41 "... should not set regex colors given 'debug'" ); 42re::bits(0, 'debugcolor'); 43isnt( $ENV{PERL_RE_COLORS}, '', 44 "... should set regex colors given 'debugcolor'" ); 45re::bits(0, 'nosuchsubpragma'); 46like( $warn, qr/Unknown "re" subpragma/, 47 '... should warn about unknown subpragma' ); 48ok( re::bits(0, 'taint') & $re_taint_bit, '... should set taint bits' ); 49ok( re::bits(0, 'eval') & $re_eval_bit, '... should set eval bits' ); 50 51undef $warn; 52eval "use re qw(debug ALL)"; 53like( $warn, qr/"Debug" not "debug"/, 'debug with debugging type should warn'); 54 55local $^H; 56 57# import 58re->import('taint', 'eval'); 59ok( $^H & $re_taint_bit, 'import should set taint bits in $^H when requested' ); 60ok( $^H & $re_eval_bit, 'import should set eval bits in $^H when requested' ); 61 62re->unimport('taint'); 63ok( !( $^H & $re_taint_bit ), 'unimport should clear bits in $^H when requested' ); 64re->unimport('eval'); 65ok( !( $^H & $re_eval_bit ), '... and again' ); 66my $reg=qr/(foo|bar|baz|blah)/; 67close STDERR; 68eval"use re Debug=>'ALL'"; 69my $ok='foo'=~/$reg/; 70eval"no re Debug=>'ALL'"; 71ok( $ok, 'No segv!' ); 72 73my $message = "Don't tread on me"; 74$_ = $message; 75re->import("/aa"); 76is($_, $message, "re doesn't clobber \$_"); 77 78package Term::Cap; 79 80sub Tgetent { 81 bless({}, $_[0]); 82} 83 84sub Tputs { 85 return $_[1]; 86} 87 88package main; 89 90{ 91 my $w; 92 local $SIG{__WARN__} = sub { warn shift; ++$w }; 93 re->import(); 94 is $w, undef, 'no warning for "use re;" (which is not useless)'; 95} 96