commit fae257684466739cf66a0f1d32f38e86c41c89fd
parent 1061599573f0736206fa697f03963c569e8e9bcb
Author: lumidify <nobody@lumidify.org>
Date:   Mon, 23 Mar 2020 21:22:30 +0100
Add tests for mv
Diffstat:
6 files changed, 81 insertions(+), 9 deletions(-)
diff --git a/TODO b/TODO
@@ -1,2 +1,3 @@
+ALLOW FORCE ON MV AND CP (don't prompt for overwrite)
 Allow to run command on multiple files but keep checksum (e.g. convmv)
 update command - if file was edited
diff --git a/lumia.pl b/lumia.pl
@@ -658,8 +658,6 @@ sub move_rename {
 		return if !defined $dst_cksums;
 	}
 
-	return if move_file($src, $dst);
-
 	my $files_touched = 0;
 	my $dirs_touched = 0;
 	if (-d $src) {
@@ -667,6 +665,9 @@ sub move_rename {
 	} else {
 		$files_touched = 1;
 	}
+
+	return if move_file($src, $dst);
+
 	if (exists($src_cksums->{$src_file})) {
 		$dst_cksums->{$dst_file} = $src_cksums->{$src_file};
 		delete $src_cksums->{$src_file};
@@ -689,11 +690,6 @@ sub move_rename {
 # $dst: destination directory or file (in latter case only one src is allowed)
 sub move_files {
 	my ($src, $dst) = @_;
-	foreach my $src_file (@$src) {
-		if ($src_file eq ".") {
-			die "Can't move current directory (.)\n";
-		}
-	}
 	if (!-d $dst && $#$src != 0) {
 		die "move: only one source argument allowed when destination is a file\n";
 	}
@@ -858,7 +854,7 @@ sub update {
 	}
 }
 
-pod2usage(1) if $#ARGV < 0;
+pod2usage(-verbose => 1) if $#ARGV < 0;
 
 if ($ARGV[0] eq "mv") {
 	if ($#ARGV < 2) {
@@ -948,11 +944,15 @@ if ($ARGV[0] eq "mv") {
 
 __END__
 
+=head1 NAME
+
+lumia.pl - Manage checksums on a filesystem
+
 =head1 SYNOPSIS
 
 B<lumia.pl> command arguments
 
-=head1 COMMANDS
+=head1 OPTIONS
 
 =over 8
 
diff --git a/tests/README b/tests/README
@@ -1,2 +1,4 @@
 All tests must sort the output from lumia.pl since the
 order in the checksum files is random.
+
+To run all tests, simply run alltests.sh
diff --git a/tests/alltests.sh b/tests/alltests.sh
@@ -1,3 +1,4 @@
 #!/bin/sh
 
 ./runtest.sh filenames
+./runtest.sh mv
diff --git a/tests/mv.sh b/tests/mv.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+mkdir tmp
+cd tmp
+mkdir a
+mkdir b
+mkdir c
+
+../../lumia.pl addnew | sort
+cat .lumidify_archive_dirs | sort
+../../lumia.pl mv a b
+cat .lumidify_archive_dirs | sort
+cat b/.lumidify_archive_dirs | sort
+../../lumia.pl mv b b
+../../lumia.pl mv c d
+cat .lumidify_archive_dirs | sort
+touch tmp1
+touch tmp2
+touch tmp3
+../../lumia.pl addnew | sort
+cat .lumidify_archive_cksums | sort
+../../lumia.pl mv tmp1 tmp4 | sort
+cat .lumidify_archive_cksums | sort
+../../lumia.pl mv b tmp2
+../../lumia.pl mv tmp2 tmp3 tmp4
+../../lumia.pl mv tmp3 b tmp4
+echo "y" | ../../lumia.pl mv ./ c
+../../lumia.pl mkdir final
+../../lumia.pl mv * final
+cat .lumidify_archive_dirs | sort
+cat .lumidify_archive_cksums | sort
+cat final/.lumidify_archive_dirs | sort
+cat final/.lumidify_archive_cksums | sort
+
+cd ..
+rm -r tmp
diff --git a/tests/mv.txt b/tests/mv.txt
@@ -0,0 +1,32 @@
+Added "./a"
+Added "./b"
+Added "./c"
+"a"
+"b"
+"c"
+"b"
+"c"
+"a"
+mv: rename ./b to b/b: Invalid argument
+"b"
+"d"
+Added "./tmp1"
+Added "./tmp2"
+Added "./tmp3"
+4294967295 0 "tmp1"
+4294967295 0 "tmp2"
+4294967295 0 "tmp3"
+4294967295 0 "tmp2"
+4294967295 0 "tmp3"
+4294967295 0 "tmp4"
+move: can't move directory to file
+move: only one source argument allowed when destination is a file
+move: only one source argument allowed when destination is a file
+mv: rename ./ to c: Invalid argument
+mv: rename ./final to final/final: Invalid argument
+"final"
+"b"
+"d"
+4294967295 0 "tmp2"
+4294967295 0 "tmp3"
+4294967295 0 "tmp4"