summaryrefslogtreecommitdiff
blob: c4a3ce824fdc18c6bf55bf7d4208a7207cd19ffe (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
#!/bin/bash
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

source tests-common.sh

inherit savedconfig

quiet() {
	local out ret
	out=$("$@" 2>&1)
	ret=$?
	[[ ${ret} -eq 0 ]] || echo "${out}"
	return ${ret}
}
sc() { EBUILD_PHASE=install quiet save_config "$@" ; }
rc() { EBUILD_PHASE=prepare quiet restore_config "$@" ; }

cleanup() { rm -rf "${ED}"/* "${T}"/* "${WORKDIR}"/* ; }
test-it() {
	local ret=0
	tbegin "$@"
	mkdir -p "${ED}"/etc/portage/savedconfig
	: $(( ret |= $? ))
	pushd "${WORKDIR}" >/dev/null
	: $(( ret |= $? ))
	test
	: $(( ret |= $? ))
	popd >/dev/null
	: $(( ret |= $? ))
	tend ${ret}
	cleanup
}

test() {
	touch f || return 1
	sc f || return 1
	[[ -f ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "simple save_config"

test() {
	touch a b c || return 1
	sc a b c || return 1
	[[ -d ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "multi save_config"

test() {
	mkdir dir || return 1
	touch dir/{a,b,c} || return 1
	sc dir || return 1
	[[ -d ${ED}/etc/portage/savedconfig/${CATEGORY}/${PF} ]]
}
test-it "dir save_config"

PORTAGE_CONFIGROOT=${D}

test() {
	echo "ggg" > f || return 1
	rc f || return 1
	[[ $(<f) == "ggg" ]]
}
test-it "simple restore_config"

test() {
	echo "ggg" > f || return 1
	rc f || return 1
	[[ $(<f) == "ggg" ]] || return 1
	sc f || return 1

	echo "hhh" > f || return 1
	rc f || return 1
	[[ $(<f) == "ggg" ]]
}
test-it "simple restore+save config"

texit