Skip to content

Commit

Permalink
Add approval tests
Browse files Browse the repository at this point in the history
mp3chop is so old that it didn't have very good tests. In the absence of
exhaustive tests, let's add a few approval tests. The expected output
files were generated using an older version of mp3chop and can be used
to show that the behaviour hasn't changed.

When we pass the mp3chop executable to our test script it is not passed
as a full path (see mesonbuild/meson#2681 )
and the current directory won't be in our path so we need to take
special action to ensure that we can run it.
  • Loading branch information
mikecrowe committed Apr 5, 2020
1 parent 32eafa5 commit 5981596
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 3 deletions.
Binary file added approval-tests/beginning.expected
Binary file not shown.
Binary file added approval-tests/cbr-jstereo-32-48000.mp3
Binary file not shown.
Binary file added approval-tests/end.expected
Binary file not shown.
Binary file added approval-tests/leading-zeros.expected
Binary file not shown.
3 changes: 3 additions & 0 deletions approval-tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
approval_tests_script = find_program('run')
test('approval-tests', approval_tests_script,
args: [ meson.current_source_dir(), meson.current_build_dir(), mp3chop_exe ])
Binary file added approval-tests/middle.expected
Binary file not shown.
Empty file.
Binary file added approval-tests/pass-through.expected
Binary file not shown.
54 changes: 54 additions & 0 deletions approval-tests/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
set -e

src="$1"
tmp="$2"
exe="$3"

# Meson will pass a relative path. We must convert it to an absolute
# path before we change directory.
mp3chop=$(realpath ${exe})

[ -z "${src}" ] || cd "${src}"
[ -n "${tmp}" ] || tmp=tmp
[ -n "${mp3chop}" ] || mp3chop=mp3chop

pass=0
count=0
check() {
name="$1"
input="$2"
expected="${name}.expected"
shift
shift
count=$((${count}+1))
echo "TEST ${name} using ${mp3chop}" 1>&2
${mp3chop} "$@" < "${input}" > "${tmp}/${name}.out"
if cmp "${expected}" "${tmp}/${name}.out"; then
echo "PASS" 1>&2
rm "${tmp}/${name}.out"
pass=$((${pass}+1))
else
echo "FAIL" 1>&2
fi
echo 1>&2
}

check pass-through cbr-jstereo-32-48000.mp3

check strip-id3v1 cbr-jstereo-32-48000.mp3 --strip-id3=1
check strip-id3v2 cbr-jstereo-32-48000.mp3 --strip-id3=2
check strip-id3 cbr-jstereo-32-48000.mp3 --strip-id3=1 --strip-id3=2

dd if=/dev/zero of=${tmp}/1Mzero bs=1024 count=1024
check no-frames ${tmp}/1Mzero

cat ${tmp}/1Mzero cbr-jstereo-32-48000.mp3 > ${tmp}/leading-zeros.mp3
cat cbr-jstereo-32-48000.mp3 ${tmp}/1Mzero > ${tmp}/trailing-zeros.mp3

check leading-zeros ${tmp}/leading-zeros.mp3
check trailing-zeros ${tmp}/trailing-zeros.mp3

check beginning cbr-jstereo-32-48000.mp3 --end=20:0.0
check end cbr-jstereo-32-48000.mp3 --begin=10:0.0
check middle cbr-jstereo-32-48000.mp3 --begin=5:0.0 --end=25:0.0
Binary file added approval-tests/strip-id3.expected
Binary file not shown.
Binary file added approval-tests/strip-id3v1.expected
Binary file not shown.
Binary file added approval-tests/strip-id3v2.expected
Binary file not shown.
Binary file added approval-tests/trailing-zeros.expected
Binary file not shown.
8 changes: 5 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ sources = [ 'header.cpp',

libchop = static_library('chop', sources)

executable('mp3chop', 'main.cpp',
link_with: libchop,
install: true)
mp3chop_exe = executable('mp3chop', 'main.cpp',
link_with: libchop,
install: true)

catch2 = subproject('catch2', required: false)
if catch2.found()
Expand All @@ -67,4 +67,6 @@ if catch2.found()
test('output_buffer_test', output_buffer_test)
endif

subdir('approval-tests')

install_man('mp3chop.1')

0 comments on commit 5981596

Please sign in to comment.