fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes Altmanningertests: filter control sequences only when interactive1e858eae3

master
2.7 KiB86 linesraw
1# RUN: %fish %s
2
3# This tests various corner cases involving command substitution.
4
5# Test cmdsubs which spawn background processes - see #7559.
6# If this hangs, it means that fish keeps trying to read from the write
7# end of the cmdsub pipe (which has escaped).
8
9# FIXME: we need to mark full job control for sleep to get its own pgid;
10# otherwise $last_pid will return fish's pgid! It's always been so!
11status job-control full
12
13echo (command sleep 1000000 & ; set -g sleep_pid $last_pid ; echo local)
14# CHECK: local
15echo $sleep_pid
16# CHECK: {{[1-9]\d*}}
17kill $sleep_pid ; echo $status
18# CHECK: 0
19
20status job-control interactive
21
22# Test limiting the amount of data we'll substitute.
23set fish_read_limit 512
24
25function subme
26    set -l x (string repeat -n $argv x)
27    echo $x
28end
29
30# Command sub just under the limit should succeed.
31set a (subme 511)
32set --show a
33#CHECK: $a: set in global scope, unexported, with 1 elements
34#CHECK: $a[1]: |{{x{510}x}}|
35
36# Command sub at the limit should fail
37set b (string repeat -n 512 x)
38set saved_status $status
39test $saved_status -eq 122
40or echo expected status 122, saw $saved_status >&2
41set --show b
42
43#CHECKERR: {{.*}}: Too much data emitted by command substitution so it was discarded
44#CHECKERR: set b (string repeat -n 512 x)
45#CHECKERR:       ^~~~~~~~~~~~~~~~~~~~~~~^
46
47
48# Command sub over the limit should fail
49set c (subme 513)
50set --show c
51
52#CHECK: $c: set in global scope, unexported, with 1 elements
53#CHECK: $c[1]: ||
54#CHECKERR: {{.*}}: Too much data emitted by command substitution so it was discarded
55#CHECKERR:     set -l x (string repeat -n $argv x)
56#CHECKERR:              ^~~~~~~~~~~~~~~~~~~~~~~~~^
57#CHECKERR: in function 'subme' with arguments '513'
58#CHECKERR: called on line {{.*}}
59#CHECKERR: in command substitution
60#CHECKERR: called on line {{.*}}
61
62# Make sure output from builtins outside of command substitution is not affected
63string repeat --max 513 a
64#CHECK: {{a{512}a}}
65
66# Same builtin in a command substitution is affected
67echo this will fail (string repeat --max 513 b) to output anything
68set saved_status $status
69test $saved_status -eq 122
70or echo expected status 122, saw $saved_status >&2
71
72#CHECKERR: {{.*}}: Too much data emitted by command substitution so it was discarded
73#CHECKERR: echo this will fail (string repeat --max 513 b) to output anything
74#CHECKERR:                     ^~~~~~~~~~~~~~~~~~~~~~~~~~^
75
76
77# Check that it's reset to the default when unset
78begin
79    set -l fish_read_limit 5
80    echo (string repeat -n 10 a)
81    # CHECKERR: {{.*}}cmdsub-limit.fish (line {{\d+}}): Too much data emitted by command substitution so it was discarded
82    # CHECKERR: echo (string repeat -n 10 a)
83    # CHECKERR:      ^~~~~~~~~~~~~~~~~~~~~~^
84end
85echo (string repeat -n 10 a)
86# CHECK: aaaaaaaaaa