xref: /freebsd/contrib/one-true-awk/testdir/T.getline (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1echo T.getline: test getline function
2
3awk=${awk-../a.out}
4
5who >foo1
6cat foo1 | $awk '
7BEGIN {
8	while (getline)
9		print
10	exit
11}
12' >foo
13cmp -s foo1 foo || echo 'BAD: T.getline (bare getline)'
14
15who >foo1
16cat foo1 | $awk '
17BEGIN {
18	while (getline xxx)
19		print xxx
20	exit
21}
22' >foo
23cmp -s foo1 foo || echo 'BAD: T.getline (getline xxx)'
24
25$awk '
26BEGIN {
27	while (getline <"/etc/passwd")
28		print
29	exit
30}
31' >foo
32cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <file)'
33
34cat /etc/passwd | $awk '
35BEGIN {
36	while (getline <"-")	# stdin
37		print
38	exit
39}
40' >foo
41cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <"-")'
42
43$awk '
44BEGIN {
45	while (getline <ARGV[1])
46		print
47	exit
48}
49' /etc/passwd >foo
50cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline <arg)'
51
52$awk '
53BEGIN {
54	while (getline x <ARGV[1])
55		print x
56	exit
57}
58' /etc/passwd >foo
59cmp -s /etc/passwd foo || echo 'BAD: T.getline (getline x <arg)'
60
61$awk '
62BEGIN {
63	while (("cat " ARGV[1]) | getline)
64		print
65	exit
66}
67' /etc/passwd >foo
68cmp -s /etc/passwd foo || echo 'BAD: T.getline (cat arg | getline)'
69
70$awk '
71BEGIN {
72	while (("cat " ARGV[1]) | getline x)
73		print x
74	exit
75}
76' /etc/passwd >foo
77cmp -s /etc/passwd foo || echo 'BAD: T.getline (cat arg | getline x)'
78
79$awk ' BEGIN { print getline <"/glop/glop/glop" } ' >foo
80echo '-1' >foo1
81cmp -s foo foo1 || echo 'BAD: T.getline (non-existent file)'
82
83echo 'false false equal' >foo1
84$awk 'BEGIN {
85	"echo 0" | getline
86	if ($0) printf "true "
87	else printf "false "
88	if ($1) printf "true "
89	else printf "false "
90	if ($0==$1) printf "equal\n"
91	else printf "not equal\n"
92}' >foo2
93cmp -s foo1 foo2 || echo 1>&2 'BAD: T.getline bad $0 type in cmd|getline'
94
95echo 'L1
96L2' | $awk 'BEGIN { $0="old stuff"; $1="new"; getline x; print}' >foo1
97echo 'new stuff' >foo2
98cmp -s foo1 foo2 || echo 1>&2 'BAD: T.getline bad update $0'
99