fork/fish-shell

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

NahorFix failing system tests on Cygwin440e7fcbc

master
3.2 KiB141 linesraw
1#RUN: %fish %s
2
3# Verify zombies are not left by disown (#7183, #5342)
4# Do this first to avoid colliding with the other disowned processes below, which may
5# still be running at the end of the script
6sleep 0.2 &
7disown
8sleep 0.2
9echo Trigger process reaping
10sleep 0.1
11#CHECK: Trigger process reaping
12# The initial approach here was to kill the PID of the sleep process, which should
13# be gone by the time we get here. Unfortunately, kill from procps on pre-2016 distributions
14# does not print an error for non-existent PIDs, so instead look for zombies in this session.
15# There could already be zombies from previous tests run in this session or a test could be run
16# simultaneously that causes a zombie to spawn, so limit the output only to processes started by
17# this fish instance.
18# Cygwin does not have zombies (or at least, `ps` cannot show if they are or not)
19if not __fish_is_cygwin
20    if not contains (uname) SunOS
21        ps -o ppid,stat
22    else
23        ps -o ppid,s
24    end | string match -e $fish_pid | string match '*Z*'
25end
26
27# Verify disown can be used with last_pid, even if it is separate from the pgroup.
28# This should silently succeed.
29command true | sleep 0.5 &
30disown $last_pid
31
32jobs -q
33echo $status
34#CHECK: 1
35sleep 5 &
36sleep 5 &
37jobs -c
38#CHECK: Command
39#CHECK: sleep
40#CHECK: sleep
41jobs -q
42echo $status
43#CHECK: 0
44bg -23 1 2>/dev/null
45or echo bg: invalid option -23 >&2
46#CHECKERR: bg: invalid option -23
47fg 3
48#CHECKERR: fg: No suitable job: 3
49bg 3
50#CHECKERR: bg: Could not find job '3'
51sleep 1 &
52disown
53jobs -c
54#CHECK: Command
55#CHECK: sleep
56#CHECK: sleep
57jobs 1
58echo $status
59#CHECK: 1
60#CHECKERR: jobs: No suitable job: 1
61jobs foo
62echo $status
63#CHECK: 2
64#CHECKERR: jobs: 'foo' is not a valid process ID
65jobs -q 1
66echo $status
67#CHECK: 1
68jobs -q foo
69echo $status
70#CHECK: 2
71#CHECKERR: jobs: 'foo' is not a valid process ID
72disown foo
73#CHECKERR: disown: 'foo' is not a valid process ID
74disown (jobs -p)
75or exit 0
76
77# Verify `jobs` output within a function lists background jobs
78# https://github.com/fish-shell/fish-shell/issues/5824
79function foo
80    sleep 0.2 &
81    jobs -c
82end
83foo
84
85# Verify we observe job exit events
86sleep 1 &
87set sleep_job $last_pid
88function sleep_done_$sleep_job --on-job-exit $sleep_job
89    command echo "sleep is done"
90    functions --erase sleep_done_$sleep_job
91end
92sleep 2
93
94# Verify `jobs -l` works and returns the right status codes
95# https://github.com/fish-shell/fish-shell/issues/6104
96jobs --last --command
97echo $status
98#CHECK: Command
99#CHECK: sleep
100#CHECK: sleep is done
101#CHECK: 1
102sleep 0.2 &
103jobs -lc
104echo $status
105#CHECK: Command
106#CHECK: sleep
107#CHECK: 0
108
109function foo
110    function caller --on-job-exit caller
111        echo caller
112    end
113    echo foo
114end
115
116function bar --on-event bar
117    echo (foo)
118end
119
120emit bar
121#CHECK: foo
122#CHECK: caller
123
124# We can't rely on a *specific* pgid being assigned,
125# but we can rely on it not being fish's.
126command true &
127set -l truepid $last_pid
128test $truepid != $fish_pid || echo true has same pid as fish
129
130# Job exit events work even after the job has exited!
131sleep .5
132function thud --on-job-exit $truepid
133    echo "thud called"
134end
135# CHECK: thud called
136
137disown 252
138# CHECKERR: disown: Could not find job '252'
139
140jobs %abc
141# CHECKERR: jobs: '%abc' is not a valid job ID