From bbccb5f1d90bf9605fc8473cb9f01bc453a82bf9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Nov 2023 09:35:34 +0000 Subject: io: introduce write_file helper sub This is pretty convenient way to create files for diff generation in both WWW and lei. The test suite should also be able to take advantage of it. --- t/io.t | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 t/io.t (limited to 't') diff --git a/t/io.t b/t/io.t new file mode 100644 index 00000000..4c7a97a3 --- /dev/null +++ b/t/io.t @@ -0,0 +1,33 @@ +#!perl -w +# Copyright (C) all contributors +# License: AGPL-3.0+ +use v5.12; +use PublicInbox::TestCommon; +my $tmpdir = tmpdir; +use_ok 'PublicInbox::IO'; +use PublicInbox::Spawn qw(which run_qx); + +# only test failures +SKIP: { +skip 'linux only test' if $^O ne 'linux'; +my $strace = which('strace') or skip 'strace missing for test'; +my $v = run_qx([$strace, '--version']); +$v =~ m!version\s+([1-9]+\.[0-9]+)! or xbail "no strace --version: $v"; +$v = eval("v$1"); +$v ge v4.16 or skip "$strace too old for syscall injection (". + sprintf('v%vd', $v). ' < v4.16)'; +my $env = { PERL5LIB => join(':', @INC) }; +my $opt = { 1 => \my $out, 2 => \my $err }; +my $dst = "$tmpdir/dst"; +my $tr = "$tmpdir/tr"; +my $cmd = [ $strace, "-o$tr", "-P$dst", + '-e', 'inject=writev,write:error=EIO', + $^X, qw(-w -MPublicInbox::IO=write_file -e), + q[write_file '>', $ARGV[0], 'hello world'], $dst ]; +xsys($cmd, $env, $opt); +isnt($?, 0, 'write failed'); +like($err, qr/\bclose\b/, 'close error noted'); +is(-s $dst, 0, 'file created and empty after EIO'); +} # /SKIP + +done_testing; -- cgit v1.2.3-24-ge0c7