@@ -973,6 +973,67 @@ func TestRenameToDirFailed(t *testing.T) {
973
973
}
974
974
}
975
975
976
+ func TestRenameCaseDifference (pt * testing.T ) {
977
+ from , to := "renameFROM" , "RENAMEfrom"
978
+ tests := []struct {
979
+ name string
980
+ create func () error
981
+ }{
982
+ {"dir" , func () error {
983
+ return Mkdir (from , 0777 )
984
+ }},
985
+ {"file" , func () error {
986
+ fd , err := Create (from )
987
+ if err != nil {
988
+ return err
989
+ }
990
+ return fd .Close ()
991
+ }},
992
+ }
993
+
994
+ for _ , test := range tests {
995
+ pt .Run (test .name , func (t * testing.T ) {
996
+ defer chtmpdir (t )()
997
+
998
+ if err := test .create (); err != nil {
999
+ t .Fatalf ("failed to create test file: %s" , err )
1000
+ }
1001
+
1002
+ if _ , err := Stat (to ); err != nil {
1003
+ // Sanity check that the underlying filesystem is not case sensitive.
1004
+ if IsNotExist (err ) {
1005
+ t .Skipf ("case sensitive filesystem" )
1006
+ }
1007
+ t .Fatalf ("stat %q, got: %q" , to , err )
1008
+ }
1009
+
1010
+ if err := Rename (from , to ); err != nil {
1011
+ t .Fatalf ("unexpected error when renaming from %q to %q: %s" , from , to , err )
1012
+ }
1013
+
1014
+ fd , err := Open ("." )
1015
+ if err != nil {
1016
+ t .Fatalf ("Open .: %s" , err )
1017
+ }
1018
+
1019
+ // Stat does not return the real case of the file (it returns what the called asked for)
1020
+ // So we have to use readdir to get the real name of the file.
1021
+ dirNames , err := fd .Readdirnames (- 1 )
1022
+ if err != nil {
1023
+ t .Fatalf ("readdirnames: %s" , err )
1024
+ }
1025
+
1026
+ if dirNamesLen := len (dirNames ); dirNamesLen != 1 {
1027
+ t .Fatalf ("unexpected dirNames len, got %q, want %q" , dirNamesLen , 1 )
1028
+ }
1029
+
1030
+ if dirNames [0 ] != to {
1031
+ t .Errorf ("unexpected name, got %q, want %q" , dirNames [0 ], to )
1032
+ }
1033
+ })
1034
+ }
1035
+ }
1036
+
976
1037
func exec (t * testing.T , dir , cmd string , args []string , expect string ) {
977
1038
r , w , err := Pipe ()
978
1039
if err != nil {
0 commit comments