1#!/bin/sh
2#
3# test-all: test fetchlog
4#
5# 28 Jun 2010		Alexander Haderer	LoeScap Technology GmbH
6#
7# NOTE: This test-script has been developed under FreeBSD and was not tested
8# 	on other platforms
9#
10# License: like fetchlog
11#
12
13set +x	# show code
14set -e	# -e : stop on error
15
16wd=$(pwd)		# working dir
17logfile=${wd}/test.log	# logfile
18bm=/tmp/fetchlog.bm	# bookmarkfile
19version=1.4		# fetchlog version
20
21usage_msg="fetchlog - fetch the last new log messages - version ${version} usage 1: fetchlog -f firstcol:lastcol:len:conv logfile bmfile"
22###############################################################################
23# ecpect  testname   expected-exitcode   expected-message   command + options
24#
25# checks results and terminate on mismatch
26#
27expect()
28{
29    testname=$1
30    shift
31    expexit=$1
32    shift
33    expmsg=$1
34    shift
35    command="$*"
36    echo "------------------------------------------------------------------"
37    echo "testname: ${testname}"
38    echo "command : ${command}"
39    set +e	# ignore error
40    realmsg=$(${command})
41    realexit=$?
42    set -e	# stop on  error
43    # shorten exitcode 3 msg to 1st 118 char, because we can't handle all the
44    # meta characters in usage message
45    if [ ${realexit} -eq 3  ]; then
46	realmsg=$(echo ${realmsg} | head -c 118 )
47    fi
48    if [ ${expexit} -ne ${realexit} -o "${expmsg}x" != "${realmsg}x" ]; then
49	echo "result  : FAILED"
50	echo " "
51        echo "  exitcode expected: ${expexit}"
52        echo "  exitcode got     : ${realexit}"
53	echo " "
54        echo "  message expected : >${expmsg}<"
55       	echo "  message got      : >${realmsg}<"
56	echo " "
57	echo "test-all FAILED to complete"
58	exit 1;
59    fi
60    echo "result  : ok"
61
62}
63
64###############################################################################
65# rotate logfiles
66#
67rotate_logs()
68{
69    rm -f ${logfile}.3
70    if [ -e ${logfile}.2 ]; then mv ${logfile}.2 ${logfile}.3; fi
71    if [ -e ${logfile}.1 ]; then mv ${logfile}.1 ${logfile}.2; fi
72    if [ -e ${logfile}.0 ]; then mv ${logfile}.0 ${logfile}.1; fi
73    if [ -e ${logfile}   ]; then mv ${logfile}   ${logfile}.0; fi
74    touch ${logfile}
75
76}
77
78###############################################################################
79# unlink logfiles
80#
81unlink_logs()
82{
83    rm -f ${logfile}
84    rm -f ${logfile}.0
85    rm -f ${logfile}.1
86    rm -f ${logfile}.2
87    rm -f ${logfile}.3
88}
89
90#
91# prepare to run
92#
93if [ -e ${bm} ]; then
94    if ! rm -f ${bm}; then
95	echo "unlinking bookmark '${bm}' failed"
96	echo "test-all FAILED to start"
97	exit 1;
98    fi
99else
100    if ! touch  ${bm}; then
101	echo "creation of bookmark '${bm}' failed"
102	echo "test-all FAILED to start"
103	exit 1;
104    fi
105    rm -f ${bm}
106fi
107
108#
109# do testing
110#
111
112unlink_logs
113
114###########################################################################
115# command line param checking
116###########################################################################
117
118expect "empty call" \
119	3 \
120	"${usage_msg}" \
121	./fetchlog
122
123expect "wrong call 1 param" \
124	3 \
125	"${usage_msg}" \
126	./fetchlog a
127
128expect "wrong call 2 param" \
129	3 \
130	"${usage_msg}" \
131	./fetchlog a b
132
133expect "wrong call 3 param" \
134	3 \
135	"${usage_msg}" \
136	./fetchlog a b c
137
138
139expect "wrong call 4 param" \
140	3 \
141	"${usage_msg}" \
142	./fetchlog a b c d
143
144
145expect "wrong call 5 param" \
146	3 \
147	"${usage_msg}" \
148	./fetchlog a b c d e
149
150
151expect "wrong call 6 param" \
152	3 \
153	"${usage_msg}" \
154	./fetchlog a b c d e f
155
156expect "call for version" \
157	3 \
158	"fetchlog version ${version}" \
159	./fetchlog -V
160
161
162# ######################################################
163# wrong call
164
165expect "wrong call 1" \
166	3 \
167	"${usage_msg}" \
168	./fetchlog -f ::: file bookmark
169
170
171expect "wrong call 2" \
172	3 \
173	"${usage_msg}" \
174	./fetchlog -f 1:100:1000: file bookmark
175
176
177expect "wrong call 3" \
178	3 \
179	"${usage_msg}" \
180	./fetchlog -X 1:100:1000: /file /bookmark
181
182# ######################################################
183# wrong param (syntax)
184
185expect "param column + conv syntax 1" \
186	3 \
187	"ERROR: fetchlog: invalid parameter: firstcol, lastcol, len or conv" \
188	./fetchlog -f a:50:200: ${logfile} ${bm}
189
190expect "param column + conv syntax 2" \
191	3 \
192	"ERROR: fetchlog: invalid parameter: firstcol, lastcol, len or conv" \
193	./fetchlog -f 1:x:200: ${logfile} ${bm}
194
195expect "param column + conv syntax 3" \
196	3 \
197	"ERROR: fetchlog: invalid parameter: firstcol, lastcol, len or conv" \
198	./fetchlog -f 1:50:x: ${logfile} ${bm}
199
200expect "param column + conv syntax 4" \
201	3 \
202	"ERROR: fetchlog: invalid parameter: firstcol, lastcol, len or conv" \
203	./fetchlog -f 1:50:200:X ${logfile} ${bm}
204
205
206# ######################################################
207# wrong param (range)
208
209touch ${logfile}
210
211expect "param column range 1" \
212	3 \
213	"ERROR: fetchlog: out of range: firstcol, lastcol or len" \
214	./fetchlog -f 1:10:200: ${logfile} ${bm}
215
216expect "param column range 2" \
217	3 \
218	"ERROR: fetchlog: out of range: firstcol, lastcol or len" \
219	./fetchlog -f 50:1:200: ${logfile} ${bm}
220
221expect "param column range 3" \
222	3 \
223	"ERROR: fetchlog: out of range: firstcol, lastco~" \
224	./fetchlog -f 1:50:49: ${logfile} ${bm}
225
226expect "param column range 3 ok" \
227	0 \
228	"" \
229	./fetchlog -f 1:50:50: ${logfile} ${bm}
230
231expect "param column range 4a" \
232	0 \
233	"" \
234	./fetchlog -f 1:50:19999: ${logfile} ${bm}
235
236expect "param column range 4b" \
237	0 \
238	"" \
239	./fetchlog -f 1:50:20000: ${logfile} ${bm}
240
241expect "param column range 4c" \
242	3 \
243	"ERROR: fetchlog: out of range: firstcol, lastcol or len" \
244	./fetchlog -f 1:50:20001: ${logfile} ${bm}
245
246expect "param column range 5" \
247	3 \
248	"ERROR: fetchlog: out of range: firstcol, lastcol or len" \
249	./fetchlog -f 300:350:200: ${logfile} ${bm}
250
251expect "param column range 6a" \
252	0 \
253	"" \
254	./fetchlog -f 250:300:200: ${logfile} ${bm}
255
256expect "param column range 6b" \
257	3 \
258	"ERROR: fetchlog: out of range: firstcol, lastcol or len" \
259	./fetchlog -f 250:301:200: ${logfile} ${bm}
260
261
262# ######################################################
263# wrong param (conv)
264
265expect "param conv 1" \
266	0 \
267	"" \
268	./fetchlog -f 1:50:200: ${logfile} ${bm}
269
270expect "param conv 2" \
271	0 \
272	"" \
273	./fetchlog -f 1:50:200:s ${logfile} ${bm}
274
275expect "param conv 3" \
276	0 \
277	"" \
278	./fetchlog -f 1:50:200:n ${logfile} ${bm}
279
280expect "param conv 4" \
281	0 \
282	"OK: no messages" \
283	./fetchlog -f 1:50:200:o ${logfile} ${bm}
284
285expect "param conv 5" \
286	0 \
287	"" \
288	./fetchlog -f 1:50:200:b ${logfile} ${bm}
289
290expect "param conv 6" \
291	0 \
292	"OK: no messages" \
293	./fetchlog -f 1:50:200:3 ${logfile} ${bm}
294
295expect "param conv 7" \
296	0 \
297	"" \
298	./fetchlog -f 1:50:200:p ${logfile} ${bm}
299
300expect "param conv 8" \
301	0 \
302	"OK: no messages" \
303	./fetchlog -f 1:50:200:snob3p ${logfile} ${bm}
304
305expect "param conv 9" \
306	0 \
307	"" \
308	./fetchlog -f 1:50:200:sssss ${logfile} ${bm}
309
310expect "param conv 10" \
311	3 \
312	"ERROR: fetchlog: invalid parameter: firstcol, lastcol, len or conv" \
313	./fetchlog -f 1:50:200:snob3ps ${logfile} ${bm}
314
315# ######################################################
316# wrong param: filenames, broken bookmarks (exitcode 1 stuff)
317
318expect "param bookmark/logfile 1" \
319	1 \
320	"ERROR: fetchlog: open: ${logfile}x: No such file or directory" \
321	./fetchlog -f 1:50:200: ${logfile}x ${bm}
322
323touch ${bm}
324expect "param bookmark/logfile 2" \
325	1 \
326	"ERROR: fetchlog: no file/wrong size: ${bm}" \
327	./fetchlog -f 1:50:200: ${logfile} ${bm}
328
329echo "ABC124" > ${bm}
330expect "param bookmark/logfile 3" \
331	1 \
332	"ERROR: fetchlog: no file/wrong size: ${bm}" \
333	./fetchlog -f 1:50:200: ${logfile} ${bm}
334rm -f ${bm}
335expect "param bookmark/logfile 4" \
336	1 \
337	"ERROR: fetchlog: no file/wrong size: /usr" \
338	./fetchlog -f 1:50:200: ${logfile} /usr
339
340
341# ######################################################
342# fetching: rotated logs without regex
343
344unlink_logs
345rm -f ${bm}
346echo "Zeile 1" > ${logfile}
347
348expect "fetching rotated w/o regex 1" \
349	2 \
350	"Zeile 1" \
351	./fetchlog -F 1:50:200: ${logfile} ${bm}
352
353expect "fetching rotated w/o regex 2" \
354	0 \
355	"" \
356	./fetchlog -F 1:50:200: ${logfile} ${bm}
357
358rotate_logs
359
360expect "fetching rotated w/o regex 3" \
361	0 \
362	"" \
363	./fetchlog -F 1:50:200: ${logfile} ${bm}
364
365rotate_logs
366rotate_logs
367
368expect "fetching rotated w/o regex 5" \
369	0 \
370	"" \
371	./fetchlog -F 1:50:200: ${logfile} ${bm}
372
373echo "Zeile 2" >> ${logfile}
374echo "Zeile 3" >> ${logfile}
375rotate_logs
376
377emsg="Zeile 2
378Zeile 3"
379
380expect "fetching rotated w/o regex 6" \
381	2 \
382	"${emsg}" \
383	./fetchlog -F 1:50:200: ${logfile} ${bm}
384
385echo "Zeile 4" >> ${logfile}
386echo "Zeile 5" >> ${logfile}
387rotate_logs
388rotate_logs
389echo "Zeile 6" >> ${logfile}
390
391emsg="Zeile 4
392Zeile 5
393Zeile 6"
394
395expect "fetching rotated w/o regex 7" \
396	2 \
397	"${emsg}" \
398	./fetchlog -F 1:50:200: ${logfile} ${bm}
399
400expect "fetching rotated w/o regex 8" \
401	0 \
402	"" \
403	./fetchlog -F 1:50:200: ${logfile} ${bm}
404
405expect "fetching nothing from rotated w/o regex 1" \
406	0 \
407	"" \
408	./fetchlog -F 1:50:200: ${logfile} ${bm}
409
410expect "fetching nothing from rotated w/o regex 2" \
411	0 \
412	"" \
413	./fetchlog -F 1:50:200:snbp ${logfile} ${bm}
414
415expect "fetching nothing from rotated w/o regex 3" \
416	0 \
417	"OK: no messages" \
418	./fetchlog -F 1:50:200:o ${logfile} ${bm}
419
420expect "fetching nothing from rotated w/o regex 4" \
421	0 \
422	"OK: no messages" \
423	./fetchlog -F 1:50:200:3 ${logfile} ${bm}
424
425echo >> ${logfile}
426
427expect "fetching newline from rotated w/o regex 1" \
428	2 \
429	"" \
430	./fetchlog -f 1:50:200: ${logfile} ${bm}
431
432expect "fetching newline from rotated w/o regex 2" \
433	2 \
434	"" \
435	./fetchlog -f 1:50:200:sobp ${logfile} ${bm}
436
437expect "fetching newline from rotated w/o regex 3" \
438	2 \
439	"\n\n" \
440	./fetchlog -f 1:50:200:n ${logfile} ${bm}
441
442expect "fetching newline from rotated w/o regex 4" \
443	2 \
444	"|\n\n" \
445	./fetchlog -f 1:50:200:3 ${logfile} ${bm}
446
447
448
449# ######################################################
450# fetching: rotated logs with regex
451
452unlink_logs
453rm -f ${bm}
454echo "Zeile 1 pattern" >> ${logfile}
455
456expect "fetching rotated with regex 1" \
457	2 \
458	"Zeile 1 pattern" \
459	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
460
461expect "fetching rotated with regex 2" \
462	0 \
463	"" \
464	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
465
466echo "Zeile 2 no-patt" >> ${logfile}
467
468expect "fetching rotated with regex 2" \
469	0 \
470	"" \
471	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
472
473rotate_logs
474
475expect "fetching rotated with regex 3" \
476	0 \
477	"" \
478	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
479
480rotate_logs
481rotate_logs
482
483expect "fetching rotated with regex 5" \
484	0 \
485	"" \
486	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
487
488echo "Zeile 3 no-patt" >> ${logfile}
489echo "Zeile 4 pattern" >> ${logfile}
490echo "Zeile 5 no-patt" >> ${logfile}
491
492expect "fetching rotated with regex 6" \
493	2 \
494	"Zeile 4 pattern" \
495	./fetchlog -f 1:50:200: ${logfile} ${bm} pattern
496
497rotate_logs
498
499expect "fetching rotated with regex 7" \
500	2 \
501	"Zeile 4 pattern" \
502	./fetchlog -f 1:50:200: ${logfile} ${bm} pattern
503
504rotate_logs
505rotate_logs
506
507expect "fetching rotated with regex 8" \
508	2 \
509	"Zeile 4 pattern" \
510	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
511
512
513expect "fetching rotated with regex 9" \
514	0 \
515	"" \
516	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
517
518echo "Zeile 6 no-patt" >> ${logfile}
519
520expect "fetching rotated with regex 10" \
521	0 \
522	"" \
523	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
524
525echo "Zeile 7 no-patt" >> ${logfile}
526
527expect "fetching nothing from rotated with regex 1" \
528	0 \
529	"" \
530	./fetchlog -F 1:50:200: ${logfile} ${bm} pattern
531
532echo "Zeile 8 no-patt" >> ${logfile}
533
534expect "fetching nothing from rotated with regex 2" \
535	0 \
536	"" \
537	./fetchlog -F 1:50:200:snbp ${logfile} ${bm} pattern
538
539echo "Zeile 9 no-patt" >> ${logfile}
540
541expect "fetching nothing from rotated with regex 3" \
542	0 \
543	"OK: no messages" \
544	./fetchlog -F 1:50:200:o ${logfile} ${bm} pattern
545
546echo "Zeile 10 no-patt" >> ${logfile}
547
548expect "fetching nothing from rotated with regex 4" \
549	0 \
550	"OK: no messages" \
551	./fetchlog -F 1:50:200:3 ${logfile} ${bm} pattern
552
553
554# ######################################################
555# fetching: rotated logs starting at .1
556
557unlink_logs
558rm -f ${bm}
559echo "Zeile a" >> ${logfile}
560
561expect "fetching rotated logs starting at .1 1" \
562	2 \
563	"\nZeile a\n" \
564	./fetchlog -f 1:50:200:n ${logfile} ${bm}
565
566rotate_logs
567echo "Zeile b" >> ${logfile}
568
569expect "fetching rotated logs starting at .1 2" \
570	2 \
571	"\nZeile a\nZeile b\n" \
572	./fetchlog -f 1:50:200:n ${logfile} ${bm}
573
574rotate_logs
575echo "Zeile c" >> ${logfile}
576
577expect "fetching rotated logs starting at .1 3" \
578	2 \
579	"\nZeile a\nZeile b\nZeile c\n" \
580	./fetchlog -f 1:50:200:n ${logfile} ${bm}
581
582rotate_logs
583echo "Zeile d" >> ${logfile}
584
585expect "fetching rotated logs starting at .1 4" \
586	2 \
587	"\nZeile a\nZeile b\nZeile c\nZeile d\n" \
588	./fetchlog -f 1:50:200:n ${logfile} ${bm}
589
590rotate_logs
591echo "Zeile e" >> ${logfile}
592
593expect "fetching rotated logs starting at .1 5" \
594	2 \
595	"\nZeile a\nZeile b\nZeile c\nZeile d\nZeile e\n" \
596	./fetchlog -f 1:50:200:n ${logfile} ${bm}
597
598mv ${logfile}.0 ${logfile}.0.off
599
600expect "fetching rotated logs starting at .1 6" \
601	2 \
602	"\nZeile a\nZeile b\nZeile c\nZeile e\n" \
603	./fetchlog -f 1:50:200:n ${logfile} ${bm}
604
605mv ${logfile}.0.off ${logfile}.0
606mv ${logfile}.1 ${logfile}.1.off
607
608expect "fetching rotated logs starting at .1 7" \
609	2 \
610	"\nZeile d\nZeile e\n" \
611	./fetchlog -f 1:50:200:n ${logfile} ${bm}
612
613mv ${logfile}.1.off ${logfile}.1
614
615
616# update bookmark
617expect "fetching rotated logs starting at .1 8" \
618	2 \
619	"\nZeile a\nZeile b\nZeile c\nZeile d\nZeile e\n" \
620	./fetchlog -F 1:50:200:n ${logfile} ${bm}
621
622# ######################################################
623# fetching: conversion
624
625rotate_logs
626
627#### newline conversion
628
629echo >> ${logfile}
630
631expect "fetching newline with conversion 1" \
632	2 \
633	"" \
634	./fetchlog -F 1:50:200: ${logfile} ${bm}
635
636echo >> ${logfile}
637
638expect "fetching newline with conversion 2" \
639	2 \
640	"\n\n" \
641	./fetchlog -F 1:50:200:n ${logfile} ${bm}
642
643echo >> ${logfile}
644
645expect "fetching newline with conversion 3" \
646	2 \
647	"|\n\n" \
648	./fetchlog -F 1:50:200:3 ${logfile} ${bm}
649
650expect "fetching nothing with conversion 1" \
651	0 \
652	"" \
653	./fetchlog -F 1:50:200: ${logfile} ${bm}
654
655expect "fetching nothing with conversion 2" \
656	0 \
657	"" \
658	./fetchlog -F 1:50:200:n ${logfile} ${bm}
659
660expect "fetching nothing with conversion 3" \
661	0 \
662	"OK: no messages" \
663	./fetchlog -F 1:50:200:o ${logfile} ${bm}
664
665expect "fetching nothing with conversion 4" \
666	0 \
667	"OK: no messages" \
668	./fetchlog -F 1:50:200:3 ${logfile} ${bm}
669
670
671#### percent conversion
672
673echo "abc%123%%xyz" >> ${logfile}
674
675expect "fetching percent with conversion 1" \
676	2 \
677	"abc%123%%xyz" \
678	./fetchlog -f 1:50:200: ${logfile} ${bm}
679
680expect "fetching percent with conversion 2" \
681	2 \
682	"abc%123%%xyz" \
683	./fetchlog -f 1:50:200:s ${logfile} ${bm}
684
685expect "fetching percent with conversion 3" \
686	2 \
687	"\nabc%123%%xyz\n" \
688	./fetchlog -f 1:50:200:n ${logfile} ${bm}
689
690expect "fetching percent with conversion 4" \
691	2 \
692	"abc%123%%xyz" \
693	./fetchlog -f 1:50:200:o ${logfile} ${bm}
694
695expect "fetching percent with conversion 5" \
696	2 \
697	"abc%123%%xyz" \
698	./fetchlog -f 1:50:200:b ${logfile} ${bm}
699
700expect "fetching percent with conversion 6" \
701	2 \
702	"abcp123ppxyz" \
703	./fetchlog -f 1:50:200:p ${logfile} ${bm}
704
705expect "fetching percent with conversion 7" \
706	2 \
707	"abc%123%%xyz|\nabc%123%%xyz\n" \
708	./fetchlog -f 1:50:200:3 ${logfile} ${bm}
709
710# update bookmark
711expect "fetching percent with conversion 8" \
712	2 \
713	"abc%123%%xyz" \
714	./fetchlog -F 1:50:200: ${logfile} ${bm}
715
716
717#### bracket <> conversion
718
719echo "a<>b" >> ${logfile}
720
721expect "fetching bracket with conversion 1" \
722	2 \
723	"a<>b" \
724	./fetchlog -f 1:50:200: ${logfile} ${bm}
725
726expect "fetching bracket with conversion 2" \
727	2 \
728	"a<>b" \
729	./fetchlog -f 1:50:200:s ${logfile} ${bm}
730
731expect "fetching bracket with conversion 3" \
732	2 \
733	"\na<>b\n" \
734	./fetchlog -f 1:50:200:n ${logfile} ${bm}
735
736expect "fetching bracket with conversion 4" \
737	2 \
738	"a<>b" \
739	./fetchlog -f 1:50:200:o ${logfile} ${bm}
740
741expect "fetching bracket with conversion 5" \
742	2 \
743	"a()b" \
744	./fetchlog -f 1:50:200:b ${logfile} ${bm}
745
746expect "fetching bracket with conversion 6" \
747	2 \
748	"a<>b" \
749	./fetchlog -f 1:50:200:p ${logfile} ${bm}
750
751expect "fetching bracket with conversion 7" \
752	2 \
753	"a<>b|\na<>b\n" \
754	./fetchlog -f 1:50:200:3 ${logfile} ${bm}
755
756expect "fetching bracket with conversion 7a" \
757	2 \
758	"a()b|\na()b\n" \
759	./fetchlog -f 1:50:200:3b ${logfile} ${bm}
760
761# update bookmark
762expect "fetching bracket with conversion 8" \
763	2 \
764	"a<>b" \
765	./fetchlog -F 1:50:200: ${logfile} ${bm}
766
767
768
769#### shell meta conversion
770# Note: we don't test for double quote, because the shell won't let us do
771
772msg="do\$ sq' bt\` ha^ bs\\ pi|"
773echo $msg >> ${logfile}
774
775expect "fetching shell meta with conversion 1" \
776	2 \
777	"$msg" \
778	./fetchlog -f 1:50:200: ${logfile} ${bm}
779
780expect "fetching shell meta with conversion 2" \
781	2 \
782	"do_ sq_ bt_ ha_ bs/ pi_"  \
783	./fetchlog -f 1:50:200:s ${logfile} ${bm}
784
785expect "fetching shell meta with conversion 3" \
786	2 \
787	"\n$msg\n" \
788	./fetchlog -f 1:50:200:n ${logfile} ${bm}
789
790expect "fetching shell meta with conversion 4" \
791	2 \
792	"$msg" \
793	./fetchlog -f 1:50:200:o ${logfile} ${bm}
794
795expect "fetching shell meta with conversion 5" \
796	2 \
797	"$msg" \
798	./fetchlog -f 1:50:200:b ${logfile} ${bm}
799
800expect "fetching shell meta with conversion 6" \
801	2 \
802	"$msg" \
803	./fetchlog -f 1:50:200:p ${logfile} ${bm}
804
805expect "fetching shell meta with conversion 7" \
806	2 \
807	"$msg|\n$msg\n" \
808	./fetchlog -f 1:50:200:3 ${logfile} ${bm}
809
810expect "fetching shell meta with conversion 7a" \
811	2 \
812	"$msg|\n$msg\n" \
813	./fetchlog -f 1:50:200:3b ${logfile} ${bm}
814
815# update bookmark
816expect "fetching shell meta with conversion 8" \
817	2 \
818	"$msg" \
819	./fetchlog -F 1:50:200: ${logfile} ${bm}
820
821
822# ######################################################
823# fetching: columns without regex
824
825rotate_logs
826
827echo "123456789a123456789b123456789c123456789d123456789e123456789f123456789g" \
828	>> ${logfile}
829
830# one line
831expect "fetching: columns w/o regex one line 1" \
832    2 \
833    "123456789a123456789b123456789c123456789d123456789e123456789f123456789g" \
834    ./fetchlog -f 1:80:200: ${logfile} ${bm}
835
836expect "fetching: columns w/o regex one line 2" \
837    2 \
838    "123456789a123456789~" \
839    ./fetchlog -f 1:20:200: ${logfile} ${bm}
840
841expect "fetching: columns w/o regex one line 3" \
842    2 \
843    "b123456789c123456789~" \
844    ./fetchlog -f 20:40:200: ${logfile} ${bm}
845
846expect "fetching: columns w/o regex one line 4" \
847    2 \
848    "f123456789g" \
849    ./fetchlog -f 60:80:200: ${logfile} ${bm}
850
851expect "fetching: columns w/o regex one line 5" \
852    2 \
853    "" \
854    ./fetchlog -f 80:100:200: ${logfile} ${bm}
855
856expect "fetching: columns w/o regex one line 6" \
857    2 \
858    "\n\n" \
859    ./fetchlog -f 80:100:200:n ${logfile} ${bm}
860
861
862# two lines
863
864echo "123456789a123456789b123456789c" \
865	>> ${logfile}
866
867expect "fetching: columns w/o regex two line 1" \
868    2 \
869    "123456789a123456789b123456789c123456789d123456789e123456789f123456789g
870123456789a123456789b123456789c" \
871    ./fetchlog -f 1:80:200: ${logfile} ${bm}
872
873expect "fetching: columns w/o regex two line 2" \
874    2 \
875    "123456789a123456789~
876123456789a123456789~" \
877    ./fetchlog -f 1:20:200: ${logfile} ${bm}
878
879expect "fetching: columns w/o regex two line 3" \
880    2 \
881    "b123456789c123456789~
882b123456789c" \
883    ./fetchlog -f 20:40:200: ${logfile} ${bm}
884
885expect "fetching: columns w/o regex two line 4a" \
886    2 \
887    "f123456789g" \
888    ./fetchlog -f 60:80:200: ${logfile} ${bm}
889
890expect "fetching: columns w/o regex two line 4b" \
891    2 \
892    "\nf123456789g\n\n" \
893    ./fetchlog -f 60:80:200:n ${logfile} ${bm}
894
895expect "fetching: columns w/o regex two line 5" \
896    2 \
897    "" \
898    ./fetchlog -f 80:100:200: ${logfile} ${bm}
899
900expect "fetching: columns w/o regex two line 6" \
901    2 \
902    "\n\n\n" \
903    ./fetchlog -f 80:100:200:n ${logfile} ${bm}
904
905# update bookmark
906expect "fetching: columns w/o regex two line 7" \
907    2 \
908    "\n\n\n" \
909    ./fetchlog -F 80:100:200:n ${logfile} ${bm}
910
911
912
913# ######################################################
914# fetching: columns with regex
915
916rotate_logs
917
918#    "123456789a123456789b123456789c123456789d123456789e123456789f123456789g"
919echo "  PAT_A  a  PAT_B  b  PAT_C  c  line1  d  PAT_E  e  PAT_F  f  PAT_G  g" \
920	>> ${logfile}
921
922# one line
923expect "fetching: columns with regex one line 1" \
924    2 \
925    "  PAT_A  a  PAT_B  b  PAT_C  c  line1  d  PAT_E  e  PAT_F  f  PAT_G  g" \
926    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_A
927
928expect "fetching: columns with regex one line 2" \
929    0 \
930    "" \
931    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_X
932
933expect "fetching: columns with regex one line 3" \
934    0 \
935    "" \
936    ./fetchlog -f 20:80:200: ${logfile} ${bm} PAT_A
937
938expect "fetching: columns with regex one line 4" \
939    0 \
940    "" \
941    ./fetchlog -f 20:80:200: ${logfile} ${bm} PAT_B
942
943expect "fetching: columns with regex one line 5" \
944    2 \
945    "b  PAT_C  c  line1  d  PAT_E  e  PAT_F  f  PAT_G  g" \
946    ./fetchlog -f 20:80:200: ${logfile} ${bm} PAT_C
947
948
949
950expect "fetching: columns with regex one line 6" \
951    0 \
952    "" \
953    ./fetchlog -f 20:60:200: ${logfile} ${bm} PAT_A
954
955expect "fetching: columns with regex one line 7" \
956    0 \
957    "" \
958    ./fetchlog -f 20:60:200: ${logfile} ${bm} PAT_B
959
960expect "fetching: columns with regex one line 8" \
961    0 \
962    "" \
963    ./fetchlog -f 20:60:200: ${logfile} ${bm} PAT_G
964
965
966# multi line
967
968echo "  PAT_A  a  PAT_B  b  PAT_C  c  line2" >> ${logfile}
969echo "         a         b         c  line3  d  PAT_E  e  PAT_F  f  PAT_G  g" \
970	>> ${logfile}
971echo "         a         b         c  line4  d         e         f         g" \
972	>> ${logfile}
973
974expect "fetching: columns with regex multi line 1" \
975    2 \
976    "  PAT_A  a  PAT_B  b  PAT_C  c  line1  ~
977  PAT_A  a  PAT_B  b  PAT_C  c  line2" \
978    ./fetchlog -f 1:40:200: ${logfile} ${bm} PAT_A
979
980expect "fetching: columns with regex multi line 2" \
981    0 \
982    "" \
983    ./fetchlog -f 1:40:200: ${logfile} ${bm} PAT_G
984
985expect "fetching: columns with regex multi line 3" \
986    0 \
987    "" \
988    ./fetchlog -f 30:80:200: ${logfile} ${bm} PAT_A
989
990expect "fetching: columns with regex multi line 4" \
991    2 \
992    "c  line1  d  PAT_E  e  PAT_F  f  PAT_G  g
993c  line3  d  PAT_E  e  PAT_F  f  PAT_G  g" \
994    ./fetchlog -f 30:80:200: ${logfile} ${bm} PAT_G
995
996# update bookmark
997rotate_logs
998expect "fetching: columns with regex multi line 5" \
999    2 \
1000    "c  line1  d  PAT_E  e  PAT_F  f  PAT_G  g
1001c  line3  d  PAT_E  e  PAT_F  f  PAT_G  g" \
1002    ./fetchlog -F 30:80:200: ${logfile} ${bm} PAT_G
1003
1004
1005
1006
1007# ######################################################
1008# fetching: multiple regex
1009
1010echo "line1 PAT_A PAT_B PAT_C" >> ${logfile}
1011echo "line2 PAT_A            " >> ${logfile}
1012echo "line3       PAT_B      " >> ${logfile}
1013echo "line4             PAT_C" >> ${logfile}
1014
1015expect "fetching: columns with multiple regex 1" \
1016    2 \
1017    "line1 PAT_A PAT_B PAT_C
1018line2 PAT_A
1019line3       PAT_B      " \
1020    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_A PAT_B
1021
1022expect "fetching: columns with multiple regex 2" \
1023    2 \
1024    "line1 PAT_A PAT_B PAT_C
1025line2 PAT_A
1026line4             PAT_C" \
1027    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_A PAT_C
1028
1029expect "fetching: columns with multiple regex 3" \
1030    2 \
1031    "line1 PAT_A PAT_B PAT_C
1032line2 PAT_A            " \
1033    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_A PAT_A
1034
1035expect "fetching: columns with multiple regex 4" \
1036    2 \
1037    "line1 PAT_A PAT_B PAT_C
1038line4             PAT_C" \
1039    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_C PAT_X
1040
1041expect "fetching: columns with multiple regex 5" \
1042    0 \
1043    "" \
1044    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_X PAT_Y
1045
1046# update bookmark
1047rotate_logs
1048expect "fetching: columns with multiple regex 6" \
1049    0 \
1050    "" \
1051    ./fetchlog -f 1:80:200: ${logfile} ${bm} PAT_X PAT_Y
1052
1053
1054
1055# ######################################################
1056# fetching: fetchlen
1057
1058# 2 x 50 + 1 char
1059echo "L 1 56789a123456789b123456789c123456789d123456789e"  >> ${logfile}
1060echo "L 2 56789a123456789b123456789c123456789d123456789e"  >> ${logfile}
1061
1062expect "fetching fetchlen errormsg 1" \
1063    3 \
1064    "ERROR: fetchlog: out of range: firstcol, lastcol~" \
1065    ./fetchlog -f 1:999:50: ${logfile} ${bm}
1066
1067expect "fetching fetchlen 1" \
1068    2 \
1069    "...56789a123456789b123456789c123456789d123456789e" \
1070    ./fetchlog -f 1:50:50: ${logfile} ${bm}
1071
1072expect "fetching fetchlen 2" \
1073    2 \
1074    "... 56789a123456789b123456789c123456789d123456789e" \
1075    ./fetchlog -f 1:50:51: ${logfile} ${bm}
1076
1077expect "fetching fetchlen 3" \
1078    2 \
1079    "...2 56789a123456789b123456789c123456789d123456789e" \
1080    ./fetchlog -f 1:50:52: ${logfile} ${bm}
1081
1082expect "fetching fetchlen 4" \
1083    2 \
1084    "... 2 56789a123456789b123456789c123456789d123456789e" \
1085    ./fetchlog -f 1:50:53: ${logfile} ${bm}
1086
1087expect "fetching fetchlen 5" \
1088    2 \
1089    "...L 2 56789a123456789b123456789c123456789d123456789e" \
1090    ./fetchlog -f 1:50:54: ${logfile} ${bm}
1091
1092expect "fetching fetchlen 6" \
1093    2 \
1094    "...
1095L 2 56789a123456789b123456789c123456789d123456789e" \
1096    ./fetchlog -f 1:50:55: ${logfile} ${bm}
1097
1098expect "fetching fetchlen 7" \
1099    2 \
1100    "...e
1101L 2 56789a123456789b123456789c123456789d123456789e" \
1102    ./fetchlog -f 1:50:56: ${logfile} ${bm}
1103
1104
1105expect "fetching fetchlen conv n 1" \
1106    2 \
1107    "\n... 2 56789a123456789b123456789c123456789d123456789e\n" \
1108    ./fetchlog -f 1:50:57:n ${logfile} ${bm}
1109
1110expect "fetching fetchlen conv n 2" \
1111    2 \
1112    "\n...L 2 56789a123456789b123456789c123456789d123456789e\n" \
1113    ./fetchlog -f 1:50:58:n ${logfile} ${bm}
1114
1115expect "fetching fetchlen conv n 3" \
1116    2 \
1117    "\n....L 2 56789a123456789b123456789c123456789d123456789e\n" \
1118    ./fetchlog -f 1:50:59:n ${logfile} ${bm}
1119
1120expect "fetching fetchlen conv n 4" \
1121    2 \
1122    "\n...\nL 2 56789a123456789b123456789c123456789d123456789e\n" \
1123    ./fetchlog -f 1:50:60:n ${logfile} ${bm}
1124
1125expect "fetching fetchlen conv n 5" \
1126    2 \
1127    "\n...e\nL 2 56789a123456789b123456789c123456789d123456789e\n" \
1128    ./fetchlog -f 1:50:61:n ${logfile} ${bm}
1129
1130expect "fetching fetchlen conv n 6" \
1131    2 \
1132    "\n...9e\nL 2 56789a123456789b123456789c123456789d123456789e\n" \
1133    ./fetchlog -f 1:50:62:n ${logfile} ${bm}
1134
1135# update bookmark
1136rotate_logs
1137expect "fetching fetchlen N" \
1138    2 \
1139    "...56789a123456789b123456789c123456789d123456789e" \
1140    ./fetchlog -F 1:50:50: ${logfile} ${bm}
1141
1142# ######################################################
1143# fetching: conversion '3'
1144
1145echo "L 1 56789a123456789b123456789c"  >> ${logfile}
1146echo "L 2 56789a123456789b123456789c"  >> ${logfile}
1147
1148expect "fetching conversion 3  1" \
1149    2 \
1150    "L 2 56789a123456789b123456789c" \
1151    ./fetchlog -f 1:50:60:3 ${logfile} ${bm}
1152
1153expect "fetching conversion 3  2" \
1154    2 \
1155    "L 2 56789a123456789b123456789c" \
1156    ./fetchlog -f 1:50:67:3 ${logfile} ${bm}
1157
1158expect "fetching conversion 3  3" \
1159    2 \
1160    "L 2 56789a123456789b123456789c" \
1161    ./fetchlog -f 1:50:68:3 ${logfile} ${bm}
1162
1163expect "fetching conversion 3  4" \
1164    2 \
1165    "L 2 56789a123456789b123456789c|\n...L 2 56789a123456789b123456789c\n" \
1166    ./fetchlog -f 1:50:69:3 ${logfile} ${bm}
1167
1168expect "fetching conversion 3  5" \
1169    2 \
1170    "L 2 56789a123456789b123456789c|\n..\nL 2 56789a123456789b123456789c\n" \
1171    ./fetchlog -f 1:50:70:3 ${logfile} ${bm}
1172
1173expect "fetching conversion 3  6" \
1174    2 \
1175    "L 2 56789a123456789b123456789c|\n...\nL 2 56789a123456789b123456789c\n" \
1176    ./fetchlog -f 1:50:71:3 ${logfile} ${bm}
1177
1178expect "fetching conversion 3  7" \
1179    2 \
1180    "L 2 56789a123456789b123456789c|\n...c\nL 2 56789a123456789b123456789c\n" \
1181    ./fetchlog -f 1:50:72:3 ${logfile} ${bm}
1182
1183expect "fetching conversion 3  8" \
1184    2 \
1185    "L 2 56789a123456789b12345678~|\n...~\nL 2 56789a123456789b12345678~\n" \
1186    ./fetchlog -f 1:29:70:3 ${logfile} ${bm}
1187
1188expect "fetching conversion 3  9" \
1189    2 \
1190    "L 2 56789a123456789b123456789c|\n...56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n" \
1191    ./fetchlog -f 1:30:97:3 ${logfile} ${bm}
1192
1193expect "fetching conversion 3  10" \
1194    2 \
1195    "L 2 56789a123456789b123456789c|\nL 1 56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n" \
1196    ./fetchlog -f 1:30:98:3 ${logfile} ${bm}
1197
1198expect "fetching conversion 3  11" \
1199    2 \
1200    "L 2 56789a123456789b123456789c|\nL 1 56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n" \
1201    ./fetchlog -f 1:30:99:3 ${logfile} ${bm}
1202
1203expect "fetching conversion 3  12" \
1204    2 \
1205    "L 2 56789a123456789b123456789c|\nL 1 56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n" \
1206    ./fetchlog -f 1:30:100:3 ${logfile} ${bm}
1207
1208echo >> ${logfile}
1209
1210expect "fetching conversion 3  13" \
1211    2 \
1212    "|\nL 1 56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n\n" \
1213    ./fetchlog -f 1:30:100:3 ${logfile} ${bm}
1214
1215echo "bla" >> ${logfile}
1216
1217expect "fetching conversion 3  14" \
1218    2 \
1219    "bla|\nL 1 56789a123456789b123456789c\nL 2 56789a123456789b123456789c\n\nbla\n" \
1220    ./fetchlog -f 1:30:100:3 ${logfile} ${bm}
1221
1222echo " "
1223echo "test-all: all tests ok"
1224echo " "
1225unlink_logs
1226exit 0
1227