aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test1.in
blob: 6c3ba956b6b9bf76850b09f3324173ce293ef2bb (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
#Test aliases, loops, conditionals and some basic elements
#

for i in 1 2 #Comment on same line as command
#Comment inside loop
    for j in a b
		#Double loop
        echo $i$j
	end;
end

# Bracket expansion
echo x-{1}
echo x-{1,2}
echo foo-{1,2{3,4}}

# Escaped newlines
echo foo\ bar
echo foo\
bar
echo "foo\
bar"
echo 'foo\
bar'

for i in \
    a b c
    echo $i
end


# Simple alias tests

function foo
    echo >../test/temp/fish_foo.txt $argv
end

foo hello

cat ../test/temp/fish_foo.txt |read foo

if test $foo = hello;
  echo Test 2 pass
else
  echo Test 2 fail
end

function foo
    printf 'Test %s' $1; echo ' pass'
end

foo 3

for i in Test for continue break and switch builtins problems;
	switch $i
		case Test
			printf "%s " $i
		case "f??"
			printf "%s " 3
		case "c*"
			echo pass
		case break
			continue
			echo fail
		case and
			break
			echo fail
		case "*"
			echo fail
	end
end

set -l sta
if eval true
	if eval false
		set sta fail
	else
		set sta pass
	end
else
	set sta fail
end
echo Test 4 $sta

# Ensure eval doesn't unnecessarily mess with the exit status
function empty_func ; end
false ; eval empty_func ; echo $status
true ; eval empty_func ; echo $status

function test_builtin_status
	return 1
end
test_builtin_status
if [ $status -eq 1 ]
	set sta pass
else
	set sta fail
end
echo Test 5 $sta

# Verify that we can turn stderr into stdout and then pipe it.
# Note that the order here seems unspecified - 'errput' appears before 'output', why?
echo Test redirections
begin ; echo output ; echo errput 1>&2  ; end 2>&1 | tee ../test/temp/tee_test.txt ; cat ../test/temp/tee_test.txt

# Test that trailing ^ doesn't trigger redirection, see #1873
echo caret_no_redirect 12345^

# Verify that we can pipe something other than stdout
# The first line should be printed, since we output to stdout but pipe stderr to /dev/null
# The second line should not be printed, since we output to stderr and pipe it to /dev/null
begin ; echo is_stdout ; end 2>| cat > /dev/null
begin ; echo is_stderr 1>&2 ; end 2>| cat > /dev/null

# echo tests

echo 'abc\ndef'
echo -e 'abc\ndef'
echo -e 'abc\zdef'
echo -e 'abc\41def'
echo -e 'abc\041def'
echo -e 'abc\121def'
echo -e 'abc\1212def'
echo -e 'abc\cdef' # won't output a newline!
echo ''
echo -

echo -ne '\376' | xxd -p

echo -e Catch your breath

echo -e 'abc\x21def'
echo -e 'abc\x211def'

# Verify that pipes don’t conflict with fd redirections
# This code is very similar to eval. We go over a bunch of fads
# to make it likely that we will nominally conflict with a pipe
# fish is supposed to detect this case and dup the pipe to something else
echo "/bin/echo pipe 3 <&3 3<&-" | source 3<&0
echo "/bin/echo pipe 4 <&4 4<&-" | source 4<&0
echo "/bin/echo pipe 5 <&5 5<&-" | source 5<&0
echo "/bin/echo pipe 6 <&6 6<&-" | source 6<&0
echo "/bin/echo pipe 7 <&7 7<&-" | source 7<&0
echo "/bin/echo pipe 8 <&8 8<&-" | source 8<&0
echo "/bin/echo pipe 9 <&9 9<&-" | source 9<&0
echo "/bin/echo pipe 10 <&10 10<&-" | source 10<&0
echo "/bin/echo pipe 11 <&11 11<&-" | source 11<&0
echo "/bin/echo pipe 12 <&12 12<&-" | source 12<&0


# Make sure while loops don't run forever with no-exec (#1543)
echo "Checking for infinite loops in no-execute"
echo "while true; end" | ../test/root/bin/fish --no-execute

# Comments allowed in between lines (#1987)
echo before comment \
  # comment
  after comment

# Backslashes are part of comments and do not join lines (#1255)
# This should execute false, not echo it
echo -n # comment\
false

function always_fails
    if true
        return 1
    end
end

# Verify $argv set correctly in sourced scripts.
# Issue #139
echo 'echo "source argv {$argv}"' | source
echo 'echo "source argv {$argv}"' | source -
echo 'echo "source argv {$argv}"' | source - abc
echo 'echo "source argv {$argv}"' | source - abc def

always_fails ; echo $status