Implement asserting references.

* gash/word.scm (word->qword): Add an implementation for the
'<sh-ref-assert>' and '<sh-ref-assert*>' cases.
* tests/variable-operators.org: New file.
* Makefile.am (FULL_TESTS): Add it.
This commit is contained in:
Timothy Sample 2019-11-28 12:58:31 -05:00
parent 7fee72f5c7
commit 8135e19904
3 changed files with 35 additions and 2 deletions

View File

@ -147,6 +147,7 @@ FULL_TESTS = \
tests/signals.org \
tests/temporary-assignments.org \
tests/variable-and.org \
tests/variable-operators.org \
tests/variable-or.org \
tests/variable-patterns.org \
tests/variable-words.org \

View File

@ -278,9 +278,15 @@ and arithmetic substitions."
(setvar! name new-value)
new-value))))
(('<sh-ref-assert> name message)
(error (format #f "Not implemented: ~s" word)))
(or (parameter-ref name)
(let ((message* (expand-word message #:output 'string)))
(throw 'shell-error (format #f "~a: ~a" name message*)))))
(('<sh-ref-assert*> name message)
(error (format #f "Not implemented: ~s" word)))
(let ((value (parameter-ref name)))
(if (string-not-null? value)
value
(let ((message* (expand-word message #:output 'string)))
(throw 'shell-error (format #f "~a: ~a" name message*))))))
(('<sh-ref-and> name value)
(if (string-not-null? (parameter-ref name))
(word->qword (or value ""))

View File

@ -0,0 +1,26 @@
;;; Gash -- Guile As SHell
;;; Copyright © 2019 Timothy Sample <samplet@ngyro.com>
;;;
;;; This file is part of Gash.
;;;
;;; Gash is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Gash is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Gash. If not, see <http://www.gnu.org/licenses/>.
* Errors on failed asserting reference
:script:
#+begin_src sh
echo ${x?not set}
echo not shown
#+end_src
:status: 1
:stdout: ""