1#!./perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 require './test.pl'; 6 set_up_inc('../lib'); 7 require './charset_tools.pl'; 8} 9 10plan(tests => 9); 11 12{ 13 local $SIG{__WARN__} = sub {}; 14 eval "evalbytes 'foo'"; 15 like $@, qr/syntax error/, 'evalbytes outside feature scope'; 16} 17 18# We enable unicode_eval just to test that it does not interfere. 19use feature 'evalbytes', 'unicode_eval'; 20 21is evalbytes("1+7"), 8, 'evalbytes basic sanity check'; 22 23my $code = qq('\xff\xfe'); 24is evalbytes($code), "\xff\xfe", 'evalbytes on extra-ASCII bytes'; 25chop((my $upcode = $code) .= chr 256); 26is evalbytes($upcode), "\xff\xfe", 'evalbytes on upgraded extra-ASCII'; 27{ 28 use utf8; 29 is evalbytes($code), "\xff\xfe", 'evalbytes ignores outer utf8 pragma'; 30} 31my $U_100 = byte_utf8a_to_utf8n("\xc4\x80"); 32is evalbytes "use utf8; $U_100", chr 256, 'use utf8 within evalbytes'; 33chop($upcode = "use utf8; $U_100" . chr 256); 34is evalbytes $upcode, chr 256, 'use utf8 within evalbytes on utf8 string'; 35eval { evalbytes chr 256 }; 36like $@, qr/Wide character/, 'evalbytes croaks on non-bytes'; 37 38eval 'evalbytes S'; 39ok 1, '[RT #129196] evalbytes S should not segfault'; 40 41