aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test/script/parser+env.test.testscript
blob: b1e864c8f6f344192d76f29d7724236c37a80ff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# file      : libbuild2/test/script/parser+env.test.testscript
# license   : MIT; see accompanying LICENSE file

: unset
:
{
  $* <'env -u a -- cmd'      >'env -u a -- cmd'      : short-opt
  $* <'env --unset a -- cmd' >'env -u a -- cmd'      : long-opt
  $* <'env --unset=a -- cmd' >'env -u a -- cmd'      : long-opt-eq
  $* <'env -u a -u b -- cmd' >'env -u a -u b -- cmd' : mult-opt
  $* <'env -u "a b" -- cmd'  >"env -u 'a b' -- cmd"  : quote

  : invalid-opt
  :
  $* <'env -w a -- cmd' 2>>EOE != 0
    testscript:1:5: error: env: expected variable assignment instead of '-w'
    EOE

  : no-val
  :
  $* <'env -u -- cmd' 2>>EOE != 0
    testscript:1:8: error: env: missing value for option '-u'
    EOE

  : empty-val
  :
  $* <'env --unset= -- cmd' 2>>EOE != 0
    testscript:1:5: error: env: empty value for option '--unset'
    EOE

  : invalid-val
  :
  $* <'env --unset=a=b -- cmd' 2>>EOE != 0
    testscript:1:5: error: env: invalid value 'a=b' for option '--unset': contains '='
    EOE

  : no-sep
  :
  $* <'env -u a cmd' 2>>EOE != 0
    testscript:1:13: error: env: expected option, variable, or '--' separator instead of <newline>
    EOE

  $* <'env && cmd' 2>>EOE != 0
    testscript:1:5: error: env: expected option, variable, or '--' separator instead of '&&'
    EOE
}

: set
:
{
  $* <'env a=b -- cmd'      >'env a=b -- cmd'        : var
  $* <'env -u a b=c -- cmd' >'env -u a - b=c -- cmd' : opt-var
  $* <'env a="b c" -- cmd'  >"env a='b c' -- cmd"    : quote
  $* <'env "a b"=c -- cmd'  >"env 'a b=c' -- cmd"    : quote-name

  : double-quote
  :
  $* <<EOF >>EOF
    env a="'a\"'" -- cmd
    EOF

  : expected-assign
  :
  $* <'env a -- cmd' 2>>EOE != 0
    testscript:1:5: error: env: expected variable assignment instead of 'a'
    EOE
}

: non-first
:
$* <'cmd1 && env -u a b=c -- cmd2' >'cmd1 && env -u a - b=c -- cmd2'

: no-cmd
:
$* <'env -u a --' 2>>EOE != 0
  testscript:1:12: error: env: expected program name instead of <newline>
  EOE