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