7
7
// spell-checker:ignore (words) seekable
8
8
9
9
use crate :: common:: util:: TestScenario ;
10
- #[ cfg( all(
11
- not( target_os = "windows" ) ,
12
- not( target_os = "macos" ) ,
13
- not( target_os = "android" ) ,
14
- not( target_os = "freebsd" ) ,
15
- not( target_os = "openbsd" )
16
- ) ) ]
17
- use std:: io:: Read ;
18
10
19
11
static INPUT : & str = "lorem_ipsum.txt" ;
20
12
@@ -408,36 +400,36 @@ fn test_all_but_last_bytes_large_file_piped() {
408
400
let fixtures = & scene. fixtures ;
409
401
410
402
// First, create all our fixtures.
411
- let seq_20000_file_name = "seq_20000 " ;
412
- let seq_19000_file_name = "seq_19000 " ;
413
- let seq_19001_20000_file_name = "seq_19001_20000 " ;
403
+ let seq_30000_file_name = "seq_30000 " ;
404
+ let seq_29000_file_name = "seq_29000 " ;
405
+ let seq_29001_30000_file_name = "seq_29001_30000 " ;
414
406
scene
415
407
. cmd ( "seq" )
416
- . arg ( "20000 " )
417
- . set_stdout ( fixtures. make_file ( seq_20000_file_name ) )
408
+ . arg ( "30000 " )
409
+ . set_stdout ( fixtures. make_file ( seq_30000_file_name ) )
418
410
. succeeds ( ) ;
419
411
scene
420
412
. cmd ( "seq" )
421
- . arg ( "19000 " )
422
- . set_stdout ( fixtures. make_file ( seq_19000_file_name ) )
413
+ . arg ( "29000 " )
414
+ . set_stdout ( fixtures. make_file ( seq_29000_file_name ) )
423
415
. succeeds ( ) ;
424
416
scene
425
417
. cmd ( "seq" )
426
- . args ( & [ "19001 " , "20000 " ] )
427
- . set_stdout ( fixtures. make_file ( seq_19001_20000_file_name ) )
418
+ . args ( & [ "29001 " , "30000 " ] )
419
+ . set_stdout ( fixtures. make_file ( seq_29001_30000_file_name ) )
428
420
. succeeds ( ) ;
429
421
430
- let seq_19001_20000_file_length = fixtures
431
- . open ( seq_19001_20000_file_name )
422
+ let seq_29001_30000_file_length = fixtures
423
+ . open ( seq_29001_30000_file_name )
432
424
. metadata ( )
433
425
. unwrap ( )
434
426
. len ( ) ;
435
427
scene
436
428
. ucmd ( )
437
- . args ( & [ "-c" , & format ! ( "-{}" , seq_19001_20000_file_length ) ] )
438
- . pipe_in_fixture ( seq_20000_file_name )
429
+ . args ( & [ "-c" , & format ! ( "-{}" , seq_29001_30000_file_length ) ] )
430
+ . pipe_in_fixture ( seq_30000_file_name )
439
431
. succeeds ( )
440
- . stdout_only_fixture ( seq_19000_file_name ) ;
432
+ . stdout_only_fixture ( seq_29000_file_name ) ;
441
433
}
442
434
443
435
#[ test]
@@ -447,12 +439,12 @@ fn test_all_but_last_lines_large_file() {
447
439
// than that.
448
440
let scene = TestScenario :: new ( util_name ! ( ) ) ;
449
441
let fixtures = & scene. fixtures ;
450
- let seq_20000_file_name = "seq_20000 " ;
442
+ let seq_30000_file_name = "seq_30000 " ;
451
443
let seq_1000_file_name = "seq_1000" ;
452
444
scene
453
445
. cmd ( "seq" )
454
- . arg ( "20000 " )
455
- . set_stdout ( fixtures. make_file ( seq_20000_file_name ) )
446
+ . arg ( "30000 " )
447
+ . set_stdout ( fixtures. make_file ( seq_30000_file_name ) )
456
448
. succeeds ( ) ;
457
449
scene
458
450
. cmd ( "seq" )
@@ -463,19 +455,19 @@ fn test_all_but_last_lines_large_file() {
463
455
// Now run our tests.
464
456
scene
465
457
. ucmd ( )
466
- . args ( & [ "-n" , "-19000 " , seq_20000_file_name ] )
458
+ . args ( & [ "-n" , "-29000 " , seq_30000_file_name ] )
467
459
. succeeds ( )
468
460
. stdout_only_fixture ( "seq_1000" ) ;
469
461
470
462
scene
471
463
. ucmd ( )
472
- . args ( & [ "-n" , "-20000 " , seq_20000_file_name ] )
464
+ . args ( & [ "-n" , "-30000 " , seq_30000_file_name ] )
473
465
. succeeds ( )
474
466
. stdout_only_fixture ( "emptyfile.txt" ) ;
475
467
476
468
scene
477
469
. ucmd ( )
478
- . args ( & [ "-n" , "-20001 " , seq_20000_file_name ] )
470
+ . args ( & [ "-n" , "-30001 " , seq_30000_file_name ] )
479
471
. succeeds ( )
480
472
. stdout_only_fixture ( "emptyfile.txt" ) ;
481
473
}
@@ -503,56 +495,14 @@ fn test_validate_stdin_offset_lines() {
503
495
let scene = TestScenario :: new ( util_name ! ( ) ) ;
504
496
let fixtures = & scene. fixtures ;
505
497
506
- // Test 1 - Print the first n lines
507
- fixtures. write ( "f1" , "a\n b\n c\n " ) ;
508
- let file = fixtures. open ( "f1" ) ;
509
- let mut file_shadow = file. try_clone ( ) . unwrap ( ) ;
510
- scene
511
- . ucmd ( )
512
- . args ( & [ "-n" , "1" ] )
513
- . set_stdin ( file)
514
- . succeeds ( )
515
- . stdout_only ( "a\n " ) ;
516
- let mut bytes_remaining_in_stdin = vec ! [ ] ;
517
- assert_eq ! (
518
- file_shadow
519
- . read_to_end( & mut bytes_remaining_in_stdin)
520
- . unwrap( ) ,
521
- 4
522
- ) ;
523
- assert_eq ! (
524
- String :: from_utf8( bytes_remaining_in_stdin) . unwrap( ) ,
525
- "b\n c\n "
526
- ) ;
527
-
528
- // Test 2 - Print all-but the last n lines
529
- fixtures. write ( "f2" , "a\n b\n c\n " ) ;
530
- let file = fixtures. open ( "f2" ) ;
531
- let mut file_shadow = file. try_clone ( ) . unwrap ( ) ;
532
- scene
533
- . ucmd ( )
534
- . args ( & [ "-n" , "-1" ] )
535
- . set_stdin ( file)
536
- . succeeds ( )
537
- . stdout_only ( "a\n b\n " ) ;
538
- let mut bytes_remaining_in_stdin = vec ! [ ] ;
539
- assert_eq ! (
540
- file_shadow
541
- . read_to_end( & mut bytes_remaining_in_stdin)
542
- . unwrap( ) ,
543
- 2
544
- ) ;
545
- assert_eq ! ( String :: from_utf8( bytes_remaining_in_stdin) . unwrap( ) , "c\n " ) ;
546
-
547
- // Test 3 - Print all but the last n lines, large input file.
548
498
// First, create all our fixtures.
549
- let seq_20000_file_name = "seq_20000 " ;
499
+ let seq_30000_file_name = "seq_30000 " ;
550
500
let seq_1000_file_name = "seq_1000" ;
551
- let seq_1001_20000_file_name = "seq_1001_20000 " ;
501
+ let seq_1001_30000_file_name = "seq_1001_30000 " ;
552
502
scene
553
503
. cmd ( "seq" )
554
- . arg ( "20000 " )
555
- . set_stdout ( fixtures. make_file ( seq_20000_file_name ) )
504
+ . arg ( "30000 " )
505
+ . set_stdout ( fixtures. make_file ( seq_30000_file_name ) )
556
506
. succeeds ( ) ;
557
507
scene
558
508
. cmd ( "seq" )
@@ -561,23 +511,54 @@ fn test_validate_stdin_offset_lines() {
561
511
. succeeds ( ) ;
562
512
scene
563
513
. cmd ( "seq" )
564
- . args ( & [ "1001" , "20000 " ] )
565
- . set_stdout ( fixtures. make_file ( seq_1001_20000_file_name ) )
514
+ . args ( & [ "1001" , "30000 " ] )
515
+ . set_stdout ( fixtures. make_file ( seq_1001_30000_file_name ) )
566
516
. succeeds ( ) ;
567
517
568
- let file = fixtures. open ( seq_20000_file_name) ;
518
+ // Test 1 - Print the first n lines
519
+ let file = fixtures. open ( "lorem_ipsum.txt" ) ;
520
+ let file_shadow = file. try_clone ( ) . unwrap ( ) ;
521
+ scene
522
+ . ucmd ( )
523
+ . args ( & [ "-n" , "1" ] )
524
+ . set_stdin ( file)
525
+ . succeeds ( )
526
+ . stdout_only_fixture ( "lorem_ipsum_1_line.expected" ) ;
527
+ scene
528
+ . cmd ( "cat" )
529
+ . set_stdin ( file_shadow)
530
+ . succeeds ( )
531
+ . stdout_only_fixture ( "lorem_ipsum_1_line.remaining" ) ;
532
+
533
+ // Test 2 - Print all-but the last n lines
534
+ let file = fixtures. open ( "lorem_ipsum.txt" ) ;
535
+ let file_shadow = file. try_clone ( ) . unwrap ( ) ;
536
+ scene
537
+ . ucmd ( )
538
+ . args ( & [ "-n" , "-15" ] )
539
+ . set_stdin ( file)
540
+ . succeeds ( )
541
+ . stdout_only_fixture ( "lorem_ipsum_backwards_15_lines.expected" ) ;
542
+ scene
543
+ . cmd ( "cat" )
544
+ . set_stdin ( file_shadow)
545
+ . succeeds ( )
546
+ . stdout_only_fixture ( "lorem_ipsum_backwards_15_lines.remaining" ) ;
547
+
548
+ // Test 3 - Print all but the last n lines, large input file.
549
+ let file = fixtures. open ( seq_30000_file_name) ;
569
550
let file_shadow = file. try_clone ( ) . unwrap ( ) ;
570
551
scene
571
552
. ucmd ( )
572
- . args ( & [ "-n" , "-19000 " ] )
553
+ . args ( & [ "-n" , "-29000 " ] )
573
554
. set_stdin ( file)
574
555
. succeeds ( )
575
556
. stdout_only_fixture ( seq_1000_file_name) ;
576
557
scene
577
558
. cmd ( "cat" )
578
559
. set_stdin ( file_shadow)
579
560
. succeeds ( )
580
- . stdout_only_fixture ( seq_1001_20000_file_name ) ;
561
+ . stdout_only_fixture ( seq_1001_30000_file_name ) ;
581
562
}
582
563
583
564
#[ cfg( all(
@@ -604,105 +585,90 @@ fn test_validate_stdin_offset_bytes() {
604
585
let scene = TestScenario :: new ( util_name ! ( ) ) ;
605
586
let fixtures = & scene. fixtures ;
606
587
588
+ // First, create all our fixtures.
589
+ let seq_30000_file_name = "seq_30000" ;
590
+ let seq_29000_file_name = "seq_29000" ;
591
+ let seq_29001_30000_file_name = "seq_29001_30000" ;
592
+ scene
593
+ . cmd ( "seq" )
594
+ . arg ( "30000" )
595
+ . set_stdout ( fixtures. make_file ( seq_30000_file_name) )
596
+ . succeeds ( ) ;
597
+ scene
598
+ . cmd ( "seq" )
599
+ . arg ( "29000" )
600
+ . set_stdout ( fixtures. make_file ( seq_29000_file_name) )
601
+ . succeeds ( ) ;
602
+ scene
603
+ . cmd ( "seq" )
604
+ . args ( & [ "29001" , "30000" ] )
605
+ . set_stdout ( fixtures. make_file ( seq_29001_30000_file_name) )
606
+ . succeeds ( ) ;
607
+
607
608
// Test 1 - Print the first n bytes
608
- fixtures. write ( "f1" , "abc\n def\n " ) ;
609
- let file = fixtures. open ( "f1" ) ;
610
- let mut file_shadow = file. try_clone ( ) . unwrap ( ) ;
609
+ let file = fixtures. open ( "lorem_ipsum.txt" ) ;
610
+ let file_shadow = file. try_clone ( ) . unwrap ( ) ;
611
611
scene
612
612
. ucmd ( )
613
- . args ( & [ "-c" , "2 " ] )
613
+ . args ( & [ "-c" , "5 " ] )
614
614
. set_stdin ( file)
615
615
. succeeds ( )
616
- . stdout_only ( "ab" ) ;
617
- let mut bytes_remaining_in_stdin = vec ! [ ] ;
618
- assert_eq ! (
619
- file_shadow
620
- . read_to_end( & mut bytes_remaining_in_stdin)
621
- . unwrap( ) ,
622
- 6
623
- ) ;
624
- assert_eq ! (
625
- String :: from_utf8( bytes_remaining_in_stdin) . unwrap( ) ,
626
- "c\n def\n "
627
- ) ;
616
+ . stdout_only_fixture ( "lorem_ipsum_5_chars.expected" ) ;
617
+ scene
618
+ . cmd ( "cat" )
619
+ . set_stdin ( file_shadow)
620
+ . succeeds ( )
621
+ . stdout_only_fixture ( "lorem_ipsum_5_chars.remaining" ) ;
628
622
629
623
// Test 2 - Print all-but the last n bytes
630
- fixtures. write ( "f2" , "abc\n def\n " ) ;
631
- let file = fixtures. open ( "f2" ) ;
632
- let mut file_shadow = file. try_clone ( ) . unwrap ( ) ;
624
+ let file = fixtures. open ( "lorem_ipsum.txt" ) ;
625
+ let file_shadow = file. try_clone ( ) . unwrap ( ) ;
633
626
scene
634
627
. ucmd ( )
635
- . args ( & [ "-c" , "-3 " ] )
628
+ . args ( & [ "-c" , "-10 " ] )
636
629
. set_stdin ( file)
637
630
. succeeds ( )
638
- . stdout_only ( "abc\n d" ) ;
639
- let mut bytes_remaining_in_stdin = vec ! [ ] ;
640
- assert_eq ! (
641
- file_shadow
642
- . read_to_end( & mut bytes_remaining_in_stdin)
643
- . unwrap( ) ,
644
- 3
645
- ) ;
646
- assert_eq ! ( String :: from_utf8( bytes_remaining_in_stdin) . unwrap( ) , "ef\n " ) ;
631
+ . stdout_only_fixture ( "lorem_ipsum_backwards_file.expected" ) ;
632
+ scene
633
+ . cmd ( "cat" )
634
+ . set_stdin ( file_shadow)
635
+ . succeeds ( )
636
+ . stdout_only_fixture ( "lorem_ipsum_backwards_file.remaining" ) ;
647
637
648
638
// Test 3 - Print all-but the last n bytes, n=0 (i.e. print everything)
649
- fixtures. write ( "f3" , "abc\n def\n " ) ;
650
- let file = fixtures. open ( "f3" ) ;
651
- let mut file_shadow = file. try_clone ( ) . unwrap ( ) ;
639
+ let file = fixtures. open ( "lorem_ipsum.txt" ) ;
640
+ let file_shadow = file. try_clone ( ) . unwrap ( ) ;
652
641
scene
653
642
. ucmd ( )
654
643
. args ( & [ "-c" , "-0" ] )
655
644
. set_stdin ( file)
656
645
. succeeds ( )
657
- . stdout_only ( "abc\n def\n " ) ;
658
- let mut bytes_remaining_in_stdin = vec ! [ ] ;
659
- assert_eq ! (
660
- file_shadow
661
- . read_to_end( & mut bytes_remaining_in_stdin)
662
- . unwrap( ) ,
663
- 0
664
- ) ;
665
- assert_eq ! ( String :: from_utf8( bytes_remaining_in_stdin) . unwrap( ) , "" ) ;
666
-
667
- // Test 4 - Print all but the last n bytes, large input file.
668
- // First, create all our fixtures.
669
- let seq_20000_file_name = "seq_20000" ;
670
- let seq_19000_file_name = "seq_19000" ;
671
- let seq_19001_20000_file_name = "seq_19001_20000" ;
672
- scene
673
- . cmd ( "seq" )
674
- . arg ( "20000" )
675
- . set_stdout ( fixtures. make_file ( seq_20000_file_name) )
676
- . succeeds ( ) ;
646
+ . stdout_only_fixture ( "lorem_ipsum.txt" ) ;
677
647
scene
678
- . cmd ( "seq" )
679
- . arg ( "19000" )
680
- . set_stdout ( fixtures. make_file ( seq_19000_file_name) )
681
- . succeeds ( ) ;
682
- scene
683
- . cmd ( "seq" )
684
- . args ( & [ "19001" , "20000" ] )
685
- . set_stdout ( fixtures. make_file ( seq_19001_20000_file_name) )
686
- . succeeds ( ) ;
648
+ . cmd ( "cat" )
649
+ . set_stdin ( file_shadow)
650
+ . succeeds ( )
651
+ . stdout_only_fixture ( "emptyfile.txt" ) ;
687
652
688
- let file = fixtures. open ( seq_20000_file_name) ;
653
+ // Test 4 - Print all but the last n bytes, large input file.
654
+ let file = fixtures. open ( "seq_30000" ) ;
689
655
let file_shadow = file. try_clone ( ) . unwrap ( ) ;
690
- let seq_19001_20000_file_length = fixtures
691
- . open ( seq_19001_20000_file_name )
656
+ let seq_29001_30000_file_length = fixtures
657
+ . open ( seq_29001_30000_file_name )
692
658
. metadata ( )
693
659
. unwrap ( )
694
660
. len ( ) ;
695
661
scene
696
662
. ucmd ( )
697
- . args ( & [ "-c" , & format ! ( "-{}" , seq_19001_20000_file_length ) ] )
663
+ . args ( & [ "-c" , & format ! ( "-{}" , seq_29001_30000_file_length ) ] )
698
664
. set_stdin ( file)
699
665
. succeeds ( )
700
- . stdout_only_fixture ( seq_19000_file_name ) ;
666
+ . stdout_only_fixture ( seq_29000_file_name ) ;
701
667
scene
702
668
. cmd ( "cat" )
703
669
. set_stdin ( file_shadow)
704
670
. succeeds ( )
705
- . stdout_only_fixture ( seq_19001_20000_file_name ) ;
671
+ . stdout_only_fixture ( seq_29001_30000_file_name ) ;
706
672
}
707
673
708
674
#[ cfg( all(
0 commit comments