Gentoo Archives: gentoo-dev

From: Mike Gilbert <floppym@g.o>
To: gentoo-dev@l.g.o
Cc: Mike Gilbert <floppym@g.o>
Subject: [gentoo-dev] [PATCH 3/3] eclass/tests: add systemd tests
Date: Mon, 10 Oct 2022 15:35:05
Message-Id: 20221010153355.197970-4-floppym@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/3] systemd.eclass improvements by Mike Gilbert
1 Signed-off-by: Mike Gilbert <floppym@g.o>
2 ---
3 eclass/tests/systemd.sh | 50 +++++++++++++++++++++++++++++++++++++++++
4 1 file changed, 50 insertions(+)
5 create mode 100755 eclass/tests/systemd.sh
6
7 diff --git a/eclass/tests/systemd.sh b/eclass/tests/systemd.sh
8 new file mode 100755
9 index 00000000000..f870df4b7a1
10 --- /dev/null
11 +++ b/eclass/tests/systemd.sh
12 @@ -0,0 +1,50 @@
13 +#!/usr/bin/env bash
14 +# Copyright 2022 Gentoo Authors
15 +# Distributed under the terms of the GNU General Public License v2
16 +
17 +EAPI=8
18 +source tests-common.sh || exit
19 +
20 +inherit systemd
21 +
22 +test_system_dir() {
23 + local exp1="${EPREFIX}$1"
24 + local exp2="${EPREFIX}/usr$1"
25 + shift
26 + tbegin "$@"
27 + local act=$("$@")
28 + [[ ${act} == ${exp1} || ${act} == ${exp2} ]]
29 + tend $?
30 +}
31 +
32 +test_user_dir() {
33 + local exp="${EPREFIX}$1"
34 + shift
35 + tbegin "$@"
36 + local act=$("$@")
37 + [[ ${act} == ${exp} ]]
38 + tend $?
39 +}
40 +
41 +test_systemd_unprefix() {
42 + local exp=$1
43 + local EPREFIX=$2
44 + shift 2
45 + tbegin "EPREFIX=${EPREFIX} _systemd_unprefix $@"
46 + [[ "$(_systemd_unprefix "$@")" == "${exp}" ]]
47 + tend $?
48 +}
49 +
50 +test_system_dir /lib/systemd/system systemd_get_systemunitdir
51 +test_system_dir /lib/systemd systemd_get_utildir
52 +test_system_dir /lib/systemd/system-generators systemd_get_systemgeneratordir
53 +test_system_dir /lib/systemd/system-preset systemd_get_systempresetdir
54 +test_system_dir /lib/systemd/system-sleep systemd_get_sleepdir
55 +
56 +test_user_dir /usr/lib/systemd/user systemd_get_userunitdir
57 +
58 +test_systemd_unprefix /lib/systemd /prefix echo /prefix/lib/systemd
59 +test_systemd_unprefix /lib/systemd '' echo /lib/systemd
60 +test_systemd_unprefix /lib/systemd '/*' echo '/*/lib/systemd'
61 +
62 +texit
63 --
64 2.37.3