# file      : tests/test/script/builtin/touch.test
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

.include ../common.test

: file
:
$c <'touch a' && $b

: file-create
:
: Test that file is created. If it didn't then 'rm' would fail.
:
$c <<EOI && $b
touch a &!a;
rm a
EOI

: file-update
:
: Test that existing file touch doesn't fail.
:
$c <<EOI && $b
cat <"" >=a;
touch a
EOI

: no-cleanup
:
: Test that touches an existing file doesn't register cleanup. If it does then
: the file would be removed while leaving the embedded scope, and so the
: cleanup registered by the first touch would fail.
:
$c <<EOI && $b
{
  +touch a
  {
    touch ../a
  }
}
EOI

: no-args
:
: Test passing no arguments.
:
$c <'touch 2>"touch: missing file" == 1' && $b

: empty-path
:
: Test touching an empty path.
:
$c <<EOI && $b
touch '' 2>"touch: invalid path ''" == 1
EOI

: dir-update
:
: Test touching an existing directory.
:
$c <<EOI && $b
a = $~;
a += "a";
mkdir a;
touch a 2>"touch: '$a' exists and is not a file" == 1
EOI