fork/fish-shell

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

Fabian HomborgReformat2e55e3454

master
4.2 KiB147 linesraw
1#!/usr/bin/env python3
2from pexpect_helper import SpawnedProc
3
4sp = SpawnedProc()
5sendline, expect_prompt, expect_str = sp.sendline, sp.expect_prompt, sp.expect_str
6
7# Test fish_postexec and $status_generation for interactive shells.
8expect_prompt()
9
10sendline(
11    "function test_fish_postexec --on-event fish_postexec; printf 'pipestatus:%s, generation:%d, command:%s\\n' (string join '|' $pipestatus) $status_generation $argv; end"
12)
13expect_prompt()
14
15generation = 1
16
17# fish_postexec is called when foreground job ends.
18sendline("true")
19generation += 1
20expect_str("pipestatus:0, generation:%d, command:true" % generation)
21expect_prompt()
22
23# Command has multiple jobs.
24sendline("true;false")
25generation += 1
26expect_str("pipestatus:1, generation:%d, command:true;false" % generation)
27expect_prompt()
28
29# Command is a pipeline.
30sendline("true|false")
31generation += 1
32expect_str("pipestatus:0|1, generation:%d, command:true|false" % generation)
33expect_prompt()
34
35# Does not increment $status_generation for background jobs.
36# status, pipestatus remain unchanged
37sendline("sleep 1000 &")
38expect_str("pipestatus:0|1, generation:%d, command:sleep 1000 &" % generation)
39expect_prompt()
40
41# multiple backgrounded jobs
42sendline("sleep 1000 &; sleep 2000 &")
43expect_str(
44    "pipestatus:0|1, generation:%d, command:sleep 1000 &; sleep 2000 &" % generation
45)
46expect_prompt()
47
48# valid variable assignment
49sendline("set foo bar")
50expect_str("pipestatus:0|1, generation:%d, command:set foo bar" % generation)
51expect_prompt()
52
53# valid variable assignment with background job
54sendline("set foo bar; sleep 1000 &")
55expect_str(
56    "pipestatus:0|1, generation:%d, command:set foo bar; sleep 1000 &" % generation
57)
58expect_prompt()
59
60# Increments $status_generation if any job was foreground.
61sendline("false|true; sleep 1000 &")
62generation += 1
63expect_str(
64    "pipestatus:1|0, generation:%d, command:false|true; sleep 1000 &" % generation
65)
66expect_prompt()
67
68sendline("sleep 1000 &; true|false|true")
69generation += 1
70expect_str(
71    "pipestatus:0|1|0, generation:%d, command:sleep 1000 &; true|false|true"
72    % generation
73)
74expect_prompt()
75
76# Increments $status_generation for empty if/while blocks.
77sendline("if true;end")
78generation += 1
79expect_str("pipestatus:0, generation:%d, command:if true;end" % generation)
80expect_prompt()
81
82sendline("while false;end")
83generation += 1
84expect_str("pipestatus:0, generation:%d, command:while false;end" % generation)
85expect_prompt()
86
87# or non-matching if.
88sendline("if false;false;end")
89generation += 1
90expect_str("pipestatus:0, generation:%d, command:if false;false;end" % generation)
91expect_prompt()
92
93# or a function definition.
94# This is an implementation detail, but the test case should prevent regressions.
95sendline("function fail; false; end")
96generation += 1
97expect_str(
98    "pipestatus:0, generation:%d, command:function fail; false; end" % generation
99)
100expect_prompt()
101
102# or an invalid variable assignment
103sendline("set '!@#$' value")
104generation += 1
105expect_str("pipestatus:2, generation:%d, command:set '!@#$' value" % generation)
106expect_prompt()
107
108# or a variable query
109sendline("set -q fish_pid")
110generation += 1
111expect_str("pipestatus:0, generation:%d, command:set -q fish_pid" % generation)
112expect_prompt()
113
114# This is just to set a memorable pipestatus.
115sendline("true|false|true")
116generation += 1
117expect_str("pipestatus:0|1|0")
118expect_prompt()
119
120# Does not increment $status_generation for empty begin/end block.
121sendline("begin;end")
122expect_str("pipestatus:0|1|0, generation:%d, command:begin;end" % generation)
123expect_prompt()
124
125# Or begin/end block with only backgrounded jobs.
126sendline("begin; sleep 200 &; sleep 400 &; end")
127expect_str(
128    "pipestatus:0|1|0, generation:%d, command:begin; sleep 200 &; sleep 400 &; end"
129    % generation
130)
131expect_prompt()
132
133# Or a combination of begin/end block and backgrounded job.
134sendline("begin; sleep 200 &; end; sleep 400 &")
135expect_str(
136    "pipestatus:0|1|0, generation:%d, command:begin; sleep 200 &; end; sleep 400 &"
137    % generation
138)
139expect_prompt()
140
141# Or a combination with variable assignments
142sendline("begin; set foo bar; sleep 1000 &; end; set bar baz; sleep 2000 &")
143expect_str(
144    "pipestatus:0|1|0, generation:%d, command:begin; set foo bar; sleep 1000 &; end; set bar baz; sleep 2000 &"
145    % generation
146)
147expect_prompt()