Skip to content

Commit e06e7f7

Browse files
vovkasmmohawk2
authored andcommitted
Add C++ XS tests
1 parent ea2c9ae commit e06e7f7

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

t/04-xscpp.t

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/perl -w
2+
3+
use strict;
4+
use warnings;
5+
use Config;
6+
BEGIN {
7+
chdir 't' or die "chdir(t): $!\n";
8+
unshift @INC, 'lib/';
9+
}
10+
use MakeMaker::Test::Utils;
11+
use MakeMaker::Test::Setup::XS;
12+
use Test::More;
13+
14+
plan skip_all => "ExtUtils::CBuilder not installed or no C++ compiler"
15+
unless have_cplusplus();
16+
plan skip_all => 'Dynaloading not enabled' if $Config{usedl} ne 'define';
17+
my @tests = list_cpp();
18+
plan skip_all => "No tests" unless @tests;
19+
plan tests => 6 * @tests;
20+
my $perl = which_perl();
21+
perl_lib;
22+
$| = 1;
23+
run_tests($perl, @$_) for @tests;

t/lib/MakeMaker/Test/Setup/XS.pm

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package MakeMaker::Test::Setup::XS;
22

33
@ISA = qw(Exporter);
44
require Exporter;
5-
@EXPORT = qw(run_tests list_dynamic list_static);
5+
@EXPORT = qw(run_tests list_dynamic list_static list_cpp);
66

77
use strict;
88
use File::Path;
@@ -246,6 +246,80 @@ END
246246

247247
};
248248

249+
$label2files{cppbasic} = +{
250+
251+
'lib/XSCPP/Test.pm' => <<'END',
252+
package XSCPP::Test;
253+
require Exporter;
254+
require DynaLoader;
255+
$VERSION = 1.02;
256+
@ISA = qw(Exporter DynaLoader);
257+
@EXPORT = qw(is_even);
258+
bootstrap XSCPP::Test $VERSION;
259+
1;
260+
END
261+
262+
'Makefile.PL' => <<'END',
263+
use ExtUtils::MakeMaker;
264+
use ExtUtils::CppGuess;
265+
my $guess = ExtUtils::CppGuess->new;
266+
WriteMakefile(
267+
NAME => 'XSCPP::Test',
268+
VERSION_FROM => 'lib/XSCPP/Test.pm',
269+
XSMULTI => 1,
270+
$guess->makemaker_options,
271+
);
272+
END
273+
274+
'lib/XSCPP/Test.xscc' => <<END,
275+
extern "C" {
276+
#include "EXTERN.h"
277+
#include "perl.h"
278+
}
279+
#include "XSUB.h"
280+
class CPPTest {
281+
public:
282+
CPPTest() { }
283+
~CPPTest() { }
284+
int is_even(int num) { return (num % 2) == 0; }
285+
};
286+
\nMODULE = XSCPP::Test PACKAGE = XSCPP::Test
287+
\nPROTOTYPES: DISABLE
288+
CPPTest*
289+
CPPTest::new();
290+
\nint
291+
CPPTest::is_even(int input);
292+
\nvoid
293+
CPPTest::DESTROY();
294+
END
295+
296+
'typemap' => <<'END',
297+
TYPEMAP
298+
CPPTest * O_OBJECT
299+
OUTPUT
300+
O_OBJECT
301+
sv_setref_pv( $arg, CLASS, (void*)$var );
302+
INPUT
303+
O_OBJECT
304+
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) )
305+
$var = ($type)SvIV((SV*)SvRV( $arg ));
306+
else{
307+
warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
308+
XSRETURN_UNDEF;
309+
}
310+
END
311+
312+
't/is_even.t' => <<'END',
313+
#!/usr/bin/perl -w
314+
use Test::More tests => 3;
315+
use_ok "XSCPP::Test";
316+
my $o = XSCPP::Test->new;
317+
ok !$o->is_even(1);
318+
ok $o->is_even(2);
319+
END
320+
321+
};
322+
249323
sub virtual_rename {
250324
my ($label, $oldfile, $newfile) = @_;
251325
$label2files{$label}->{$newfile} = delete $label2files{$label}->{$oldfile};
@@ -291,6 +365,11 @@ sub list_dynamic {
291365
);
292366
}
293367

368+
sub list_cpp {
369+
(
370+
);
371+
}
372+
294373
sub run_tests {
295374
my ($perl, $label, $add_target, $add_testtarget) = @_;
296375
my $sublabel = $add_target;

0 commit comments

Comments
 (0)