]> gitweb.hhaalo.de Git - albentohandy.git/commitdiff
add mp3 check programs
authorBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 17:56:42 +0000 (19:56 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 25 Sep 2026 17:56:42 +0000 (19:56 +0200)
src/lib/mp3.sh [new file with mode: 0644]
tests/mp3.bats [new file with mode: 0755]

diff --git a/src/lib/mp3.sh b/src/lib/mp3.sh
new file mode 100644 (file)
index 0000000..b2e195e
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+vorbis_errlog()
+{
+       local lastexit=$?
+       local msg="$1"
+
+       echo "❌ ERROR: $msg"
+       return $lastexit
+}
+
+mp3_check_programs()
+{
+       command -v flac > /dev/null \
+               || vorbis_errlog "command flac not found" \
+               || return $?
+       command -v lame > /dev/null \
+               || vorbis_errlog "command lame not found" \
+               || return $?
+       command -v eyeD3 > /dev/null \
+               || vorbis_errlog "command eyeD3 not found" \
+               || return $?
+       command -v parallel > /dev/null \
+               || vorbis_errlog "command parallel not found" \
+               || return $?
+}
+
+mp3_check_programs || return $?
\ No newline at end of file
diff --git a/tests/mp3.bats b/tests/mp3.bats
new file mode 100755 (executable)
index 0000000..e5ab777
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/bats
+
+setup() {
+       bats_load_library 'bats-support'
+       bats_load_library 'bats-assert'
+       source "src/lib/mp3.sh"
+}
+
+# bats test_tags=mp3:check_programs
+@test "failed: check programs missing flac" {
+       command() {
+               [ "$2" != "flac" ] || return 1
+       }
+
+       run mp3_check_programs
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command flac not found"
+}
+
+# bats test_tags=mp3:check_programs
+@test "failed: check programs missing lame" {
+       command() {
+               [ "$2" != "lame" ] || return 1
+       }
+
+       run mp3_check_programs
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command lame not found"
+}
+
+# bats test_tags=mp3:check_programs
+@test "failed: check programs eyeD3 oggenc" {
+       command() {
+               [ "$2" != "eyeD3" ] || return 1
+       }
+
+       run mp3_check_programs
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command eyeD3 not found"
+}
+
+# bats test_tags=mp3:check_programs
+@test "failed: check programs missing parallel" {
+       command() {
+               [ "$2" != "parallel" ] || return 1
+       }
+
+       run mp3_check_programs
+
+       assert_failure
+       assert_line --index 0 "❌ ERROR: command parallel not found"
+}
\ No newline at end of file