gash/tests/temporary-assignments.org

3.5 KiB
Raw Permalink Blame History

;;; 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/>.

;; Special built-ins

Assignments escape special built-ins

  eval 'X=foo'
  echo $X

:STDOUT:

  foo

Temporary assignments escape special built-ins

  X=bar eval 'X=foo'
  echo $X

:STDOUT:

  foo

Updates of temporary assignments escape special built-ins

  X=foo
  X=bar eval 'X=baz'
  echo $X

:STDOUT:

  baz

Temporary assignments are not exported in special built-ins

  X=foo eval 'guile -c '\''(format #t "~a~%" (getenv "X"))'\'

:STDOUT:

  #f

Temporary exports do not escape special built-ins

  X=bar
  X=foo :
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  #f

Exports escape special built-ins

  X=foo
  eval 'export X'
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  foo

Exports of temporary assignments escape special built-ins

  X=foo eval 'export X'
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  foo

;; Functions

Assignments escape functions

  f() {
      X=foo
  }
  f
  echo $X

:STDOUT:

  foo

Temporary assignments do not escape functions

  f() {
      X=foo
  }
  X=bar f
  echo $X

:STDOUT:


Updates of temporary assignments do not escape functions

  f() {
      X=baz
  }
  X=foo
  X=bar f
  echo $X

:STDOUT:

  foo

Temporary assignments are not exported in functions

  f() {
      guile -c '(format #t "~a~%" (getenv "X"))'
  }
  X=foo f

:STDOUT:

  #f

Temporary exports do not escape functions

  f() {
      :
  }
  X=bar
  X=foo f
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  #f

Exports escape functions

  f() {
      export X
  }
  X=foo
  f
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  foo

Exports of temporary assignments do not escape functions

  f() {
      export X
  }
  X=foo f
  guile -c '(format #t "~a~%" (getenv "X"))'

:STDOUT:

  #f

Read-only temporary assignments do not escape functions

  f() {
      readonly X
  }
  X=foo f
  echo $X

:STDOUT: