fork/fish-shell

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

Fabian Boehmtests: Specifically #require fish_test_helper when neededb531cc8b4

master
2.3 KiB71 linesraw
1# RUN: env fth=%fish_test_helper fish=%fish %fish %s
2#REQUIRES: command -v %fish_test_helper
3
4status job-control full
5
6# Ensure that lots of nested jobs all end up in the same pgroup.
7
8function save_pgroup -a var_name
9    $fth print_pgrp | read -g $var_name
10end
11
12# Here everything should live in the pgroup of the first fish_test_helper.
13$fth print_pgrp | read -g global_group | save_pgroup g1 | begin
14    save_pgroup g2
15end | begin
16    echo (save_pgroup g3) >/dev/null
17end
18
19[ "$global_group" -eq "$g1" ] && [ "$g1" -eq "$g2" ] && [ "$g2" -eq "$g3" ]
20and echo "All pgroups agreed"
21or echo "Pgroups disagreed. Should be in $global_group but found $g1, $g2, $g3"
22# CHECK: All pgroups agreed
23
24# Here everything should live in fish's pgroup.
25# Unfortunately we don't know what fish's pgroup is (it may not be fish's pid).
26# So run it twice and verify that everything agrees; this implies that it could
27# not have used any of the pids of the child procs.
28function nothing
29end
30nothing | $fth print_pgrp | read -g a0 | save_pgroup a1 | begin
31    save_pgroup a2
32end
33nothing | $fth print_pgrp | read -g b0 | save_pgroup b1 | begin
34    save_pgroup b2
35end
36
37[ "$a0" -eq "$a1" ] && [ "$a1" -eq "$a2" ] \
38    && [ "$b0" -eq "$b1" ] && [ "$b1" -eq "$b2" ] \
39    && [ "$a0" -eq "$b0" ]
40and echo "All pgroups agreed"
41or echo "Pgroups disagreed. Found $a0 $a1 $a2, and $b0 $b1 $b2"
42# CHECK: All pgroups agreed
43
44# Ensure that eval retains pgroups - #6806.
45set -l tmpfile1 (mktemp)
46set -l tmpfile2 (mktemp)
47$fth print_pgrp > $tmpfile1 | eval '$fth print_pgrp > $tmpfile2'
48read -l pgrp1 < $tmpfile1
49read -l pgrp2 < $tmpfile2
50[ "$pgrp1" -eq "$pgrp2" ]
51and echo "eval pgroups agreed"
52or echo "eval pgroups disagreed, meaning eval does not retain pgroups: $pgrp1 $pgrp2"
53# CHECK: eval pgroups agreed
54echo -n > $tmpfile1
55echo -n > $tmpfile2
56
57# Ensure that if a background job launches another background job, that they have different pgroups.
58# Our regex will capture the first pgroup and use a negative lookahead on the second.
59status job-control full
60$fth print_pgrp > $tmpfile1 | begin
61    $fth print_pgrp > $tmpfile2 &
62    wait
63end &
64wait
65read -l pgrp1 < $tmpfile1
66read -l pgrp2 < $tmpfile2
67[ "$pgrp1" -ne "$pgrp2" ]
68and echo "background job correctly got new pgroup"
69or echo "background job did not get new pgroup: $pgrp1 $pgrp2"
70# CHECK: background job correctly got new pgroup
71rm $tmpfile1 $tmpfile2