# file      : tests/builtin/touch.testscript
# license   : MIT; see accompanying LICENSE file

test.arguments = "touch"

: file
:
$* a &a

: file-create
:
: Test that file is created. If it didn't then 'rm' would fail.
:
{
  $* a &!a

  rm a
}

: file-update
:
: Test that existing file touch doesn't fail.
:
{
  cat <'' >=a

  $* a
}

: callback
:
: Test that the callback is not called for touching an existing file.
:
{
  test.options += -c

  $* a >>/~%EOO% &a
    %create .+/a true%
    %create .+/a false%
    EOO

  $* >>/~%EOO% a
    %create .+/a true%
    %create .+/a false%
    EOO
}

: unknown-option
:
$* -u 2>"touch: unknown option '-u'" == 1

: no-args
:
: Test passing no arguments.
:
$* 2>"touch: missing file" != 0

: empty-path
:
: Test touching an empty path.
:
$* '' 2>"touch: invalid path ''" != 0

: dir-update
:
: Test touching an existing directory.
:
{
  mkdir a

  $* a 2>~'%touch: cannot create/update .+: .+%' != 0
}

: after
:
{{
  : success
  :
  {
    $* a &a
    $* --after a b &b
  }

  : no-value
  :
  $* --after 2>"touch: missing value for option '--after'" != 0

  : not-exists
  :
  touch --after a b 2>~"%touch: cannot obtain file '.+a' modification time: .+%" != 0
}}
