From 241c9b3071059b39fbd82c205f973c0f19c68cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Tue, 30 Oct 2018 19:12:58 -0400 Subject: [PATCH] t: allow running the suite from an arbitrary directory --- t/tags.t | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/t/tags.t b/t/tags.t index 8ff7ea0..1830d97 100644 --- a/t/tags.t +++ b/t/tags.t @@ -7,9 +7,13 @@ use utf8; use Test::More tests => 27; use Digest::MD5; +use File::Basename; use IPC::Open3; use Symbol 'gensym'; +my $t = dirname(__FILE__); +BAIL_OUT("'$t' contains unsupported characters") if $t !~ m|^[\w/]*$|; + sub md5 { my ($file) = @_; open(my $fh, '<', $file) or return; @@ -20,36 +24,36 @@ sub md5 { my $fh; -is(md5('t/gobble.opus'), '111a483596ac32352fbce4d14d16abd2', 'the sample is the one we expect'); -is(`./opustags t/gobble.opus`, <<'EOF', 'read the initial tags'); +is(md5("$t/gobble.opus"), '111a483596ac32352fbce4d14d16abd2', 'the sample is the one we expect'); +is(`./opustags $t/gobble.opus`, <<'EOF', 'read the initial tags'); encoder=Lavc58.18.100 libopus EOF # empty out.opus -open($fh, '> t/out.opus') or die; +open($fh, '>', "$t/out.opus") or die; close($fh); -is(`./opustags t/gobble.opus -o t/out.opus 2>&1 >/dev/null`, <<'EOF', 'refuse to override'); -'t/out.opus' already exists (use -y to overwrite) +is(`./opustags $t/gobble.opus -o $t/out.opus 2>&1 >/dev/null`, <<"EOF", 'refuse to override'); +'$t/out.opus' already exists (use -y to overwrite) EOF -is(md5('t/out.opus'), 'd41d8cd98f00b204e9800998ecf8427e', 'the output wasn\'t written'); +is(md5("$t/out.opus"), 'd41d8cd98f00b204e9800998ecf8427e', 'the output wasn\'t written'); is($?, 256, 'check the error code'); -is(`./opustags t/out.opus -o t/out.opus 2>&1 >/dev/null`, <<'EOF', 'output and input can\'t be the same'); +is(`./opustags $t/out.opus -o $t/out.opus 2>&1 >/dev/null`, <<'EOF', 'output and input can\'t be the same'); error: the input and output files are the same EOF is($?, 256, 'check the error code'); -unlink('t/out.opus'); -is(`./opustags t/gobble.opus -o t/out.opus 2>&1`, '', 'copy the file without changes'); -is(md5('t/out.opus'), '111a483596ac32352fbce4d14d16abd2', 'the copy is faithful'); +unlink("$t/out.opus"); +is(`./opustags $t/gobble.opus -o $t/out.opus 2>&1`, '', 'copy the file without changes'); +is(md5("$t/out.opus"), '111a483596ac32352fbce4d14d16abd2', 'the copy is faithful'); is($?, 0, 'check the error code'); -is(`./opustags --in-place t/out.opus -a A=B --add="A=C" --add "TITLE=Foo Bar" --delete A --add TITLE=七面鳥 --set encoder=whatever -s 1=2 -s X=1 -a X=2 -s X=3`, '', 'complex tag editing'); +is(`./opustags --in-place $t/out.opus -a A=B --add="A=C" --add "TITLE=Foo Bar" --delete A --add TITLE=七面鳥 --set encoder=whatever -s 1=2 -s X=1 -a X=2 -s X=3`, '', 'complex tag editing'); is($?, 0, 'updating the tags went well'); -is(md5('t/out.opus'), '66780307a6081523dc9040f3c47b0448', 'check the footprint'); +is(md5("$t/out.opus"), '66780307a6081523dc9040f3c47b0448', 'check the footprint'); $/ = undef; -open($fh, './opustags t/out.opus |'); +open($fh, "./opustags $t/out.opus |"); binmode($fh, ':utf8'); is(<$fh>, <<'EOF', 'check the tags written'); A=B @@ -64,34 +68,34 @@ X=3 EOF close($fh); -is(`./opustags t/out.opus -d A -d foo -s X=4 -a TITLE=gobble -d TITLE`, <<'EOF', 'dry editing'); +is(`./opustags $t/out.opus -d A -d foo -s X=4 -a TITLE=gobble -d TITLE`, <<'EOF', 'dry editing'); 1=2 encoder=whatever X=4 TITLE=gobble EOF -is(md5('t/out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); +is(md5("$t/out.opus"), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); -is(`./opustags -i t/out.opus -a fatal=yes -a FOO -a BAR 2>&1`, <<'EOF', 'bad tag with --add'); +is(`./opustags -i $t/out.opus -a fatal=yes -a FOO -a BAR 2>&1`, <<'EOF', 'bad tag with --add'); invalid comment: 'FOO' EOF is($?, 256, 'exited with a failure code'); -is(md5('t/out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); +is(md5("$t/out.opus"), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); -is(`./opustags -i t/out.opus -s fatal=yes -s FOO -s BAR 2>&1`, <<'EOF', 'bad tag with --set'); +is(`./opustags -i $t/out.opus -s fatal=yes -s FOO -s BAR 2>&1`, <<'EOF', 'bad tag with --set'); invalid comment: 'FOO' EOF is($?, 256, 'exited with a failure code'); -is(md5('t/out.opus'), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); +is(md5("$t/out.opus"), '66780307a6081523dc9040f3c47b0448', 'the file did not change'); -is(`./opustags t/out.opus --delete-all -a OK=yes`, <<'EOF', 'delete all'); +is(`./opustags $t/out.opus --delete-all -a OK=yes`, <<'EOF', 'delete all'); OK=yes EOF my ($pid, $pin, $pout, $perr); $perr = gensym; -$pid = open3($pin, $pout, $perr, './opustags t/out.opus --set-all -a A=B -s X=Z -d OK'); +$pid = open3($pin, $pout, $perr, "./opustags $t/out.opus --set-all -a A=B -s X=Z -d OK"); binmode($pin, ':utf8'); binmode($pout, ':utf8'); print $pin <<'EOF'; @@ -111,7 +115,7 @@ X=Z EOF waitpid($pid, 0); -$pid = open3($pin, $pout, $perr, './opustags t/out.opus --set-all'); +$pid = open3($pin, $pout, $perr, "./opustags $t/out.opus --set-all"); print $pin <<'EOF'; whatever @@ -131,4 +135,4 @@ EOF waitpid($pid, 0); is($?, 0, 'non fatal'); -unlink('t/out.opus'); +unlink("$t/out.opus");