File: test_cmds.sh

package info (click to toggle)
lnav 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,536 kB
  • ctags: 4,798
  • sloc: cpp: 37,738; sh: 6,871; ansic: 5,090; makefile: 670; python: 196; sql: 67
file content (781 lines) | stat: -rw-r--r-- 24,378 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#! /bin/bash

run_test ${lnav_test} -n \
    -c ":config /bad/option" \
    ${test_dir}/logfile_access_log.0

check_error_output "config bad option" <<EOF
error: unknown configuration option -- /bad/option
EOF

check_output "config bad option" <<EOF
EOF

run_test ${lnav_test} -nvq \
    -c ":config /ui/clock-format" \
    ${test_dir}/logfile_access_log.0

check_error_output "config clock-format" <<EOF
EOF

check_output "config clock-format" <<EOF
info: /ui/clock-format = "%a %b %d %H:%M:%S %Z"
EOF

run_test ${lnav_test} -nvq \
    -c ":config /ui/clock-format" \
    -c ":config /ui/clock-format abc" \
    -c ":config /ui/clock-format" \
    ${test_dir}/logfile_access_log.0

check_error_output "config clock-format" <<EOF
EOF

check_output "config clock-format" <<EOF
info: /ui/clock-format = "%a %b %d %H:%M:%S %Z"
info: changed config option -- /ui/clock-format
info: /ui/clock-format = "abc"
EOF

run_test ${lnav_test} -nvq \
    -c ":config /ui/clock-format abc" \
    -c ":reset-config /ui/clock-format" \
    -c ":config /ui/clock-format" \
    ${test_dir}/logfile_access_log.0

check_error_output "config clock-format" <<EOF
EOF

check_output "config clock-format" <<EOF
info: changed config option -- /ui/clock-format
info: reset option
info: /ui/clock-format = "%a %b %d %H:%M:%S %Z"
EOF


run_test ${lnav_test} -n \
    -c "|${test_dir}/toplevel.lnav 123 456 789" \
    ${test_dir}/logfile_access_log.0

check_error_output "include toplevel.lnav" <<EOF
EOF

check_output "include toplevel.lnav" <<EOF
toplevel here 123 456
nested here nested.lnav abc 789
EOF


run_test ${lnav_test} -n \
    -f "nonexistent.lnav" \
    ${test_dir}/logfile_access_log.0

check_error_output "include nonexistent" <<EOF
error: unknown script -- nonexistent.lnav -- file not found
EOF


run_test ${lnav_test} -n \
    -c ":adjust-log-time 2010-01-01T00:00:00" \
    ${test_dir}/logfile_access_log.0

check_output "adjust-log-time is not working" <<EOF
192.168.202.254 - - [01/Jan/2010:00:00:00 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
192.168.202.254 - - [01/Jan/2010:00:00:03 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [01/Jan/2010:00:00:03 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":goto 1" \
    ${test_dir}/logfile_access_log.0

check_output "goto 1 is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":goto -1" \
    ${test_dir}/logfile_access_log.0

check_output "goto -1 is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":goto 2 hours later" \
    ${test_dir}/logfile_syslog_with_mixed_times.0

check_output "goto 3:45 is not working?" <<EOF
Sep 13 03:12:04 Tim-Stacks-iMac kernel[0]: vm_compressor_record_warmup (9478314 - 9492476)
Sep 13 03:12:04 Tim-Stacks-iMac kernel[0]: AppleBCM5701Ethernet [en0]:        0        0 memWrInd fBJP_Wakeup_Timer
Sep 13 01:25:39 Tim-Stacks-iMac kernel[0]: AppleThunderboltNHIType2::waitForOk2Go2Sx - retries = 60000
Sep 13 03:12:04 Tim-Stacks-iMac kernel[0]: hibernate_page_list_setall(preflight 0) start 0xffffff8428276000, 0xffffff8428336000
Sep 13 03:12:58 Tim-Stacks-iMac kernel[0]: *** kernel exceeded 500 log message per second limit  -  remaining messages this second discarded ***
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: IOThunderboltSwitch<0xffffff803f4b3000>(0x0)::listenerCallback - Thunderbolt HPD packet for route = 0x0 port = 11 unplug = 0
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: vm_compressor_flush - starting
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: AppleBCM5701Ethernet [en0]:        0        0 memWrInd fBJP_Wakeup_Timer
Sep 13 03:13:16 Tim-Stacks-iMac kernel[0]: AppleThunderboltNHIType2::waitForOk2Go2Sx - retries = 60000
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: hibernate_page_list_setall(preflight 0) start 0xffffff838f1fc000, 0xffffff838f2bc000
EOF


run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":goto 3:45" \
    ${test_dir}/logfile_syslog_with_mixed_times.0

check_output "goto 3:45 is not working?" <<EOF
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: IOThunderboltSwitch<0xffffff803f4b3000>(0x0)::listenerCallback - Thunderbolt HPD packet for route = 0x0 port = 11 unplug = 0
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: vm_compressor_flush - starting
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: AppleBCM5701Ethernet [en0]:        0        0 memWrInd fBJP_Wakeup_Timer
Sep 13 03:13:16 Tim-Stacks-iMac kernel[0]: AppleThunderboltNHIType2::waitForOk2Go2Sx - retries = 60000
Sep 13 03:46:03 Tim-Stacks-iMac kernel[0]: hibernate_page_list_setall(preflight 0) start 0xffffff838f1fc000, 0xffffff838f2bc000
EOF


run_test ${lnav_test} -n \
    -c ":goto invalid" \
    ${test_dir}/logfile_access_log.0

check_error_output "goto invalid is working" <<EOF
error: expecting line number/percentage, timestamp, or relative time
EOF

check_output "goto invalid is not working" <<EOF
EOF


run_test ${lnav_test} -n \
    -c ":goto 1" \
    -c ":relative-goto -1" \
    ${test_dir}/logfile_access_log.0

check_output "relative-goto -1 is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":next-mark error" \
    ${test_dir}/logfile_access_log.0

check_output "next-mark error is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF

run_test ${lnav_test} -n \
    -c ":goto -1" \
    -c ":prev-mark error" \
    ${test_dir}/logfile_access_log.0

check_output "prev-mark error is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF

run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":next-mark foobar" \
    ${test_dir}/logfile_access_log.0

check_error_output "goto invalid is not working" <<EOF
error: unknown bookmark type
EOF

check_output "invalid mark-type is working" <<EOF
EOF


run_test ${lnav_test} -n \
    -c ":filter-in vmk" \
    ${test_dir}/logfile_access_log.0

check_output "filter-in vmk is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":filter-in vmk" \
    -c ":reset-session" \
    -c ":filter-in cgi" \
    ${test_dir}/logfile_access_log.0

check_output "filter-in vmk is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":filter-in today" \
    ${test_dir}/logfile_multiline.0

check_output "filter-in multiline is not working" <<EOF
2009-07-20 22:59:27,672:DEBUG:Hello, World!
  How are you today?
EOF


run_test ${lnav_test} -n \
    -c ":filter-out vmk" \
    ${test_dir}/logfile_access_log.0

check_output "filter-out vmk is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
EOF


run_test ${lnav_test} -n \
    -c ":filter-out today" \
    ${test_dir}/logfile_multiline.0

check_output "filter-out multiline is not working" <<EOF
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
EOF

cp ${test_dir}/logfile_multiline.0 logfile_append.0
chmod ug+w logfile_append.0

run_test ${lnav_test} -n \
    -c ";update generic_log set log_mark=1" \
    -c ":filter-in Goodbye" \
    -c ":append-to logfile_append.0" \
    -c ":rebuild" \
    logfile_append.0

check_output "filter-in append is not working" <<EOF
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
EOF

cp ${test_dir}/logfile_multiline.0 logfile_append.0
chmod ug+w logfile_append.0

run_test ${lnav_test} -n \
    -c ":filter-out Goodbye" \
    -c ":shexec echo '2009-07-20 22:59:30,221:ERROR:Goodbye, World!' >> logfile_append.0" \
    -c ":rebuild" \
    logfile_append.0

check_output "filter-out append is not working" <<EOF
2009-07-20 22:59:27,672:DEBUG:Hello, World!
  How are you today?
EOF


run_test ${lnav_test} -n \
    -c ":filter-in avahi" \
    -c ":delete-filter avahi" \
    -c ":filter-in avahi" \
    -c ":filter-in dnsmasq" \
    ${test_dir}/logfile_filter.0

check_output "multiple filter-in is not working" <<EOF
Dec  6 13:01:34 ubu-mac avahi-daemon[786]: Joining mDNS multicast group on interface virbr0.IPv4 with address 192.168.122.1.
Dec  6 13:01:34 ubu-mac avahi-daemon[786]: New relevant interface virbr0.IPv4 for mDNS.
Dec  6 13:01:34 ubu-mac avahi-daemon[786]: Registering new address record for 192.168.122.1 on virbr0.IPv4.
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: started, version 2.68 cachesize 150
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
Dec  6 13:01:34 ubu-mac dnsmasq-dhcp[1840]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Dec  6 13:01:34 ubu-mac dnsmasq-dhcp[1840]: DHCP, sockets bound exclusively to interface virbr0
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: reading /etc/resolv.conf
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: using nameserver 192.168.1.1#53
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: read /etc/hosts - 5 addresses
Dec  6 13:01:34 ubu-mac dnsmasq[1840]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Dec  6 13:01:34 ubu-mac dnsmasq-dhcp[1840]: read /var/lib/libvirt/dnsmasq/default.hostsfile
EOF


run_test ${lnav_test} -n \
    -c ":switch-to-view text" \
    -c ":filter-in World" \
    ${test_dir}/logfile_plain.0
check_output "plain text filter-in is not working" <<EOF
Hello, World!
Goodbye, World!
EOF

run_test ${lnav_test} -n \
    -c ":switch-to-view text" \
    -c ":filter-out World" \
    ${test_dir}/logfile_plain.0
check_output "plain text filter-out is not working" <<EOF
How are you?
EOF


TOO_MANY_FILTERS=""
for i in `seq 1 33`; do
    TOO_MANY_FILTERS="$TOO_MANY_FILTERS -c ':filter-out $i'"
done
run_test eval ${lnav_test} -d /tmp/lnav.err -n \
    $TOO_MANY_FILTERS \
    ${test_dir}/logfile_filter.0
check_error_output "able to create too many filters?" <<EOF
error: filter limit reached, try combining filters with a pipe symbol (e.g. foo|bar)
EOF


run_test ${lnav_test} -n \
    -c ":switch-to-view help" \
    ${test_dir}/logfile_access_log.0

check_output "switch-to-view help is not working" < ${top_srcdir}/src/help.txt


run_test ${lnav_test} -n \
    -c ":close" \
    ${test_dir}/logfile_access_log.0

check_output "close is not working" <<EOF
EOF


run_test ${lnav_test} -n \
    -c ":close" \
    -c ":close" \
    ${test_dir}/logfile_access_log.0

check_error_output "double close works" <<EOF
error: no log files loaded
EOF

check_output "double close is working" <<EOF
EOF


run_test ${lnav_test} -n \
    -c ":close" \
    -c ":open ${test_dir}/logfile_multiline.0" \
    ${test_dir}/logfile_access_log.0

check_output "open is not working" <<EOF
2009-07-20 22:59:27,672:DEBUG:Hello, World!
  How are you today?
2009-07-20 22:59:30,221:ERROR:Goodbye, World!
EOF


run_test ${lnav_test} -n \
    -c ":close" \
    -c ":open /non-existent" \
    ${test_dir}/logfile_access_log.0

check_error_output "open non-existent is working" <<EOF
error: cannot stat file: /non-existent -- No such file or directory
EOF

check_output "open non-existent is not working" <<EOF
EOF


run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":close" \
    -c ":goto 0" \
    "${test_dir}/logfile_access_log.*"

check_output "close not sticking" <<EOF
10.112.81.15 - - [15/Feb/2013:06:00:31 +0000] "-" 400 0 "-" "-"
EOF


run_test ${lnav_test} -n \
    -c ";select * from access_log" \
    -c ':write-json-to -' \
    ${test_dir}/logfile_access_log.0



check_output "write-json-to is not working" <<EOF
[
    {
        "log_line": 0,
        "log_part": null,
        "log_time": "2009-07-20 22:59:26.000",
        "log_idle_msecs": 0,
        "log_level": "info",
        "log_mark": 0,
        "c_ip": "192.168.202.254",
        "cs_method": "GET",
        "cs_referer": "-",
        "cs_uri_query": null,
        "cs_uri_stem": "/vmw/cgi/tramp",
        "cs_user_agent": "gPXE/0.9.7",
        "cs_username": "-",
        "cs_version": "HTTP/1.0",
        "sc_bytes": 134,
        "sc_status": 200
    },
    {
        "log_line": 1,
        "log_part": null,
        "log_time": "2009-07-20 22:59:29.000",
        "log_idle_msecs": 3000,
        "log_level": "error",
        "log_mark": 0,
        "c_ip": "192.168.202.254",
        "cs_method": "GET",
        "cs_referer": "-",
        "cs_uri_query": null,
        "cs_uri_stem": "/vmw/vSphere/default/vmkboot.gz",
        "cs_user_agent": "gPXE/0.9.7",
        "cs_username": "-",
        "cs_version": "HTTP/1.0",
        "sc_bytes": 46210,
        "sc_status": 404
    },
    {
        "log_line": 2,
        "log_part": null,
        "log_time": "2009-07-20 22:59:29.000",
        "log_idle_msecs": 0,
        "log_level": "info",
        "log_mark": 0,
        "c_ip": "192.168.202.254",
        "cs_method": "GET",
        "cs_referer": "-",
        "cs_uri_query": null,
        "cs_uri_stem": "/vmw/vSphere/default/vmkernel.gz",
        "cs_user_agent": "gPXE/0.9.7",
        "cs_username": "-",
        "cs_version": "HTTP/1.0",
        "sc_bytes": 78929,
        "sc_status": 200
    }
]
EOF


# By setting the LNAVSECURE mode before executing the command, we will disable
# the access to the write-json-to command and the output would just be the
# actual display of select query rather than json output.
export LNAVSECURE=1
run_test ${lnav_test} -n \
    -c ";select * from access_log" \
    -c ':write-json-to -' \
    ${test_dir}/logfile_access_log.0

check_error_output "We managed to bypass LNAVSECURE mode" <<EOF
error: write-json-to -- unavailable in secure mode
EOF
unset LNAVSECURE

run_test ${lnav_test} -n \
    -c ";update generic_log set log_mark=1" \
    -c ":pipe-to sed -e 's/World!/Bork!/g' -e 's/2009//g'" \
    ${test_dir}/logfile_multiline.0
check_output "pipe-to is not working" <<EOF
-07-20 22:59:27,672:DEBUG:Hello, Bork!
  How are you today?
-07-20 22:59:30,221:ERROR:Goodbye, Bork!
EOF

run_test ${lnav_test} -n \
    -c ":goto 2" \
    -c ":pipe-line-to sed -e 's/World!/Bork!/g' -e 's/2009//g'" \
    ${test_dir}/logfile_multiline.0
check_output "pipe-line-to is not working" <<EOF
-07-20 22:59:30,221:ERROR:Goodbye, Bork!
EOF

run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":pipe-line-to echo \$cs_uri_stem \$sc_status" \
    ${test_dir}/logfile_access_log.0
check_output "pipe-line-to env vars are not working" <<EOF
/vmw/cgi/tramp 200
EOF


run_test ${lnav_test} -n \
    -c ":switch-to-view pretty" \
    ${test_dir}/textfile_json_one_line.0
check_output "pretty-printer is not working for text files" <<EOF
{
    "foo bar" : null,
    "array" : [
        1,
        2,
        3
    ],
    "obj" : {
        "one" : 1,
        "two" : true
    }
}
EOF

run_test ${lnav_test} -n \
    -c ":switch-to-view pretty" \
    ${test_dir}/textfile_json_one_line.0
check_output "pretty-printer is not working for indented text files" <<EOF
{
  "foo bar": null,
  "array": [
    1,
    2,
    3
  ],
  "obj": {
    "one": 1,
    "two": true
  }
}
EOF

run_test ${lnav_test} -n \
    -c ":switch-to-view pretty" \
    ${test_dir}/textfile_quoted_json.0
check_output "pretty-printer is not working for quoted text" <<EOF
{
  "foo bar": null,
  "array": [
    1,
    2,
    3
  ],
  "obj": {
    "one": 1,
    "two": true
  }
}
EOF

run_test ${lnav_test} -n \
    -c ":switch-to-view pretty" \
    ${test_dir}/logfile_vami.0
check_output "pretty-printer is not working" <<EOF
2015-03-12T23:16:52.071:INFO:com.root:Response :

<?xml version="1.0"?>
<response>
    <locale>en-US</locale>
    <requestid>ipInfo</requestid>
    <value id="ipv4Gateway" actions="enabled">198.51.100.253 (unknown)</value>
    <value id="ipv6Gateway" actions="enabled"/>
    <value id="ipv6Enabled" actions="enabled">true</value>
    <value id="ipv4Enabled" actions="enabled">true</value>
    <value id="name" actions="enabled">nic1</value>
    <value id="v4config" actions="enabled">
        <value id="defaultGateway" actions="enabled">0.0.0.0 (unknown)</value>
        <value id="updateable" actions="enabled">True</value>
        <value id="prefix" actions="enabled">22</value>
        <value id="mode" actions="enabled">dhcp</value>
        <value id="address" actions="enabled">198.51.100.110 (unknown)</value>
        <value id="interface" actions="enabled">nic1</value>
    </value>
    <value id="v6config" actions="enabled">
        <value id="defaultGateway" actions="enabled">fe80::214:f609:19f7:6bf1 (unknown)</value>
        <value id="updateable" actions="enabled">True</value>
        <value id="interface" actions="enabled">nic1</value>
        <value id="dhcp" actions="enabled">False</value>
        <value id="autoconf" actions="enabled">False</value>
        <value id="addresses" actions="enabled">
            <value id="origin" actions="enabled">other</value>
            <value id="status" actions="enabled">preferred</value>
            <value id="prefix" actions="enabled">64</value>
            <value id="address" actions="enabled">fe80::250:56ff:feaa:5abf (unknown)</value>
        </value>
    </value>
    <value id="interfaceInfo" actions="enabled">
        <value id="status" actions="enabled">up</value>
        <value id="mac" actions="enabled">00:50:56:aa:5a:bf</value>
        <value id="name" actions="enabled">nic1</value>
    </value>
</response>
EOF


run_test ${lnav_test} -n \
    -c ":goto 0" \
    -c ":switch-to-view pretty" \
    ${test_dir}/logfile_pretty.0
check_output "pretty-printer is not working" <<EOF
Apr  7 00:49:42 Tim-Stacks-iMac kernel[0]: Ethernet [AppleBCM5701Ethernet]: Link up on en0, 1-Gigabit, Full-duplex, Symmetric flow-control, Debug [
    796d,
    2301,
    0de1,
    0300,
    cde1,
    3800
]
Apr  7 05:49:53 Tim-Stacks-iMac.local GoogleSoftwareUpdateDaemon[17212]: -[KSUpdateCheckAction performAction]
 KSUpdateCheckAction running KSServerUpdateRequest:
<KSOmahaServerUpdateRequest:0x511f30
		server=<KSOmahaServer:0x510d80>
    url="https://tools.google.com/service/update2"
    runningFetchers=0
    tickets=1
    activeTickets=1
    rollCallTickets=1
    body=

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <o:gupdate xmlns:o="http://www.google.com/update2/request" protocol="2.0" version="KeystoneDaemon-1.2.0.7709" ismachine="1" requestid="{0DFDBCD1-5E29-4DFC-BD99-31A2397198FE}">
        <o:os platform="mac" version="MacOSX" sp="10.10.2_x86_64h"></o:os>
        <o:app appid="com.google.Keystone" version="1.2.0.7709" lang="en-us" installage="180" brand="GGLG">
            <o:ping r="1" a="1"></o:ping>
            <o:updatecheck></o:updatecheck>
        </o:app>
    </o:gupdate>
    >
Apr  7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: WARNING: The Gestalt selector gestaltSystemVersion is returning 10.9.2 instead of 10.10.2. Use NSProcessInfo's operatingSystemVersion property to get correct system version number.
	Call location:
Apr  7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: 0   CarbonCore                          0x00007fff8a9b3d9b ___Gestalt_SystemVersion_block_invoke + 113
Apr  7 07:31:56 Tim-Stacks-iMac.local VirtualBox[36403]: 1   libdispatch.dylib                   0x00007fff8bc84c13 _dispatch_client_callout + 8
Apr  7 07:32:56 Tim-Stacks-iMac.local logger[234]: Bad data {
    abc,
    123,
    456
)
}]
EOF


run_test ${lnav_test} -n \
    -c ":set-min-log-level error" \
    ${test_dir}/logfile_access_log.0

check_output "set-min-log-level is not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
EOF

run_test ${lnav_test} -n \
    -c ":highlight foobar" \
    -c ":clear-highlight foobar" \
    ${test_dir}/logfile_access_log.0

check_error_output "clear-highlight is not working?" <<EOF
EOF

run_test ${lnav_test} -n \
    -c ":clear-highlight foobar" \
    ${test_dir}/logfile_access_log.0

check_error_output "clear-highlight did not report an error?" <<EOF
error: highlight does not exist
EOF

touch -t 200711030923 ${srcdir}/logfile_syslog.0
run_test ${lnav_test} -n \
    -c ":switch-to-view histogram" \
    -c ":zoom-to 4-hour" \
    ${test_dir}/logfile_syslog.0

check_output "histogram is not working?" <<EOF
 Sat Nov 03 08:00:00          2 normal         2 errors         0 warnings         0 marks
EOF

run_test ${lnav_test} -n \
    -c ":switch-to-view histogram" \
    -c ":zoom-to 1-day" \
    ${test_dir}/logfile_syslog.0

check_output "histogram is not working?" <<EOF
 Sat Nov 03 00:00:00          2 normal         2 errors         0 warnings         0 marks
EOF

run_test ${lnav_test} -n \
    -c ":filter-in sudo" \
    -c ":switch-to-view histogram" \
    -c ":zoom-to 4-hour" \
    ${test_dir}/logfile_syslog.0

check_output "histogram is not working?" <<EOF
 Sat Nov 03 08:00:00          1 normal         0 errors         0 warnings         0 marks
EOF

run_test ${lnav_test} -n \
    -c ":zoom-to bad" \
    ${test_dir}/logfile_access_log.0

check_error_output "bad zoom level is not rejected?" <<EOF
error: invalid zoom level -- bad
EOF


run_test ${lnav_test} -n \
    -f ${test_dir}/multiline.lnav \
    ${test_dir}/logfile_access_log.0

check_output "multiline commands do not work?" <<EOF
Hello: Jules
EOF


printf 'Hello, World!' | run_test ${lnav_test} -n \
  -c ":switch-to-view text"

check_output "stdin with no line feed failed" <<EOF
Hello, World!
EOF


run_test ${lnav_test} -n \
    -c ":hide-lines-before 2009-07-20T22:59:29" \
    ${test_dir}/logfile_access_log.0

check_output "hide-lines-before does not work?" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF

run_test ${lnav_test} -n \
    -c ":hide-lines-after 2009-07-20T22:59:26" \
    ${test_dir}/logfile_access_log.0

check_output "hide-lines-after does not work?" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
EOF

run_test ${lnav_test} -n \
    -c ":hide-lines-after 2009-07-20T22:59:26" \
    -c ":show-lines-before-and-after" \
    ${test_dir}/logfile_access_log.0

check_output "hide-lines-after does not work?" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:26 +0000] "GET /vmw/cgi/tramp HTTP/1.0" 200 134 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF

export XYZ="World"

run_test ${lnav_test} -n \
    -c ':echo Hello, $XYZ!' \
    ${test_dir}/logfile_access_log.0

check_output "echo hello" <<EOF
Hello, \$XYZ!
EOF

export XYZ="World"

run_test ${lnav_test} -n \
    -c ':echo -n Hello, ' \
    -c ':echo World!' \
    ${test_dir}/logfile_access_log.0

check_output "echo hello" <<EOF
Hello, World!
EOF


run_test ${lnav_test} -n \
    -c ':eval :echo Hello, $XYZ!' \
    ${test_dir}/logfile_access_log.0

check_output "eval echo hello" <<EOF
Hello, World!
EOF