Adapt testcase from Doug Maceachern <dougm@covalent.net> for perlio_destruct
Nick Ing-Simmons [Sun, 28 Oct 2001 09:36:20 +0000 (09:36 +0000)]
bug as lib/ExtUtils/Embed.t which tests that and some aspects of
ExtUtils::Embed.

p4raw-id: //depot/perlio@12729

MANIFEST
lib/ExtUtils/Embed.t [new file with mode: 0644]

index 99e6773..66e32b6 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -893,6 +893,7 @@ lib/ExtUtils/Command.pm             Utilities for Make on non-UNIX platforms
 lib/ExtUtils/Command.t         See if ExtUtils::Command works (Win32 only)
 lib/ExtUtils/Constant.pm       generate XS code to import C header constants
 lib/ExtUtils/Embed.pm          Utilities for embedding Perl in C programs
+lib/ExtUtils/Embed.t           See if ExtUtils::Embed and embedding works
 lib/ExtUtils/inst              Give information about installed extensions
 lib/ExtUtils/Install.pm                Handles 'make install' on extensions
 lib/ExtUtils/Installed.pm      Information on installed extensions
diff --git a/lib/ExtUtils/Embed.t b/lib/ExtUtils/Embed.t
new file mode 100644 (file)
index 0000000..618fb9c
--- /dev/null
@@ -0,0 +1,73 @@
+#!./perl
+
+BEGIN {
+    chdir 't' if -d 't';
+    unshift @INC, '../lib';
+}
+use Config;
+use ExtUtils::Embed;
+
+open(my $fh,">embed_test.c") || die "Cannot open embed_test.c:$!";
+print $fh <DATA>;
+close($fh);
+
+$| = 1;
+print "1..9\n";
+my @cmd = ($Config{'cc'},-o => 'embed_test',"-I$INC[0]/..",
+           ccopts(),
+           'embed_test.c',"-L$INC[0]/..",'-lperl',ldopts()
+           );
+#print "#@cmd\n";
+print "not " if system(join(' ',@cmd));
+print "ok 1\n";
+print "not " if system("embed_test");
+print "ok 9\n";
+unlink("embed_test","embed_test.c");
+
+#gcc -g -I.. -L../ -o perl_test perl_test.c -lperl `../perl -I../lib -MExtUtils::Embed -I../ -e ccopts -e ldopts`
+
+__END__
+
+/* perl_test.c */
+
+#include <EXTERN.h>
+#include <perl.h>
+
+#define my_puts(a) if(puts(a) < 0) exit(666)
+
+char *cmds[] = { "perl","-e", "print qq[ok 5\\n]", NULL };
+
+int main(int argc, char **argv, char **env)
+{
+    PerlInterpreter *my_perl = perl_alloc();
+
+    my_puts("ok 2");
+
+    perl_construct(my_perl);
+
+    my_puts("ok 3");
+
+    perl_parse(my_perl, NULL, (sizeof(cmds)/sizeof(char *))-1, cmds, env);
+
+    my_puts("ok 4");
+
+    fflush(stdout);
+
+    perl_run(my_perl);
+
+    my_puts("ok 6");
+
+    perl_destruct(my_perl);
+
+    my_puts("ok 7");
+
+    perl_free(my_perl);
+
+    my_puts("ok 8");
+
+    return 0;
+}
+
+
+
+