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

test.arguments = "rm"
test.options += -c

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

: no-args
:
{
  : fail
  :
  : Removing with no arguments fails.
  :
  $* 2>"rm: missing file" == 1

  : force
  :
  : Removing with no arguments succeeds with -f option.
  :
  $* -f
}

: file
:
{
  : exists
  :
  : Removing existing file succeeds.
  :
  {
    touch a &!a;

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

  : not-exists
  :
  {
    : fail
    :
    : Removing non-existing file fails.
    :
    $* a >/~'%remove .+/a false true%' 2>>/~%EOE% == 1
      %rm: unable to remove '.+/a': .+%
      EOE

    : force
    :
    : Removing non-existing file succeeds with -f option.
    :
    $* -f a >>/~%EOO%
      %remove .+/a true true%
      %remove .+/a true false%
      EOO
  }
}

: dir
:
{
  : default
  :
  : Removing directory fails by default.
  :
  {
    mkdir a;

    $* a >/~'%remove .+/a false true%' 2>>/~%EOE% == 1
      %rm: '.+/a' is a directory%
      EOE
  }

  : recursive
  :
  : Removing directory succeeds with -r option.
  :
  {
    mkdir -p a/b &!a &!a/b;

    $* -r a >>/~%EOO%
      %remove .+/a false true%
      %remove .+/a false false%
      EOO
  }
}

: path
:
{
  : empty
  :
  : Removing an empty path fails.
  :
  {
    $* '' 2>"rm: invalid path ''" == 1
  }
}
