diff options
author | Eric Wong <e@80x24.org> | 2023-11-02 09:35:34 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-11-03 06:39:30 +0000 |
commit | bbccb5f1d90bf9605fc8473cb9f01bc453a82bf9 (patch) | |
tree | bcaab4c47b6ebf6bfbb99332a5906ce36b680925 /t | |
parent | cfe25e6aa966144a9c96d1ba2c301fd5e1bad79b (diff) | |
download | public-inbox-bbccb5f1d90bf9605fc8473cb9f01bc453a82bf9.tar.gz |
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.
Diffstat (limited to 't')
-rw-r--r-- | t/io.t | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -0,0 +1,33 @@ +#!perl -w +# Copyright (C) all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +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; |