Skip to content

Commit 8438d46

Browse files
vovkasmmohawk2
authored andcommitted
Add C++ XS tests
1 parent 0c53283 commit 8438d46

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;
@@ -194,6 +194,80 @@ $label2files{staticmulti} = +{
194194
),
195195
};
196196

197+
$label2files{cppbasic} = +{
198+
199+
'lib/XSCPP/Test.pm' => <<'END',
200+
package XSCPP::Test;
201+
require Exporter;
202+
require DynaLoader;
203+
$VERSION = 1.02;
204+
@ISA = qw(Exporter DynaLoader);
205+
@EXPORT = qw(is_even);
206+
bootstrap XSCPP::Test $VERSION;
207+
1;
208+
END
209+
210+
'Makefile.PL' => <<'END',
211+
use ExtUtils::MakeMaker;
212+
use ExtUtils::CppGuess;
213+
my $guess = ExtUtils::CppGuess->new;
214+
WriteMakefile(
215+
NAME => 'XSCPP::Test',
216+
VERSION_FROM => 'lib/XSCPP/Test.pm',
217+
XSMULTI => 1,
218+
$guess->makemaker_options,
219+
);
220+
END
221+
222+
'lib/XSCPP/Test.xspp' => <<END,
223+
extern "C" {
224+
#include "EXTERN.h"
225+
#include "perl.h"
226+
}
227+
#include "XSUB.h"
228+
class CPPTest {
229+
public:
230+
CPPTest() { }
231+
~CPPTest() { }
232+
int is_even(int num) { return (num % 2) == 0; }
233+
};
234+
\nMODULE = XSCPP::Test PACKAGE = XSCPP::Test
235+
\nPROTOTYPES: DISABLE
236+
CPPTest*
237+
CPPTest::new();
238+
\nint
239+
CPPTest::is_even(int input);
240+
\nvoid
241+
CPPTest::DESTROY();
242+
END
243+
244+
'typemap' => <<'END',
245+
TYPEMAP
246+
CPPTest * O_OBJECT
247+
OUTPUT
248+
O_OBJECT
249+
sv_setref_pv( $arg, CLASS, (void*)$var );
250+
INPUT
251+
O_OBJECT
252+
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) )
253+
$var = ($type)SvIV((SV*)SvRV( $arg ));
254+
else{
255+
warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
256+
XSRETURN_UNDEF;
257+
}
258+
END
259+
260+
't/is_even.t' => <<'END',
261+
#!/usr/bin/perl -w
262+
use Test::More tests => 3;
263+
use_ok "XSCPP::Test";
264+
my $o = XSCPP::Test->new;
265+
ok !$o->is_even(1);
266+
ok $o->is_even(2);
267+
END
268+
269+
};
270+
197271
sub virtual_rename {
198272
my ($label, $oldfile, $newfile) = @_;
199273
$label2files{$label}->{$newfile} = delete $label2files{$label}->{$oldfile};
@@ -237,6 +311,11 @@ sub list_dynamic {
237311
);
238312
}
239313

314+
sub list_cpp {
315+
(
316+
);
317+
}
318+
240319
sub run_tests {
241320
my ($perl, $label, $add_target, $add_testtarget) = @_;
242321
my $sublabel = $add_target;

0 commit comments

Comments
 (0)