Created
April 14, 2012 14:53
-
-
Save mix3/2384966 to your computer and use it in GitHub Desktop.
C output capture test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
BEGIN { use_ok('IOCaptureTest') }; | |
use Capture::Tiny qw/:all/; | |
my $output; | |
$output = capture { | |
IOCaptureTest::c_print_with_fflush(); | |
}; | |
is($output, 'C Output with fflush', 'OK'); | |
$output = capture { | |
IOCaptureTest::perl_print(); | |
}; | |
is($output, 'Perl Output', 'OK'); | |
$output = capture { | |
IOCaptureTest::c_print(); | |
}; | |
is($output, 'C Output', 'NG'); | |
done_testing();#include "EXTERN.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "perl.h" | |
#include "XSUB.h" | |
#include "ppport.h" | |
MODULE = IOCaptureTest> > PACKAGE = IOCaptureTest>> | |
void | |
c_print() | |
CODE: | |
{ | |
printf("C Output"); | |
} | |
void | |
perl_print() | |
CODE: | |
{ | |
PerlIO_stdoutf("Perl Output"); | |
} | |
void | |
c_print_with_fflush() | |
CODE: | |
{ | |
printf("C Output with fflush"); | |
fflush( stdout ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl -Mblib -MIOCaptureTest t/IOCaptureTest.t | |
ok 1 - use IOCaptureTest; | |
ok 2 - OK | |
ok 3 - OK | |
not ok 4 - NG | |
# Failed test 'NG' | |
# at t/IOCaptureTest.t line 39. | |
# got: '' | |
# expected: 'C Output' | |
1..4 | |
# Looks like you failed 1 test of 4. | |
C Output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment