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