mpvd

Control mpv using the MPD protocol

git clone https://git.8pit.net/mpvd.git

 1#!/bin/sh
 2
 3cd "${0%/*}"
 4
 5export MPVD_TEST_ADDR="${MPVD_TEST_ADDR:-localhost}"
 6export MPVD_TEST_PORT="${MPVD_TEST_PORT:-6600}"
 7
 8mkdir -p "${testdir:=${TMPDIR:-/tmp}/mpvd-tests}"
 9trap 'rm -rf ${testdir} ; kill $(jobs -p) 2>/dev/null' INT EXIT
10
11for test in *; do
12	[ -e "${test}/commands" ] || continue
13	printf "Running test case '%s': " "${test##*/}"
14
15	read -r fn < "${test}/song"
16	sock="${testdir}/mpvsock"
17
18	mpv --quiet --input-ipc-server="${sock}" \
19		--pause --loop inf "testdata/${fn}" >/dev/null &
20	hy ../mpvd.hy -a "${MPVD_TEST_ADDR}" \
21		-p "${MPVD_TEST_PORT}" "${sock}" &
22
23	./wait_port.hy "${MPVD_TEST_ADDR}" "${MPVD_TEST_PORT}"
24
25	output="${testdir}/output"
26	env -i HOST="${MPVD_TEST_ADDR}" PORT="${MPVD_TEST_PORT}" \
27		PATH="$(pwd):${PATH}" sh "${test}/commands" > "${output}"
28
29	expected="${testdir}/expected"
30	sed "/./!d" < "${test}/output" > "${expected}"
31
32	if ! cmp -s "${output}" "${expected}"; then
33		printf "FAIL: Output didn't match.\n\n"
34		diff -u "${output}" "${expected}"
35		exit 1
36	fi
37
38	kill $(jobs -p); wait
39	printf "OK.\n"
40done