xref: /freebsd/contrib/one-true-awk/testdir/T.nextfile (revision 31ba4ce8898f9dfa5e7f054fdbc26e50a599a6e3)
1echo T.nextfile: tests of nextfile command
2
3awk=${awk-../a.out}
4
5# 1st lines of some files
6rm -f foo0
7for i in T.*
8do
9	sed 1q $i >>foo0
10done
11
12$awk '
13{ print $0; nextfile }	# print first line, quit
14' T.* >foo1
15
16diff foo0 foo1 || echo 'BAD: T.nextfile 1'
17
18$awk '	# same test but in a for loop
19{ print $0;
20  for (i = 1; i < 10; i++)
21	if (i == 1)
22		nextfile
23  print "nextfile for error"
24}	# print first line, quit
25' T.* >foo1
26
27diff foo0 foo1 || echo 'BAD: T.nextfile 1f'
28
29$awk '	# same test but in a while loop
30{ print $0;
31  i = 1
32  while (i < 10)
33	if (i++ == 1)
34		nextfile
35  print "nextfile while error"
36}	# print first line, quit
37' T.* >foo1
38
39diff foo0 foo1 || echo 'BAD: T.nextfile 1w'
40
41$awk '	# same test but in a do loop
42{ print $0;
43  i = 1
44  do {
45	if (i++ == 1)
46		nextfile	# print first line, quit
47  } while (i < 10)
48  print "nextfile do error"
49}
50' T.* >foo1
51
52diff foo0 foo1 || echo 'BAD: T.nextfile 1d'
53
54
55# 100 lines of some files
56rm -f foo0
57for i in T.*
58do
59	sed 100q $i >>foo0
60done
61
62$awk '
63{ print }
64FNR == 100 { nextfile }	# print first line, quit
65' T.* >foo1
66
67diff foo0 foo1 || echo 'BAD: T.nextfile 2'
68
69
70>foo0	# empty
71$awk ' { nextfile; print $0 }' T.* >foo1
72
73diff foo0 foo1 || echo 'BAD: T.nextfile 3'
74
75# skip weird args
76rm -f foo0
77for i in T.*
78do
79	sed 1q $i >>foo0
80done
81
82$awk '
83{ print $0; nextfile }	# print first line, quit
84' T.* >foo1
85
86diff foo0 foo1 || echo 'BAD: T.nextfile 4'
87