From 359821f1bc3d201abceb6d095c17d54dc5293045 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 2 Jan 2018 17:36:50 +0000 Subject: make MusicFile work with non-absolute paths --- lib/Ultramarine/Model/MusicFile.pm6 | 3 ++- t/tests/model/music-file.t | 31 ++++++++++--------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/lib/Ultramarine/Model/MusicFile.pm6 b/lib/Ultramarine/Model/MusicFile.pm6 index 0370310..7c3ccd1 100644 --- a/lib/Ultramarine/Model/MusicFile.pm6 +++ b/lib/Ultramarine/Model/MusicFile.pm6 @@ -3,9 +3,10 @@ use JSON::Fast; class Ultramarine::Model::MusicFile { has $.path is required; + submethod BUILD(IO() :$!path!) {} method metadata() { - my $proc = run 'avprobe', '-show_format','-of', 'json', $.path, + my $proc = run 'avprobe', '-show_format','-of', 'json', $.path.absolute, :err,:out; CATCH { when X::Proc::Unsuccessful { return %() } } my $json-str = $proc.out.slurp(:close); diff --git a/t/tests/model/music-file.t b/t/tests/model/music-file.t index 2016f8e..845a88d 100644 --- a/t/tests/model/music-file.t +++ b/t/tests/model/music-file.t @@ -5,28 +5,17 @@ use Ultramarine::Model::MusicFile; # test file generated with: # avconv -ac 2 -ar 44100 -f s16le -i /dev/zero -t 1 -q 0 -metadata title="some title" -metadata artist="some artist" test.mp3 -my Ultramarine::Model::MusicFile $mf .= new(:path('t/data/test.mp3')); -my $data = $mf.metadata; +# this way we test that MusicFile passes a usable path to avprobe, not +# just the .Str +my $path = IO::Path.new('test.mp3',:CWD('t/data/')); +my Ultramarine::Model::MusicFile $mf .= new(:$path); +my %data = $mf.metadata; -is-deeply( - $data, - %( - :bit_rate("33633.000000"), - :duration("1.044898"), - :filename("t/data/test.mp3"), - :format_long_name("MP2/3 (MPEG audio layer 2/3)"), - :format_name("mp3"), - :nb_streams(1), - :size("4393.000000"), - :start_time("0.000000"), - :tags(%( - :artist("some artist"), - :encoder("Lavf56.1.0"), - :title("some title"), - )), - ), - 'metadata should match', -); +is-approx(%data.Num,33633,:1abs-tol,'bit rate should match'); +is-approx(%data.Num,1,:1abs-tol,'length should match'); +is(%data,'mp3','format should match'); +is(%data,'some artist','artist should match'); +is(%data,'some title','title should match'); done-testing; -- cgit v1.2.3