# file      : tests/test/script/runner/env.testscript
# license   : MIT; see accompanying LICENSE file

.include ../common.testscript

: cwd
:
{
  : not-exist
  :
  $c <'env -c a -- $* -w' && $b 2>>/~%EOE% != 0
  %testscript:1:1: error: specified working directory .+/a/ does not exist%
    info: test id: 1
  EOE

  : process
  :
  $c <<EOI && $b
  mkdir a;
  env -c a -- $* -w >/~%.+/a%
  EOI

  : builtin
  :
  $c <<EOI && $b
  mkdir a;
  env -c a -- touch b;
  test -f a/b
  EOI

  : absolute
  :
  $c <<EOI && $b
  mkdir a;
  env -c $~/a -- touch b;
  test -f a/b
  EOI
}

: variables
:
{
  $c <'env abc=xyz -- $* -v abc >xyz' && $b                         : set
  $c <'env --unset=abc -- $* -v abc >"<none>"' && env abc=xyz -- $b : unset
}

: timeout
:
{
  : expired
  :
  $c <'env --timeout 1 -- $* -l 5' && $b 2>>~%EOE% != 0
  %testscript:1:1: error: .+ terminated: execution timeout expired%
    info: test id: 1
  EOE

  : not-expired
  :
  $c <'env --timeout 5 -- $* -l 1' && $b

  : invalid
  :
  $c <'env --timeout a -- $*' && $b 2>>EOE != 0
  testscript:1:15: error: env: invalid value 'a' for option '--timeout'
  EOE
}
