@@ -491,6 +491,7 @@ var scriptCmds = map[string]func(*testScript, simpleStatus, []string){
491
491
"go" : (* testScript ).cmdGo ,
492
492
"grep" : (* testScript ).cmdGrep ,
493
493
"mkdir" : (* testScript ).cmdMkdir ,
494
+ "mv" : (* testScript ).cmdMv ,
494
495
"rm" : (* testScript ).cmdRm ,
495
496
"skip" : (* testScript ).cmdSkip ,
496
497
"stale" : (* testScript ).cmdStale ,
@@ -585,10 +586,6 @@ func (ts *testScript) cmdChmod(want simpleStatus, args []string) {
585
586
586
587
// cmp compares two files.
587
588
func (ts * testScript ) cmdCmp (want simpleStatus , args []string ) {
588
- if want != success {
589
- // It would be strange to say "this file can have any content except this precise byte sequence".
590
- ts .fatalf ("unsupported: %v cmp" , want )
591
- }
592
589
quiet := false
593
590
if len (args ) > 0 && args [0 ] == "-q" {
594
591
quiet = true
@@ -597,14 +594,11 @@ func (ts *testScript) cmdCmp(want simpleStatus, args []string) {
597
594
if len (args ) != 2 {
598
595
ts .fatalf ("usage: cmp file1 file2" )
599
596
}
600
- ts .doCmdCmp (args , false , quiet )
597
+ ts .doCmdCmp (want , args , false , quiet )
601
598
}
602
599
603
600
// cmpenv compares two files with environment variable substitution.
604
601
func (ts * testScript ) cmdCmpenv (want simpleStatus , args []string ) {
605
- if want != success {
606
- ts .fatalf ("unsupported: %v cmpenv" , want )
607
- }
608
602
quiet := false
609
603
if len (args ) > 0 && args [0 ] == "-q" {
610
604
quiet = true
@@ -613,17 +607,18 @@ func (ts *testScript) cmdCmpenv(want simpleStatus, args []string) {
613
607
if len (args ) != 2 {
614
608
ts .fatalf ("usage: cmpenv file1 file2" )
615
609
}
616
- ts .doCmdCmp (args , true , quiet )
610
+ ts .doCmdCmp (want , args , true , quiet )
617
611
}
618
612
619
- func (ts * testScript ) doCmdCmp (args []string , env , quiet bool ) {
613
+ func (ts * testScript ) doCmdCmp (want simpleStatus , args []string , env , quiet bool ) {
620
614
name1 , name2 := args [0 ], args [1 ]
621
615
var text1 , text2 string
622
- if name1 == "stdout" {
616
+ switch name1 {
617
+ case "stdout" :
623
618
text1 = ts .stdout
624
- } else if name1 == "stderr" {
619
+ case "stderr" :
625
620
text1 = ts .stderr
626
- } else {
621
+ default :
627
622
data , err := os .ReadFile (ts .mkabs (name1 ))
628
623
ts .check (err )
629
624
text1 = string (data )
@@ -638,14 +633,28 @@ func (ts *testScript) doCmdCmp(args []string, env, quiet bool) {
638
633
text2 = ts .expand (text2 , false )
639
634
}
640
635
641
- if text1 == text2 {
642
- return
643
- }
644
-
645
- if ! quiet {
636
+ eq := text1 == text2
637
+ if ! eq && ! quiet && want != failure {
646
638
fmt .Fprintf (& ts .log , "[diff -%s +%s]\n %s\n " , name1 , name2 , diff (text1 , text2 ))
647
639
}
648
- ts .fatalf ("%s and %s differ" , name1 , name2 )
640
+ switch want {
641
+ case failure :
642
+ if eq {
643
+ ts .fatalf ("%s and %s do not differ" , name1 , name2 )
644
+ }
645
+ case success :
646
+ if ! eq {
647
+ ts .fatalf ("%s and %s differ" , name1 , name2 )
648
+ }
649
+ case successOrFailure :
650
+ if eq {
651
+ fmt .Fprintf (& ts .log , "%s and %s do not differ" , name1 , name2 )
652
+ } else {
653
+ fmt .Fprintf (& ts .log , "%s and %s differ" , name1 , name2 )
654
+ }
655
+ default :
656
+ ts .fatalf ("unsupported: %v cmp" , want )
657
+ }
649
658
}
650
659
651
660
// cp copies files, maybe eventually directories.
@@ -840,6 +849,16 @@ func (ts *testScript) cmdMkdir(want simpleStatus, args []string) {
840
849
}
841
850
}
842
851
852
+ func (ts * testScript ) cmdMv (want simpleStatus , args []string ) {
853
+ if want != success {
854
+ ts .fatalf ("unsupported: %v mv" , want )
855
+ }
856
+ if len (args ) != 2 {
857
+ ts .fatalf ("usage: mv old new" )
858
+ }
859
+ ts .check (os .Rename (ts .mkabs (args [0 ]), ts .mkabs (args [1 ])))
860
+ }
861
+
843
862
// rm removes files or directories.
844
863
func (ts * testScript ) cmdRm (want simpleStatus , args []string ) {
845
864
if want != success {
0 commit comments