summaryrefslogtreecommitdiff
blob: cac03e0401ba81487841f9825194f0c97c19f4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8
source tests-common.sh || exit

inherit edo

make_some_noise() {
	echo "Here is some noise:"
	echo "${1:?Must provide some noise}"
	echo "EoN"
}

test_edob_simple() {
	tbegin "edob with output test"
	(
		edob make_some_noise foo
		eend $?
	) &> "${T}/edob.out"
	local res=$?
	if [[ $res -ne 0 ]]; then
		tend $res
		return 0
	fi

	local log_file="${T}/make_some_noise.log"
	local second_line="$(sed -n '2p' "${log_file}")"
    [[ "${second_line}" == "foo" ]];
	tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""

	rm "${log_file}" || die
}

test_edob_explicit_log_name() {
	tbegin "edob with explicit logfile name"
	(
		edob -l mylog make_some_noise bar
		eend $?
	) &> "${T}/edob.out"
	local res=$?
	if [[ $res -ne 0 ]]; then
		cat "${T}/edob.out"
		tend $res
		return 0
	fi

	local log_file="${T}/mylog.log"
	local second_line="$(sed -n '2p' "${log_file}")"
    [[ "${second_line}" == "bar" ]];
	tend $? "Unexpected output, found \"${second_line}\", expected \"foo\""

	rm "${log_file}" || die
}

test_edob_explicit_message() {
	tbegin "edob with explicit message"
	(
		edob -m "Making some noise" make_some_noise baz
		eend $?
	) &> "${T}/edob.out"
	local res=$?
	if [[ $res -ne 0 ]]; then
		cat "${T}/edob.out"
		tend $res
		return 0
	fi

	local log_file="${T}/make_some_noise.log"
	local second_line="$(sed -n '2p' "${log_file}")"
    [[ "${second_line}" == "baz" ]];
	tend $? "Unexpected output, found \"${second_line}\", expected \"baz\""

	rm "${log_file}" || die
}

test_edob_failure() {
	make_some_noise_and_fail() {
		make_some_noise "$@"
		return 1
	}

	tbegin "edob with failing command"
	(
		edob -m "Making some noise" make_some_noise_and_fail quz
		eend $?
	) &> "${T}/edob.out"
	local res=$?
	# Now, this time we expect res to be exactly '1'.
	if [[ $res -ne 1 ]]; then
		tend 1
		return 1
	fi

	local log_file="${T}/make_some_noise_and_fail.log"
	local second_line="$(sed -n '2p' "${log_file}")"
    [[ "${second_line}" == "quz" ]];
	tend $? "Unexpected output, found \"${second_line}\", expected \"quz\""

	rm "${log_file}" || die

	local fourth_line_of_edob_out="$(sed -n '4p' "${T}/edob.out")"
	[[ "${fourth_line_of_edob_out}" == "quz" ]];
	tend $? "Unexpected output, found \"${fourth_line_of_edob_out}\", expected \"quz\""
}

test_edob_simple
test_edob_explicit_log_name
test_edob_explicit_message
test_edob_failure

texit