aboutsummaryrefslogtreecommitdiffstats
path: root/test/iolint.awk
blob: 257678ed9cff3931a4217d436f47c717a2e9f7da (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
BEGIN {
	LINT = 1

	# `%.*s' used for input file and for output file
	print "hi" > "f1"
	fflush("f1")
	getline x < "f1"
	print close("f1")
	print close("f1")
	fflush()

	# `%.*s' used for input file and input pipe
	# `%.*s' used for input file and two-way pipe
	# `%.*s' used for input pipe and two-way pipe
	getline data3 < "echo hello"
	"echo hello" |& getline data2
	"echo hello" | getline data

	print data, data2, data3

	print close("echo hello")
	print close("echo hello")
	print close("echo hello")
	fflush()

	# `%.*s' used for input file and output pipe
	getline x < "cat"
	print "foo" | "cat"
	print close("cat")
	print close("cat")
	fflush()

	# unnecessary mixing of `>' and `>>' for file `%.*s'
	print "foo" >  "f2"
	print "bar" >> "f2"
	print close("f2")
	print close("f2")	# -1 expected here
	fflush()

	# `%.*s' used for input pipe and output file
	"echo hello" | getline junk
	print "hello" > "echo hello"
	print close("echo hello")
	print close("echo hello")
	fflush()

	# `%.*s' used for output file and output pipe
	# `%.*s' used for output file and two-way pipe
	# `%.*s' used for output pipe and two-way pipe
	# Not doing |& due to race condition and signals. sigh
	cat = "cat"
	print "hello" | "cat"
	print "/bin/cat \"$@\"" > "cat"
	print close("cat")
	print close("cat")
	fflush()

	# `%.*s' used for input pipe and output pipe
	"echo hello" | getline junk
	print "hello" | "echo hello"
	print close("echo hello")
	print close("echo hello")
	fflush()

	# `%.*s' used for output file and output pipe"
	BINMODE = 2
	print "junk" > "cksum"	# cksum is more portable than md5sum
	print "hello" | "cksum"
	print close("cksum")
	print close("cksum")
	fflush()
}