use
SPVM
'TestCase::Operator::Stdio'
;
use
SPVM
'TestCase::NativeAPI'
;
my
$test_dir
=
$ENV
{SPVM_TEST_DIR};
my
$build_dir
=
$ENV
{SPVM_BUILD_DIR};
my
$test_tmp_dir
=
"$test_dir/test_files_tmp"
;
my
$script_file
=
"$test_tmp_dir/print-script.pl"
;
my
$output_file
=
"$test_tmp_dir/print-output.txt"
;
mkpath
$test_tmp_dir
;
sub
write_script_file {
my
(
$script_file
,
$func_call
) =
@_
;
my
$pre
=
<<"EOS";
use lib "t/testlib";
use TestAuto;
use strict;
use warnings;
use SPVM 'TestCase::Operator::Stdio';
use TestFile;
EOS
open
my
$script_fh
,
'>'
,
$script_file
or
die
"Can't open file $script_file: $!"
;
my
$output_source
=
"$pre$func_call;"
;
print
$script_fh
$output_source
;
}
sub
slurp_binmode {
my
(
$output_file
) =
@_
;
open
my
$fh
,
'<'
,
$output_file
or
die
"Can't open file $output_file:$!"
;
binmode
$fh
;
my
$output
=
do
{
local
$/; <
$fh
> };
return
$output
;
}
my
$api
= SPVM::api();
my
$start_memory_blocks_count
=
$api
->get_memory_blocks_count();
{
{
{
my
$func_call
=
'SPVM::TestCase::Operator::Stdio->print_line_feed_to_stdout'
;
write_script_file(
$script_file
,
$func_call
);
system
(
"$^X -Mblib $script_file > $output_file"
);
my
$output
= slurp_binmode(
$output_file
);
is(
$output
,
"\x0A"
);
}
}
{
{
my
$func_call
=
'SPVM::TestCase::Operator::Stdio->print_line_feed_to_stderr'
;
write_script_file(
$script_file
,
$func_call
);
system
(
"$^X -Mblib $script_file 2> $output_file"
);
my
$output
= slurp_binmode(
$output_file
);
is(
$output
,
"\x0A"
);
}
}
ok(SPVM::TestCase::NativeAPI->check_stdio_binary_mode);
}
$api
->set_exception(
undef
);
my
$end_memory_blocks_count
=
$api
->get_memory_blocks_count();
is(
$end_memory_blocks_count
,
$start_memory_blocks_count
);
done_testing;