fish-shell/tests/checks/umask.fish
Fabian Boehm e66f6878b5 Make tests usable with path with spaces
This is somewhat subtle:

The #RUN line in a littlecheck file will be run by a posix shell,
which means the substitutions will also be mangled by it.

Now, we *have* shell-quoted them, but unfortunately what we need is to
quote them for inside a pre-existing layer of quotes, e.g.

    # RUN: fish -C 'set -g fish %fish'

here, %fish can't be replaced with `'path with spaces/fish'`, because
that ends up as

    # RUN: fish -C 'set -g fish 'path with spaces/fish''

which is just broken.

So instead, we pass it as a variable to that fish:

    # RUN: fish=%fish fish...

In addition, we need to not mangle the arguments in our test_driver.

For that, because we insist on posix shell, which has only one array,
and we source a file, we *need* to stop having that file use
arguments.

Which is okay - test_env.sh could previously be used to start a test,
and now it no longer can because that is test_*driver*.sh's job.

For the interactive tests, it's slightly different:

pexpect.spawn(foo) is sensitive to shell metacharacters like space.

So we shell-quote it.

But if you pass any args to pexpect.spawn, it no longer uses a shell,
and so we cannot shell-quote it.

There could be a better way to fix this?
2025-01-01 16:45:43 +01:00

98 lines
1.6 KiB
Fish

# RUN: fish=%fish %fish %s
# Test the umask command. In particular the symbolic modes since they've been
# broken for four years (see issue #738) at the time I added these tests.
# Establish a base line umask.
umask 027
umask
echo umask var = $umask
umask -S
#CHECK: 0027
#CHECK: umask var = 0027
#CHECK: u=rwx,g=rx,o=
# Verify that an invalid umask is rejected
umask 1234
umask 228
umask 0282
#CHECKERR: umask: Invalid mask '1234'
#CHECKERR: umask: Invalid mask '228'
#CHECKERR: umask: Invalid mask '0282'
# Verify that symbolic modifications and output is correct.
#
# When I wrote these tests I based all of the results on the behavior of bash
# when executing identical commands. So if bash has a bug with the umask
# command it's possible fish will as well. However, I did verify the result of
# each interaction and did not find any bugs in how bash or fish handled these
# scenarios.
#
umask 0777
umask a-r
umask
umask -S
#CHECK: 0777
#CHECK: u=,g=,o=
umask 0777
umask u+x
umask
umask -S
#CHECK: 0677
#CHECK: u=x,g=,o=
umask 777
umask g+rwx,o+x
umask
umask -S
#CHECK: 0706
#CHECK: u=,g=rwx,o=x
umask 0
umask u-w,o-x
umask
umask -S
#CHECK: 0201
#CHECK: u=rx,g=rwx,o=rw
umask 0
umask a-r
umask
umask -S
#CHECK: 0444
#CHECK: u=wx,g=wx,o=wx
umask 0
umask ug-rx
umask
umask -S
#CHECK: 0550
#CHECK: u=w,g=w,o=rwx
umask 777
umask u+r,g+w,o=rw
umask
umask -S
#CHECK: 0351
#CHECK: u=r,g=w,o=rw
umask 777
umask =r,g+w,o+x,o-r
umask
umask -S
#CHECK: 0316
#CHECK: u=r,g=rw,o=x
umask 0
umask rx
umask
umask -S
#CHECK: 0222
#CHECK: u=rx,g=rx,o=rx
umask u=rwx,g=rwx,o=
umask
#CHECK: 0007
umask u=rwx,g=,o=rwx
umask
#CHECK: 0070