X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fnodatacow.t;h=19247c109b0931b8340f4f75bc4d189bd5a5577a;hb=1411a6e0ca36d6eda89a2f2f4e937fec3cad2030;hp=87b6bdf72142a72a008e3366f301a1e30a0a517f;hpb=c106504309621b662ce6c7cd914718f7045edca4;p=public-inbox.git diff --git a/t/nodatacow.t b/t/nodatacow.t index 87b6bdf7..19247c10 100644 --- a/t/nodatacow.t +++ b/t/nodatacow.t @@ -1,11 +1,8 @@ #!perl -w -# Copyright (C) 2020 all contributors +# Copyright (C) 2020-2021 all contributors # License: AGPL-3.0+ -use strict; -use Test::More; -use File::Temp qw(tempfile); -use PublicInbox::TestCommon; -use PublicInbox::Spawn qw(which); +use strict; use v5.10.1; use PublicInbox::TestCommon; +use File::Temp 0.19; use_ok 'PublicInbox::NDC_PP'; SKIP: { @@ -13,22 +10,39 @@ SKIP: { skip 'test is Linux-only', $nr if $^O ne 'linux'; my $dir = $ENV{BTRFS_TESTDIR}; skip 'BTRFS_TESTDIR not defined', $nr unless defined $dir; - skip 'chattr(1) not installed', $nr unless which('chattr'); - my $lsattr = which('lsattr') or skip 'lsattr(1) not installed', $nr; - my ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1); - BAIL_OUT "tempfile: $!" unless $fh && defined($name); - my $pp_sub = \&PublicInbox::NDC_PP::set_nodatacow; + require_cmd('chattr', 1) or skip 'chattr(1) not installed', $nr; + my $lsattr = require_cmd('lsattr', 1) or + skip 'lsattr(1) not installed', $nr; + my $tmp = File::Temp->newdir('nodatacow-XXXX', DIR => $dir); + my $dn = $tmp->dirname; + + my $name = "$dn/pp.f"; + open my $fh, '>', $name or BAIL_OUT "open($name): $!"; + my $pp_sub = \&PublicInbox::NDC_PP::nodatacow_fd; $pp_sub->(fileno($fh)); my $res = xqx([$lsattr, $name]); - like($res, qr/C/, "`C' attribute set with pure Perl"); + like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with pure Perl"); + + $name = "$dn/pp.d"; + mkdir($name) or BAIL_OUT "mkdir($name) $!"; + PublicInbox::NDC_PP::nodatacow_dir($name); + $res = xqx([$lsattr, '-d', $name]); + like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with pure Perl"); - my $ic_sub = \&PublicInbox::Spawn::set_nodatacow; + $name = "$dn/ic.f"; + my $ic_sub = \&PublicInbox::Spawn::nodatacow_fd; $pp_sub == $ic_sub and - skip 'Inline::C or Linux kernel headers missing', 1; - ($fh, $name) = tempfile(DIR => $dir, UNLINK => 1); + skip 'Inline::C or Linux kernel headers missing', 2; + open $fh, '>', $name or BAIL_OUT "open($name): $!"; $ic_sub->(fileno($fh)); $res = xqx([$lsattr, $name]); - like($res, qr/C/, "`C' attribute set with Inline::C"); + like($res, qr/C.*\Q$name\E/, "`C' attribute set on fd with Inline::C"); + + $name = "$dn/ic.d"; + mkdir($name) or BAIL_OUT "mkdir($name) $!"; + PublicInbox::Spawn::nodatacow_dir($name); + $res = xqx([$lsattr, '-d', $name]); + like($res, qr/C.*\Q$name\E/, "`C' attribute set on dir with Inline::C"); }; done_testing;