From 78a45fbb030cdee544ad72de21ddb5ce51366300 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Tue, 22 Jan 2013 10:16:07 -0700 Subject: [PATCH] add example that compiles an executable with cbuilder --- examples/01-compile.t | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/01-compile.t diff --git a/examples/01-compile.t b/examples/01-compile.t new file mode 100644 index 0000000..ffde85d --- /dev/null +++ b/examples/01-compile.t @@ -0,0 +1,61 @@ +#!perl + +# This test may be performed after the installation of Alien::ZMQ, e.g.: +# prove examples/01-compile.t + +use warnings; +use strict; + +BEGIN { + require ExtUtils::CBuilder; + unless (ExtUtils::CBuilder->new->have_compiler) { + require Test::More; + Test::More::plan(skip_all => "these tests require a working compiler"); + } +} + +use Alien::ZMQ; +use Test::More tests => 5; +use version; + +my $cb = ExtUtils::CBuilder->new; + +my $src = "test-$$.c"; +open my $SRC, '>', $src; +print $SRC < +#include +int main(int argc, char* argv[]) { + int major, minor, patch; + zmq_version(&major, &minor, &patch); + printf("%d.%d.%d %d.%d.%d", + ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH, + major, minor, patch); + return 0; +} +END +close $SRC; + +my $obj = eval { + $cb->compile(source => $src, extra_compiler_flags => Alien::ZMQ::cflags); +}; +unlink $src; +ok($obj, "compile C code"); +BAIL_OUT("compile failed") unless $obj; + +my $exe = eval { + $cb->link_executable(objects => $obj, extra_linker_flags => Alien::ZMQ::libs); +}; +unlink $obj; +ok($exe, "link object"); +BAIL_OUT("link failed") unless $exe; + +$ENV{LD_LIBRARY_PATH} = Alien::ZMQ::lib_dir; +my $out = `./$exe`; +ok($out, "run executable"); +unlink $exe; +my ($inc_version, $lib_version) = $out =~ /(\d\.\d\.\d) (\d\.\d\.\d)/; + +ok(version->parse($inc_version) == Alien::ZMQ::inc_version, "include versions are equal"); +ok(version->parse($lib_version) == Alien::ZMQ::lib_version, "library versions are equal"); + -- 2.45.2