aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test9.in
blob: 962fae8c95b7a118765c00d2cf8d0d8d3f6f8c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# vim: set filetype=fish:
# ensure that builtins that produce no output can still truncate files
# (bug PCA almost reintroduced!)
echo "Testing that builtins can truncate files"
echo abc > /tmp/file_truncation_test.txt
cat /tmp/file_truncation_test.txt
echo -n > /tmp/file_truncation_test.txt
cat /tmp/file_truncation_test.txt

# Test events. 


# This pattern caused a crash; github issue #449

set -g var before

function test1 --on-event test
    set -g var $var:test1
    functions -e test2
end

function test2 --on-event test
    # this should not run, as test2 gets removed before it has a chance of running
    set -g var $var:test2a
end
emit test

echo $var


function test3 --on-event test3
    echo received event test3 with args: $argv
end

emit test3 foo bar

# test empty argument
emit

echo "Test break and continue"
# This should output Ping once
for i in a b c
    if not contains $i c ; continue ; end
    echo Ping
end

# This should output Pong not at all
for i in a b c
    if not contains $i c ; break ; end
    echo Pong
end

# This should output Foop three times, and Boop not at all
set i a a a
while contains $i a
    set -e i[-1]
    echo Foop
    continue
    echo Boop
end

# This should output Doop once
set i a a a
while contains $i a
    set -e i[-1]
    echo Doop
    break
    echo Darp
end

# Test implicit cd. This should do nothing.
./

# Test special for loop expansion
# Here we the name of the variable is derived from another variable
echo "Testing for loop"
set var1 var2
for $var1 in 1 2 3
    echo -n $var2
end
echo

# Test status -n
eval 'status -n
status -n
status -n'

# Test psub
cat (echo foo | psub)
cat (echo bar | psub)
cat (echo baz | psub)

set -l filename (echo foo | psub)
if test -e $filename
    echo 'psub file was not deleted'
else
    echo 'psub file was deleted'
end

# Test support for unbalanced blocks
function try_unbalanced_block
    ../fish -c "echo $argv | source " 2>&1 | grep "Missing end" 1>&2
end
try_unbalanced_block 'begin'
try_unbalanced_block 'while true'
try_unbalanced_block 'for x in 1 2 3'
try_unbalanced_block 'switch abc'
try_unbalanced_block 'function anything'
try_unbalanced_block 'if false'

# Ensure that quoted keywords work
'while' false; end
"while" false; end
"wh"'ile' false; "e"nd

# BOM checking (see #1518)
# But only in UTF8
if locale | __fish_sgrep -q -i utf-8
    echo \uFEFF"echo bom_test" | source
else
    echo "echo bom_test" | source
end

# Comments abutting text (#953)
echo not#a#comment
echo is # a # comment

false