view release on metacpan or search on metacpan
t/1078-replace_all.t view on Meta::CPAN
# Multiple occurrences
is(replace_all("aaa", "a", "bb"), "bbbbbb", "multiple single char");
is(replace_all("the the the", "the", "a"), "a a a", "multiple words");
# Non-overlapping
is(replace_all("aaaa", "aa", "X"), "XX", "non-overlapping aa in aaaa");
# Real-world examples
is(replace_all("Hello, World!", ", ", " - "), "Hello - World!", "comma to dash");
is(replace_all("/path/to/file", "/", "\\"), "\\path\\to\\file", "unix to windows path");
# Longer strings
my $str = "the quick brown fox jumps over the lazy dog";
is(replace_all($str, "the", "THE"), "THE quick brown fox jumps over THE lazy dog", "case replacement");
is(replace_all($str, " ", "_"), "the_quick_brown_fox_jumps_over_the_lazy_dog", "spaces to underscores");
done_testing;
t/8006-file-platform.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir);
use Config;
use_ok('file');
my $tmpdir = tempdir(CLEANUP => 1);
my $is_windows = $^O eq 'MSWin32';
my $is_unix = !$is_windows;
diag("Running on: $^O");
diag("Perl version: $]");
# ============================================
# Platform detection
# ============================================
subtest 'platform identification' => sub {
ok(defined $^O, 'OS is defined');
t/8006-file-platform.t view on Meta::CPAN
SKIP: {
skip "Windows path tests", 2 unless $is_windows;
# Windows should also handle backslashes
is(file::basename('C:\\path\\to\\file.txt'), 'file.txt', 'basename with backslashes');
is(file::dirname('C:\\path\\to\\file.txt'), 'C:\\path\\to', 'dirname with backslashes');
}
};
# ============================================
# Symlink tests (Unix only)
# ============================================
SKIP: {
skip "Symlink tests require Unix", 6 unless $is_unix;
subtest 'symlinks' => sub {
my $target = "$tmpdir/symlink_target.txt";
my $link = "$tmpdir/symlink_link.txt";
file::spew($target, "target content");
SKIP: {
skip "symlink not available", 5 unless eval { symlink($target, $link) };
t/8006-file-platform.t view on Meta::CPAN
# Reading through symlink should work
is(file::slurp($link), "target content", 'can read through symlink');
# File tests on symlink
ok(file::is_file($link), 'symlink to file is_file');
}
};
}
# ============================================
# Permission tests (Unix only)
# ============================================
SKIP: {
skip "Permission tests require Unix", 1 unless $is_unix;
subtest 'unix permissions' => sub {
my $file = "$tmpdir/perm_test.txt";
file::spew($file, "permission test");
# Test chmod
ok(file::chmod($file, 0644), 'chmod 0644');
my $mode = file::mode($file);
is($mode & 0777, 0644, 'mode is 0644');
ok(file::chmod($file, 0755), 'chmod 0755');
$mode = file::mode($file);
t/8006-file-platform.t view on Meta::CPAN
# ============================================
subtest 'case sensitivity' => sub {
my $lower = "$tmpdir/casefile.txt";
my $upper = "$tmpdir/CaseFile.txt";
file::spew($lower, "lowercase");
SKIP: {
# On case-insensitive systems (macOS default, Windows), these are same file
skip "Case-insensitive filesystem", 2 if file::exists($upper) && !$is_unix;
# On case-sensitive systems, these are different files
if (!file::exists($upper)) {
file::spew($upper, "UPPERCASE");
ok(file::exists($lower), 'lowercase file exists');
ok(file::exists($upper), 'uppercase file exists');
isnt(file::slurp($lower), file::slurp($upper), 'different content');
}
}
pass('case sensitivity test completed');
};
# ============================================
# Line ending handling
# ============================================
subtest 'line endings' => sub {
my $unix_file = "$tmpdir/unix_lines.txt";
my $win_file = "$tmpdir/win_lines.txt";
my $mac_file = "$tmpdir/mac_lines.txt";
# Unix: \n
file::spew($unix_file, "line1\nline2\nline3");
my $unix_lines = file::lines($unix_file);
is(scalar(@$unix_lines), 3, 'unix line count');
is($unix_lines->[0], 'line1', 'unix line 1');
# Windows: \r\n (note: file module splits on \n only)
file::spew($win_file, "line1\r\nline2\r\nline3");
my $win_lines = file::lines($win_file);
is(scalar(@$win_lines), 3, 'windows line count');
# Lines will have \r at end
like($win_lines->[0], qr/^line1/, 'windows line 1 starts correctly');
# Old Mac: \r only
file::spew($mac_file, "line1\rline2\rline3");
t/8006-file-platform.t view on Meta::CPAN
skip "Large file test slow", 1 unless $ENV{TEST_LARGE_FILES};
# Large file (10MB)
my $large = "$tmpdir/size_large.txt";
file::spew($large, "x" x (10 * 1024 * 1024));
is(file::size($large), 10 * 1024 * 1024, 'large file size');
}
};
# ============================================
# Special files (Unix only)
# ============================================
SKIP: {
skip "Special file tests require Unix", 1 unless $is_unix;
subtest 'special files' => sub {
# /dev/null
SKIP: {
skip "/dev/null not available", 3 unless -e '/dev/null';
ok(file::exists('/dev/null'), '/dev/null exists');
# Can write to /dev/null
ok(file::spew('/dev/null', "test"), 'can write to /dev/null');
# Size of /dev/null is 0
t/xs/file_api_test/Makefile.PL view on Meta::CPAN
use warnings;
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linking against file shared library
my $extra_libs = '';
my $extra_ldfrom = '';
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: link against file.so with $ORIGIN-relative rpath
$extra_libs = '-Wl,-rpath,\$ORIGIN/../file';
$extra_ldfrom = '../../../blib/arch/auto/file/file.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: link against file DLL
my $dll_ext = $Config{dlext} || 'dll';
$extra_ldfrom = "../../../blib/arch/auto/file/file.$dll_ext";
}
# macOS/darwin: no special linking needed (flat namespace makes symbols visible)
t/xs/nvec_api_test/Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linking against nvec shared library
# On non-macOS platforms, symbols from nvec aren't automatically visible
my $extra_libs = '';
my $extra_ldfrom = '';
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: link against nvec.so with $ORIGIN-relative rpath
# $ORIGIN means "directory of this .so file" - nvec.so is in ../nvec/
$extra_libs = '-Wl,-rpath,\$ORIGIN/../nvec';
$extra_ldfrom = '../../../blib/arch/auto/nvec/nvec.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: link against nvec DLL
my $dll_ext = $Config{dlext} || 'dll';
$extra_ldfrom = "../../../blib/arch/auto/nvec/nvec.$dll_ext";
}
# macOS/darwin: no special linking needed (flat namespace makes symbols visible)
t/xs/util_export_test/Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linking against util shared library
# On non-macOS platforms, symbols from util aren't automatically visible
my $extra_libs = '';
my $extra_ldfrom = '';
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: link against util.so with $ORIGIN-relative rpath
# $ORIGIN means "directory of this .so file" - util.so is in ../util/
$extra_libs = '-Wl,-rpath,\$ORIGIN/../util';
$extra_ldfrom = '../../../blib/arch/auto/util/util.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: link against util DLL
my $dll_ext = $Config{dlext} || 'dll';
$extra_ldfrom = "../../../blib/arch/auto/util/util.$dll_ext";
}
# macOS/darwin: no special linking needed (flat namespace makes symbols visible)
xs/file/Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linker flags for symbol export
# Other XS modules can use file hooks C API
my %platform_args;
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: export symbols and set SONAME
$platform_args{LDDLFLAGS} = $Config{lddlflags} . ' -Wl,--export-dynamic -Wl,-soname,file.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: export all symbols for DLL linking
$platform_args{LDDLFLAGS} = ($Config{lddlflags} || '') . ' -Wl,--export-all-symbols';
}
# macOS/darwin: no special flags needed (flat namespace exports symbols automatically)
WriteMakefile(
NAME => 'file',
xs/nvec/Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linker flags for symbol export
# nvec_api_test (and other XS modules) link against nvec to use the C API
my %platform_args;
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: export symbols and set SONAME
$platform_args{LDDLFLAGS} = $Config{lddlflags} . ' -Wl,--export-dynamic -Wl,-soname,nvec.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: export all symbols for DLL linking
$platform_args{LDDLFLAGS} = ($Config{lddlflags} || '') . ' -Wl,--export-all-symbols';
}
# macOS/darwin: no special flags needed (flat namespace exports symbols automatically)
WriteMakefile(
NAME => 'nvec',
xs/object/Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linker flags for symbol export
# Other XS modules can use object_types.h to register C-level type checks
my %platform_args;
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: export symbols and set SONAME
$platform_args{LDDLFLAGS} = $Config{lddlflags} . ' -Wl,--export-dynamic -Wl,-soname,object.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: export all symbols for DLL linking
$platform_args{LDDLFLAGS} = ($Config{lddlflags} || '') . ' -Wl,--export-all-symbols';
}
# macOS/darwin: no special flags needed (flat namespace exports symbols automatically)
WriteMakefile(
NAME => 'object',
xs/util/Makefile.PL view on Meta::CPAN
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Config;
# Platform-specific linker flags for symbol export
# Other XS modules can use util_callbacks.h to register C-level callbacks
my %platform_args;
if ($^O eq 'linux' || $^O eq 'freebsd' || $^O eq 'openbsd' || $^O eq 'netbsd' ||
$^O eq 'solaris' || $^O eq 'sunos' || $^O eq 'dragonfly') {
# Unix ELF systems: export symbols and set SONAME
$platform_args{LDDLFLAGS} = $Config{lddlflags} . ' -Wl,--export-dynamic -Wl,-soname,util.so';
}
elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') {
# Windows/Cygwin/MSYS: export all symbols for DLL linking
$platform_args{LDDLFLAGS} = ($Config{lddlflags} || '') . ' -Wl,--export-all-symbols';
}
# macOS/darwin: no special flags needed (flat namespace exports symbols automatically)
WriteMakefile(
NAME => 'util',
xt/c-compat.t view on Meta::CPAN
'hardcoded_sizes' => {
pattern => qr/\b(sizeof\s*\(\s*(int|long|void\s*\*)\s*\)\s*==\s*[48]|[48]\s*==\s*sizeof)/,
severity => 'warning',
message => 'Hardcoded type sizes are not portable across platforms',
},
# Platform-specific headers without guards
'unistd_without_guard' => {
pattern => qr/^#\s*include\s+<unistd\.h>/m,
severity => 'info',
message => '<unistd.h> is Unix-only - may need HAS_UNISTD guard',
negative_pattern => qr/#\s*if.*HAS_UNISTD|#\s*ifdef.*WIN32|#\s*ifndef.*_WIN32/,
},
# Windows-specific headers without guards
'windows_header_without_guard' => {
pattern => qr/^#\s*include\s+<windows\.h>/mi,
severity => 'info',
message => '<windows.h> is Windows-only - ensure proper guards',
negative_pattern => qr/#\s*if.*WIN32|#\s*ifdef.*_WIN32/,
},