Test::A...nthetic(3)
β¨ NAME β¨
okay so bestie, welcome to Test::Alien::Synthetic β it's a mock alien object for testing, and honestly? it's giving fake-it-till-you-make-it in the best way πΈπ
The manual you're reading rn is the Test::A...nthetic(3) page from the User Contributed Perl Documentation collection, and it's gonna walk you through every single thing this lil class does. no skips, no skimming, we're doing this together π«Ά
π VERSION π
version 2.88
like. she's got a version. respect her. β
πΈ SYNOPSIS πΈ
here's the whole vibe in one sitting:
use Test2::V0;
use Test::Alien;
my $alien = synthetic {
cflags => '-I/foo/bar/include',
libs => '-L/foo/bar/lib -lbaz',
};
alien_ok $alien;
done_testing;
see how easy that was?? you just hand synthetic a hashref and boom, you got an alien π
π¦ DESCRIPTION π¦
This class is used to model a synthetic Alien class that implements the minimum Alien::Base interface needed by Test::Alien.
It can be useful if you have a non-Alien::Base based Alien distribution that you need to test. (iykyk β sometimes you inherit code and you just gotta test it, no judgement β¨)
NOTE: The name of this class may move in the future, so do not refer to this class name directly. Instead create instances of this class using the Test::Alien#synthetic function. bestie I'm begging you, don't hardcode the class name, she's not staying at this address forever π
π ATTRIBUTES π
every one of these, in order, no crumbs left behind:
π cflags
String containing the compiler flags
π cflags_static
String containing the static compiler flags
π libs
String containing the linker and library flags
π libs_static
String containing the static linker and library flags
π dynamic_libs
List reference containing the dynamic libraries.
π bin_dir
Tool binary directory.
π runtime_prop
Runtime properties.
π₯ EXAMPLE π₯
Here is a complete example using Alien::Libarchive which is a non-Alien::Base based Alien distribution. it's the whole main-character arc, start to finish π
use strict;
use warnings;
use Test2::V0;
use Test::Alien;
use Alien::Libarchive;
my $real = Alien::Libarchive->new;
my $alien = synthetic {
cflags => scalar $real->cflags,
libs => scalar $real->libs,
dynamic_libs => [$real->dlls],
};
alien_ok $alien;
xs_ok do { local $/; <DATA> }, with_subtest {
my($module) = @_;
my $ptr = $module->archive_read_new;
like $ptr, qr{^[0-9]+$};
$module->archive_read_free($ptr);
};
ffi_ok { symbols => [qw( archive_read_new )] }, with_subtest {
my($ffi) = @_;
my $new = $ffi->function(archive_read_new => [] => 'opaque');
my $free = $ffi->function(archive_read_close => ['opaque'] => 'void');
my $ptr = $new->();
like $ptr, qr{^[0-9]+$};
$free->($ptr);
};
done_testing;
__DATA__
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <archive.h>
MODULE = TA_MODULE PACKAGE = TA_MODULE
void *archive_read_new(class);
const char *class;
CODE:
RETVAL = (void*) archive_read_new();
OUTPUT:
RETVAL
void archive_read_free(class, ptr);
const char *class;
void *ptr;
CODE:
archive_read_free(ptr);
notice how we're pulling the real values out of a real Alien::Libarchive object and then feeding them into our fake one? that's the trick, that's the whole slay π§β¨
β SEE ALSO β
Test::Alienβ go read that one too, she's the reason any of this works π
π AUTHOR π
Author: Graham Ollis <plicease@cpan.org>
Contributors:
- Diab Jerius (DJERIUS)
- Roy Storey (KIWIROY)
- Ilya Pavlov
- David Mertens (run4flat)
- Mark Nunberg (mordy, mnunberg)
- Christian Walde (Mithaldu)
- Brian Wightman (MidLifeXis)
- Zaki Mughal (zmughal)
- mohawk (mohawk2, ETJ)
- Vikas N Kumar (vikasnkumar)
- Flavio Poletti (polettix)
- Salvador FandiΓ±o (salva)
- Gianni Ceccarelli (dakkar)
- Pavel Shaydo (zwon, trinitum)
- Kang-min Liu (εεΊ·ζ°, gugod)
- Nicholas Shipp (nshp)
- Juan JuliΓ‘n Merelo GuervΓ³s (JJ)
- Joel Berger (JBERGER)
- Petr PΓsaΕ (ppisar)
- Lance Wicks (LANCEW)
- Ahmad Fatoum (a3f, ATHREEF)
- JosΓ© JoaquΓn Atria (JJATRIA)
- Duke Leto (LETO)
- Shoichi Kaji (SKAJI)
- Shawn Laffan (SLAFFAN)
- Paul Evans (leonerd, PEVANS)
- HΓ₯kon HΓ¦gland (hakonhagland, HAKONH)
- nick nauwelaerts (INPHOBIA)
- Florian Weimer
- Marcel Telka (mtelka)
that's a whole squad and every single one of them ate π π₯
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2011-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie!! this one shipped with perl v5.42.3 and it's dated 2026-09-21, so if you're reading it somewhere in the future, hi, hope your tests pass, mwah π«Άπβ¨
π¦ where this page comes from
- fedora 43: perl-Alien-Build 2.88-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-Alien-Build 2.88-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms