public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt*
@ 2017-03-24 21:01 Michał Górny
  2017-03-24 21:01 ` [gentoo-dev] [PATCH 2/2] estack.eclass: Use 'shopt -p -o' to restore 'set' flags Michał Górny
  2017-04-14 16:31 ` [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny
  0 siblings, 2 replies; 3+ messages in thread
From: Michał Górny @ 2017-03-24 21:01 UTC (permalink / raw)
  To: gentoo-dev; +Cc: base-system, Michał Górny

---
 eclass/tests/estack_eshopts.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/eclass/tests/estack_eshopts.sh b/eclass/tests/estack_eshopts.sh
index 606a17cfb053..28346c65ec13 100755
--- a/eclass/tests/estack_eshopts.sh
+++ b/eclass/tests/estack_eshopts.sh
@@ -27,6 +27,29 @@ for arg in nullglob dotglob extglob ; do
 	done
 done
 
+# test 'set' options
+set -f
+tbegin "set +f"
+s0=$-
+t eshopts_push +f
+s1=$-
+t eshopts_pop
+s2=$-
+[[ ${s0} == "${s2}" ]] &&
+[[ ${s1} != *f* ]]
+tend $?
+
+set +f
+tbegin "set -f"
+s0=$-
+t eshopts_push -f
+s1=$-
+t eshopts_pop
+s2=$-
+[[ ${s0} == "${s2}" ]] &&
+[[ ${s1} == *f* ]]
+tend $?
+
 tbegin "multi push/pop"
 s0=$(shopt -p)
 t eshopts_push -s dotglob
-- 
2.12.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH 2/2] estack.eclass: Use 'shopt -p -o' to restore 'set' flags
  2017-03-24 21:01 [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny
@ 2017-03-24 21:01 ` Michał Górny
  2017-04-14 16:31 ` [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Górny @ 2017-03-24 21:01 UTC (permalink / raw)
  To: gentoo-dev; +Cc: base-system, Michał Górny

Use 'shopt -p -o' to obtain the current set of 'set' flags, and to
restore them on popping. Unlike $-, it is output in command form (alike
'shopt -p'), removing the need for separate logic in eshopts_pop.
---
 eclass/estack.eclass | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/eclass/estack.eclass b/eclass/estack.eclass
index 19c388f3d8d2..f548abf8c283 100644
--- a/eclass/estack.eclass
+++ b/eclass/estack.eclass
@@ -158,7 +158,7 @@ eshopts_push() {
 		[[ $# -eq 0 ]] && return 0
 		shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
 	else
-		estack_push eshopts $-
+		estack_push eshopts "$(shopt -p -o)"
 		[[ $# -eq 0 ]] && return 0
 		set "$@" || die "${FUNCNAME}: bad options to set: $*"
 	fi
@@ -172,12 +172,7 @@ eshopts_push() {
 eshopts_pop() {
 	local s
 	estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
-	if [[ ${s} == "shopt -"* ]] ; then
-		eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
-	else
-		set +$-     || die "${FUNCNAME}: sanity: invalid shell settings: $-"
-		set -${s}   || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
-	fi
+	eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
 }
 
 # @FUNCTION: eumask_push
-- 
2.12.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt*
  2017-03-24 21:01 [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny
  2017-03-24 21:01 ` [gentoo-dev] [PATCH 2/2] estack.eclass: Use 'shopt -p -o' to restore 'set' flags Michał Górny
@ 2017-04-14 16:31 ` Michał Górny
  1 sibling, 0 replies; 3+ messages in thread
From: Michał Górny @ 2017-04-14 16:31 UTC (permalink / raw)
  To: gentoo-dev; +Cc: base-system

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

On pią, 2017-03-24 at 22:01 +0100, Michał Górny wrote:
> ---
>  eclass/tests/estack_eshopts.sh | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)


Both merged.

-- 
Best regards,
Michał Górny

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-14 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24 21:01 [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny
2017-03-24 21:01 ` [gentoo-dev] [PATCH 2/2] estack.eclass: Use 'shopt -p -o' to restore 'set' flags Michał Górny
2017-04-14 16:31 ` [gentoo-dev] [PATCH 1/2] eclass/tests/estack_eshopts.sh: Add tests for 'set' variant of eshopt* Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox