[prev in list] [next in list] [prev in thread] [next in thread]
List: gentoo-dev
Subject: [gentoo-dev] [PATCH 2/2] eclass/tests/esed.sh: basic tests for esed.eclass
From: Ionen Wolkens <ionen () gentoo ! org>
Date: 2022-05-31 11:23:19
Message-ID: 20220531112319.29168-3-ionen () gentoo ! org
[Download RAW message or body]
Bit sloppy, but should pickup most regressions.
Signed-off-by: Ionen Wolkens <ionen@gentoo.org>
---
eclass/tests/esed.sh | 173 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 173 insertions(+)
create mode 100755 eclass/tests/esed.sh
diff --git a/eclass/tests/esed.sh b/eclass/tests/esed.sh
new file mode 100755
index 00000000000..fad1319ea13
--- /dev/null
+++ b/eclass/tests/esed.sh
@@ -0,0 +1,173 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+inherit esed
+
+cd "${WORKDIR:-/dev/null}" || exit 1
+
+tsddied=n
+tsddie() {
+ tsddied=y
+ echo "would die: $*" >&2
+ # silence further errors given didn't actually die
+ sed() { :; }
+ die() { :; }
+}
+
+tsdbegin() {
+ tbegin "${1}"
+ tsddied=n
+ unset -f sed
+ die() { tsddie "${@}"; }
+}
+
+tsdend() {
+ if [[ ${1} == fatal && ${tsddied} == n ]]; then
+ tend 127 "should have died"
+ elif [[ ${1} == nonfatal && ${tsddied} == y ]]; then
+ tend 128 "should not have died"
+ else
+ tend ${2:-0} "${3:-something went wrong(tm)}"
+ fi
+}
+
+tsdfile() {
+ local file
+ for file in "${@}"; do
+ if [[ ${file%:*} ]]; then
+ echo "${file%:*}" > "${file#*:}" || exit 1
+ elif [[ -e ${file#*:} ]]; then
+ rm -- "${file#*:}" || exit 1
+ fi
+ done
+}
+
+tsdcmp() {
+ local contents
+ contents=$(<"${1}") || exit 1
+ [[ ${contents} == "${2}" ]]
+}
+
+tsdbegin "esed: change on single file"
+tsdfile replace:file
+esed s/replace/new/ file
+tsdcmp file new
+tsdend nonfatal
+
+tsdbegin "esed: die due to no change on a single file"
+tsdfile keep:file
+esed s/replace/new/ file
+tsdcmp file keep
+tsdend fatal ${?}
+
+tsdbegin "esed: change on at least one of two files with ESED_VERBOSE=1"
+tsdfile keep:file1 replace:file2
+ESED_VERBOSE=1 esed s/replace/new/ file1 file2
+tsdcmp file1 keep &&
+ tsdcmp file2 new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to no change on two files with ESED_VERBOSE=1"
+tsdfile keep:file{1..2}
+ESED_VERBOSE=1 esed s/replace/new/ file1 file2
+tsdcmp file1 keep &&
+ tsdcmp file2 keep
+tsdend fatal ${?}
+
+tsdbegin "esed: change using esedexps"
+tsdfile replace1-replace2:file
+esedexps=(
+ s/replace1/new1/
+ s/replace2/new2/
+)
+esed file
+tsdcmp file new1-new2
+tsdend nonfatal ${?}
+
+tsdbegin "esed: don't call sed with empty esedexps"
+tsdfile keep:file
+esedexps=( '' )
+esed file
+[[ ! -v esedexps ]]
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to passing -i"
+esed -i s/replace/new/
+tsdend fatal
+
+tsdbegin "esed: change files with one nicely named '-- -i' using esedexp extended regex"
+tsdfile replace:"-- -i" replace:file
+esedexps=(
+ 's/(replace)/\1-new/'
+)
+esed -E file -- "-- -i"
+tsdcmp file replace-new &&
+ tsdcmp "-- -i" replace-new
+tsdend nonfatal ${?}
+
+tsdbegin "esed: die due to no files found"
+esed s/replace/new/
+tsdend fatal
+
+tsdbegin "esed: die due to invalid sed use"
+tsdfile keep:file
+esed s/replace/new file
+tsdend fatal
+
+tsdbegin "enewsed: change on a new file"
+tsdfile replace:file :newfile
+enewsed s/replace/new/ file newfile
+tsdcmp file replace &&
+ tsdcmp newfile new
+tsdend nonfatal ${?}
+
+tsdbegin "enewsed: die due to no changes on a newfile"
+tsdfile keep:file :newfile
+enewsed s/replace/new/ file newfile
+tsdcmp file keep &&
+ tsdcmp newfile keep
+tsdend fatal ${?}
+
+tsdbegin "enewsed: concatenating changed files to a newfile"
+tsdfile keep:file1 replace:file2
+enewsed s/replace/new/ file1 file2 newfile
+tsdcmp file1 keep &&
+ tsdcmp file2 replace &&
+ tsdcmp newfile $'keep\nnew'
+tsdend nonfatal ${?}
+
+tsdbegin "enewsed: script-file not being concatenated"
+tsdfile 's/missing/new/':script keep:file :newfile
+enewsed file -f script newfile
+tsdcmp script 's/missing/new/' &&
+ tsdcmp file keep &&
+ tsdcmp newfile keep
+tsdend fatal ${?}
+
+tsdbegin "esedfind: change found files"
+tsdfile keep:file1.find replace:file2.find
+esedfind . -type f -name '*.find' -esed s/replace/new/
+tsdcmp file1.find keep &&
+ tsdcmp file2.find new
+tsdend nonfatal ${?}
+
+tsdbegin "esedfind: die due to no files found"
+esedfind . -type f -name '*.missing' -esed s/replace/new/
+tsdend fatal
+
+tsdbegin "esedfind: die due to no changes from one esedexps without -esed"
+tsdfile keep:file1.find2 replace:file2.find2
+esedexps=(
+ s/replace/new/
+ s/missing/new/
+)
+esedfind . -type f -name '*.find2'
+tsdcmp file1.find2 keep &&
+ tsdcmp file2.find2 new
+tsdend fatal ${?}
+
+texit
--
2.35.1
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic