aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/builtin/test.testscript
blob: dceb229eee055b64b401e50d4bd780b4edbd404f (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
78
79
80
81
82
83
84
85
# file      : tests/test/script/builtin/test.testscript
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

.include ../common.testscript

: file
:
{
  : exists
  :
  $c <<EOI && $b
  touch a;
  test -f a
  EOI

  : not-exists
  :
  $c <'test -f a == 1' && $b

  : not-file
  :
  $c <'test -f . == 1' && $b
}

: dir
:
{
  : exists
  :
  $c <'test -d .' && $b

  : not-exists
  :
  $c <'test -d a == 1' && $b

  : not-dir
  :
  $c <<EOI && $b
  touch a;
  test -d a == 1
  EOI
}

: options
:
{
  : unknown
  :
  $c <<EOI && $b
  test -u 2>"test: unknown option '-u'" == 2
  EOI

  : none
  :
  $c <<EOI && $b
  test 2>"test: either -f|--file or -d|--directory must be specified" == 2
  EOI

  : both-file-dir
  :
  $c <<EOI && $b
  test -f -d 2>"test: both -f|--file and -d|--directory specified" == 2
  EOI
}

: args
:
{
  : none
  :
  $c <'test -f 2>"test: missing path" == 2' && $b

  : unexpected
  :
  $c <<EOI && $b
  test -f a b 2>"test: unexpected argument 'b'" == 2
  EOI

  : empty-path
  :
  $c <<EOI && $b
  test -d '' 2>"test: invalid path ''" == 2
  EOI
}