Skip to content

Commit c3449a4

Browse files
committed
Perlito5 - XS - organize tests a bit
1 parent b3566a1 commit c3449a4

37 files changed

+610
-66
lines changed

t5-xs/Makefile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11

2-
CODE = package Some::Thing;
3-
#CODE += sub foo { my $$something = 21; return $$something * 2; }
4-
CODE += sub foo { warn( "MOO" ) }
5-
#CODE += sub foo { my $$something = [qw[ Hello World ]]; return $$something }
6-
#CODE += sub bar { my @something = qw( Hello World ); return \@something }
2+
# keep names uppercase and a single word to keep the makefile simple
3+
TESTS += ReturnHelloWorld
4+
TESTS += ReturnArray
5+
TESTS += ReturnArrayRef
6+
TESTS += Warn
77

88
all: rebuild test
99

10-
test:
11-
perl ../perlito5.pl -I../src5/lib -Cast-perl5 -e '${CODE}'
12-
test -d Some-Thing || h2xs --skip-ppport -An Some::Thing
13-
perl ../perlito5.pl -I../src5/lib -Cxs -e '${CODE}' > Some-Thing/Thing.xs
14-
cd Some-Thing && perl Makefile.PL && make test TEST_VERBOSE=1
10+
test: ${TESTS:%=test-%}
1511

12+
# to strip leading "test-" in target rule from target name
13+
TEST = ${@:test-%=%}
14+
15+
# prepend "test-" to all test targets
16+
${TESTS:%=test-%}:
17+
perl ../perlito5.pl -I../src5/lib -Cast-perl5 ${TEST}.pl
18+
test -d ${TEST} || ( \
19+
h2xs --skip-ppport -An ${TEST} && \
20+
cd ${TEST} && echo -e "use Test::More tests => 2;\nBEGIN { use_ok('${TEST}') }\nok( ${TEST}::test() );" > \
21+
t/${TEST}.t \
22+
)
23+
perl ../perlito5.pl -I../src5/lib -Cxs ${TEST}.pl > ${TEST}/${TEST}.xs
24+
cd ${TEST} && perl Makefile.PL && make test TEST_VERBOSE=1
1625

1726
rebuild:
1827
cd ../ && make build-5to5
1928

29+
clean:
30+
-for D in ${TESTS}; do \
31+
( cd $${D} && make clean; rm -f Makefile.old ); \
32+
done

t5-xs/ReturnArray.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ReturnArray;
2+
3+
sub test
4+
{
5+
my @something = qw[ Hello World ];
6+
7+
return @something;
8+
}
9+

t5-xs/ReturnArray/Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Revision history for Perl extension ReturnArray.
2+
3+
0.01 Fri Aug 16 20:53:40 2013
4+
- original version; created by h2xs 1.23 with options
5+
--skip-ppport -An ReturnArray
6+

t5-xs/ReturnArray/MANIFEST

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Changes
2+
Makefile.PL
3+
MANIFEST
4+
README
5+
ReturnArray.xs
6+
t/ReturnArray.t
7+
lib/ReturnArray.pm

t5-xs/ReturnArray/Makefile.PL

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use 5.012002;
2+
use ExtUtils::MakeMaker;
3+
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
4+
# the contents of the Makefile that is written.
5+
WriteMakefile(
6+
NAME => 'ReturnArray',
7+
VERSION_FROM => 'lib/ReturnArray.pm', # finds $VERSION
8+
PREREQ_PM => {}, # e.g., Module::Name => 1.1
9+
($] >= 5.005 ? ## Add these new keywords supported since 5.005
10+
(ABSTRACT_FROM => 'lib/ReturnArray.pm', # retrieve abstract from module
11+
AUTHOR => 'A. U. Thor <simon@>') : ()),
12+
LIBS => [''], # e.g., '-lm'
13+
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
14+
# Insert -I. if you add *.h files later:
15+
INC => '', # e.g., '-I/usr/include/other'
16+
# Un-comment this if you add C files to link with later:
17+
# OBJECT => '$(O_FILES)', # link all the C files too
18+
);

t5-xs/ReturnArray/README

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ReturnArray version 0.01
2+
========================
3+
4+
The README is used to introduce the module and provide instructions on
5+
how to install the module, any machine dependencies it may have (for
6+
example C compilers and installed libraries) and any other information
7+
that should be provided before the module is installed.
8+
9+
A README file is required for CPAN modules since CPAN extracts the
10+
README file from a module distribution so that people browsing the
11+
archive can use it get an idea of the modules uses. It is usually a
12+
good idea to provide version information here so that people can
13+
decide whether fixes for the module are worth downloading.
14+
15+
INSTALLATION
16+
17+
To install this module type the following:
18+
19+
perl Makefile.PL
20+
make
21+
make test
22+
make install
23+
24+
DEPENDENCIES
25+
26+
This module requires these other modules and libraries:
27+
28+
blah blah blah
29+
30+
COPYRIGHT AND LICENCE
31+
32+
Put the correct copyright and licence information here.
33+
34+
Copyright (C) 2013 by A. U. Thor
35+
36+
This library is free software; you can redistribute it and/or modify
37+
it under the same terms as Perl itself, either Perl version 5.12.2 or,
38+
at your option, any later version of Perl 5 you may have available.
39+
40+

t5-xs/ReturnArray/ReturnArray.xs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* Do not edit this file - Generated by Perlito5 9.0 */
2+
#include "EXTERN.h"
3+
#include "perl.h"
4+
#include "XSUB.h"
5+
6+
MODULE = ReturnArray PACKAGE = ReturnArray
7+
void test ()
8+
PPCODE:
9+
SV *something = (newSVpv("Hello", 0), newSVpv("World", 0));
10+
PUSHs(something);
11+
12+
13+
14+

t5-xs/Some-Thing/lib/Some/Thing.pm renamed to t5-xs/ReturnArray/lib/ReturnArray.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Some::Thing;
1+
package ReturnArray;
22

33
use 5.012002;
44
use strict;
@@ -12,7 +12,7 @@ our @ISA = qw(Exporter);
1212
# names by default without a very good reason. Use EXPORT_OK instead.
1313
# Do not simply export all your public functions/methods/constants.
1414

15-
# This allows declaration use Some::Thing ':all';
15+
# This allows declaration use ReturnArray ':all';
1616
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
1717
# will save memory.
1818
our %EXPORT_TAGS = ( 'all' => [ qw(
@@ -28,7 +28,7 @@ our @EXPORT = qw(
2828
our $VERSION = '0.01';
2929

3030
require XSLoader;
31-
XSLoader::load('Some::Thing', $VERSION);
31+
XSLoader::load('ReturnArray', $VERSION);
3232

3333
# Preloaded methods go here.
3434

@@ -38,16 +38,16 @@ __END__
3838
3939
=head1 NAME
4040
41-
Some::Thing - Perl extension for blah blah blah
41+
ReturnArray - Perl extension for blah blah blah
4242
4343
=head1 SYNOPSIS
4444
45-
use Some::Thing;
45+
use ReturnArray;
4646
blah blah blah
4747
4848
=head1 DESCRIPTION
4949
50-
Stub documentation for Some::Thing, created by h2xs. It looks like the
50+
Stub documentation for ReturnArray, created by h2xs. It looks like the
5151
author of the extension was negligent enough to leave the stub
5252
unedited.
5353

t5-xs/ReturnArray/t/ReturnArray.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use Test::More tests => 3;
2+
BEGIN { use_ok('ReturnArray') }
3+
my @word = ReturnArray::test();
4+
is( $word[0], "Hello" );
5+
is( $word[1], "World" );

t5-xs/ReturnArrayRef.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ReturnArrayRef;
2+
3+
sub test
4+
{
5+
my $something = [qw[ Hello World ]];
6+
7+
return $something;
8+
}
9+

0 commit comments

Comments
 (0)