xref: /openbsd-src/regress/bin/csh/filec.sh (revision f45a9042c244e39369bbe1194dd2523513032700)
1#!/bin/sh
2#
3# $OpenBSD: filec.sh,v 1.7 2021/09/02 07:14:15 jasper Exp $
4#
5# Copyright (c) 2017 Anton Lindqvist <anton@openbsd.org>
6#
7# Permission to use, copy, modify, and distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19testseq() {
20	stdin=$1
21	exp=$(echo "$2")
22	act=$(echo -n "$stdin" | ./edit -p "$PS1" $CSH)
23	[ $? = 0 ] && [ "$exp" = "$act" ] && return 0
24
25	echo input:
26	echo ">>>${stdin}<<<"
27	echo -n "$stdin" | hexdump -Cv
28	echo expected:
29	echo ">>>${exp}<<<"
30	echo -n "$exp" | hexdump -Cv
31	echo actual:
32	echo ">>>${act}<<<"
33	echo -n "$act" | hexdump -Cv
34
35	exit 1
36}
37
38CSH=${1:-/bin/csh}
39PS1='? '
40
41# Create a fake HOME with a minimal .cshrc and a few files used for completion.
42tmp=$(mktemp -d)
43trap 'rm -r $tmp' 0
44touch $tmp/ambiguous.{1,2} $tmp/complete $tmp/ignore.{c,o} $tmp/only.o
45cat >$tmp/.cshrc <<!
46set filec
47set fignore = (.o)
48set prompt = "$PS1"
49cd ~
50!
51
52HOME=$tmp
53export HOME
54
55# NL: Execute command.
56testseq "echo a\n" "? echo a\r\na\r\n? "
57testseq "echo \0001\n" "? echo ^A\r\n\0001\r\n? "
58
59# VEOF: List all completions or exit.
60testseq "a\0004" "? a^D\r\nambiguous.1  ambiguous.2  \r\r\n? a"
61testseq "ignore\0004" "? ignore^D\r\nignore.c  ignore.o  \r\r\n? ignore"
62testseq "set ignoreeof\n\0004" \
63	"? set ignoreeof\r\n? ^D\r\nUse \"exit\" to leave csh.\r\n? "
64testseq "set ignoreeof\na\0004" \
65	"? set ignoreeof\r\n? a^D\r\nambiguous.1  ambiguous.2  \r\r\n? a"
66
67# VEOL: File name completion.
68testseq "\0033" "? \0007"
69testseq "c\0033" "? complete"
70testseq "a\0033" "? a\0007mbiguous."
71testseq "~${USER}\0033" "? ~${USER}"
72testseq "ignore\0033" "? ignore.c"
73testseq "only\0033" "? only.o"
74
75# VERASE: Delete character.
76testseq "\0177" "? "
77testseq "ab\0177\0177\0177" "? ab\b \b\b \b"
78testseq "a\0002\0177" "? a^B\b\b  \b\b"
79testseq "\0001\0002\0177" "? ^A^B\b\b  \b\b"
80testseq "\t\0177" "?         \b\b\b\b\b\b\b\b        \b\b\b\b\b\b\b\b"
81
82# VINTR: Abort line.
83testseq "\0003" "? ^C\r\n? "
84testseq "ab\0003" "? ab^C\r\n? "
85testseq "foreach i ()\n\0003" "? foreach i ()\r\n? ^C\r\r\n? "
86
87# VKILL: Kill line.
88testseq "\0025" "? "
89testseq "ab\0025" "? ab\b\b  \b\b"
90
91# VLNEXT: Insert literal.
92testseq "\0026\0007" "? ^G"
93testseq "\0026\0033" "? ^["
94testseq "echo \0026\0001a\n" "? echo ^Aa\r\n\0001a\r\n? "
95
96# VREPRINT: Reprint line.
97testseq "ab\0022" "? ab^R\r\nab"
98
99# XXX VSTATUS: Send TIOCSTAT.
100
101# VWERASE: Delete word.
102testseq "\0027" "? "
103testseq "ab\0027" "? ab\b\b  \b\b"
104testseq "ab cd\0027\0027" "? ab cd\b\b  \b\b\b\b\b   \b\b\b"
105
106# VWERASE: Delete word using altwerase.
107testseq "stty altwerase\n\0027" "? stty altwerase\r\n? "
108testseq "stty altwerase\nab\0027" "? stty altwerase\r\n? ab\b\b  \b\b"
109testseq "stty altwerase\nab/cd\0027\0027" \
110	"? stty altwerase\r\n? ab/cd\b\b  \b\b\b\b\b   \b\b\b"
111