URI: 
       tAdd more tests - lumia - Archive checksum manager
  HTML git clone git://lumidify.org/git/lumia.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit ae5ceb4ffcbb4205584e4a1e7dc8b055a8c152d6
   DIR parent d170d94e968a44a9330ed8d5eb8b2fd4996afa90
  HTML Author: lumidify <nobody@lumidify.org>
       Date:   Tue, 24 Mar 2020 18:27:06 +0100
       
       Add more tests
       
       Diffstat:
         M lumia.pl                            |      27 +++++++++++++++------------
         M tests/README                        |       3 +++
         A tests/addcknew.sh                   |      26 ++++++++++++++++++++++++++
         A tests/addcknew.txt                  |      23 +++++++++++++++++++++++
         M tests/alltests.sh                   |       6 ++++++
         A tests/checkupdate.sh                |      21 +++++++++++++++++++++
         A tests/checkupdate.txt               |      19 +++++++++++++++++++
         A tests/extract.sh                    |      21 +++++++++++++++++++++
         A tests/extract.txt                   |      19 +++++++++++++++++++
         A tests/mkdir.sh                      |      11 +++++++++++
         A tests/mkdir.txt                     |       8 ++++++++
         A tests/rm.sh                         |      27 +++++++++++++++++++++++++++
         A tests/rm.txt                        |      11 +++++++++++
         A tests/rmckold.sh                    |      27 +++++++++++++++++++++++++++
         A tests/rmckold.txt                   |      50 +++++++++++++++++++++++++++++++
       
       15 files changed, 287 insertions(+), 12 deletions(-)
       ---
   DIR diff --git a/lumia.pl b/lumia.pl
       t@@ -10,7 +10,6 @@ use strict;
        use warnings;
        use File::Spec::Functions qw(catfile abs2rel);
        use File::Basename qw(basename dirname);
       -use File::Path qw(remove_tree);
        use String::ShellQuote;
        use Pod::Usage;
        use Getopt::Long;
       t@@ -88,6 +87,7 @@ sub make_file_iter_basic {
        # note: this returns nonexistent directories if those are still
        # specified in the lumia files
        sub make_lumia_iter {
       +        my ($quiet, @dirs) = @_;
                make_file_iter sub {1}, sub {
                        my $path = "$_[0]/$DIR_FILE";
                        return [] if !-f $path;
       t@@ -97,13 +97,14 @@ sub make_lumia_iter {
                        foreach my $dir (keys %$dirs) {
                                my $dir_path = "$_[0]/$dir";
                                if (!-d $dir_path) {
       -                                warn "ERROR: Directory \"$dir_path\" mentioned in \"$path\" does not exist or is not directory.\n";
       +                                warn "ERROR: Directory \"$dir_path\" mentioned in " .
       +                                        "\"$path\" does not exist or is not directory.\n" if !$quiet;
                                }
                                # still push it even when it doesn't exist so rmold can work properly
                                push @new_dirs, $dir_path;
                        }
                        return \@new_dirs;
       -        }, @_;
       +        }, @dirs;
        }
        
        # remove all special lumia files from the given directory
       t@@ -128,7 +129,7 @@ sub read_file {
                my ($file, $cksums, $handle_cksum_func) = @_;
                my $fh;
                if (!open $fh, "<", $file) {
       -                warn "ERROR: unable to open file \"$file\": $!\n";
       +                warn "ERROR: Unable to open file \"$file\": $!\n";
                        return;
                }
                my $in_fn = 0;
       t@@ -205,7 +206,7 @@ sub get_cksum {
                my $path_esc = shell_quote $path;
                my $cksum_output = `$CKSUM_CMD -- $path_esc 2>&1`;
                if ($?) {
       -                warn "ERROR getting cksum for file \"$path\":\n$cksum_output\n";
       +                warn "ERROR getting cksum for file \"$path\":\n$cksum_output";
                        return undef;
                }
                chomp $cksum_output;
       t@@ -262,7 +263,7 @@ sub check_files {
                                print "FAILED $file\n";
                        }
                }
       -        my $iter = make_lumia_iter @dirs;
       +        my $iter = make_lumia_iter 0, @dirs;
                while (my $file = $iter->()) {
                        check_cksums $file, $DOUBLE_CKSUM_FILE, $args->{"q"};
                        check_cksums $file, $CKSUM_FILE, $args->{"q"};
       t@@ -468,9 +469,8 @@ sub write_cksums {
        # show all files that are present in the checksum files but don't exist on the filesystem anymore
        sub check_old_files {
                my $top_dir = shift;
       -        my $iter = make_lumia_iter $top_dir;
       +        my $iter = make_lumia_iter 1, $top_dir;
                while (my $dir = $iter->()) {
       -                # if $dir doesn't exist, the iterator already issued a warning
                        if (-e $dir) {
                                my $cksums = read_cksum_file("$dir/$CKSUM_FILE", {}) // {};
                                foreach my $file (keys %$cksums) {
       t@@ -478,6 +478,8 @@ sub check_old_files {
                                                warn "Nonexistent file: \"$dir/$file\"!\n";
                                        }
                                }
       +                } else {
       +                        warn "Nonexistent directory: \"$dir\"!\n";
                        }
                }
        }
       t@@ -486,7 +488,7 @@ sub check_old_files {
        # on the filesystem anymore
        sub remove_old_files {
                my ($top_dir, $args) = @_;
       -        my $iter = make_lumia_iter $top_dir;
       +        my $iter = make_lumia_iter 1, $top_dir;
                while (my $dir = $iter->()) {
                        if (!-e $dir) {
                                my $parent = dirname $dir;
       t@@ -770,7 +772,7 @@ sub remove_file_dir {
                        return 1;
                }
                if (-e $path) {
       -                warn "ERROR: unable to remove \"$path\" from filesystem but " .
       +                warn "ERROR: Unable to remove \"$path\" from filesystem but " .
                                "will still be removed from checksum database\n";
                }
                return 0;
       t@@ -856,7 +858,7 @@ sub make_dirs {
        # entire directory structure in the process
        sub extract {
                my ($src_dir, $dst_dir, $args) = @_;
       -        my $iter = make_lumia_iter $src_dir;
       +        my $iter = make_lumia_iter 0, $src_dir;
                my $options = $args->{"v"} ? "-av" : "-a";
                while (my $dir = $iter->()) {
                        my $final_dir = abs2rel $dir, $src_dir;
       t@@ -1059,7 +1061,8 @@ B<directory> defaults to the current directory.
        
        =item B<rmold> [-q] [directory]
        
       -Deletes all files found by B<checkold>. B<directory> defaults to the current directory.
       +Removes all files found by B<checkold> from the database. B<directory> defaults to
       +the current directory.
        
        C<-q> suppresses the printing of each file as it is removed.
        
   DIR diff --git a/tests/README b/tests/README
       t@@ -2,3 +2,6 @@ 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
       +
       +There aren't that many tests yet. Maybe I'll get around
       +to adding more tests for all the edge cases someday.
   DIR diff --git a/tests/addcknew.sh b/tests/addcknew.sh
       t@@ -0,0 +1,26 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +mkdir a
       +mkdir b
       +mkdir c
       +
       +touch f1
       +touch f2
       +touch f3
       +
       +../../lumia.pl addnew | sort
       +../../lumia.pl clean -q
       +../../lumia.pl addnew -q
       +touch -- -bob
       +../../lumia.pl checknew
       +../../lumia.pl addnew
       +touch a/fred
       +../../lumia.pl checknew a
       +../../lumia.pl addnew a
       +../../lumia.pl check | sort
       +
       +cd ..
       +rm -r tmp
   DIR diff --git a/tests/addcknew.txt b/tests/addcknew.txt
       t@@ -0,0 +1,23 @@
       +Added "./a"
       +Added "./b"
       +Added "./c"
       +Added "./f1"
       +Added "./f2"
       +Added "./f3"
       +./-bob
       +Added "./-bob"
       +a/fred
       +Added "a/fred"
       +OK ./-bob
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./a/.lumidify_archive_cksums
       +OK ./a/.lumidify_archive_dirs
       +OK ./a/fred
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f1
       +OK ./f2
       +OK ./f3
   DIR diff --git a/tests/alltests.sh b/tests/alltests.sh
       t@@ -3,3 +3,9 @@
        ./runtest.sh filenames
        ./runtest.sh mv
        ./runtest.sh cp
       +./runtest.sh addcknew
       +./runtest.sh checkupdate
       +./runtest.sh rmckold
       +./runtest.sh mkdir
       +./runtest.sh extract
       +./runtest.sh rm
   DIR diff --git a/tests/checkupdate.sh b/tests/checkupdate.sh
       t@@ -0,0 +1,21 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +mkdir a
       +mkdir b
       +mkdir c
       +
       +touch f1
       +touch f2
       +touch f3
       +
       +../../lumia.pl addnew | sort
       +echo "a" > f1
       +../../lumia.pl check -q
       +../../lumia.pl update f1 a
       +../../lumia.pl check | sort
       +
       +cd ..
       +rm -r tmp
   DIR diff --git a/tests/checkupdate.txt b/tests/checkupdate.txt
       t@@ -0,0 +1,19 @@
       +Added "./a"
       +Added "./b"
       +Added "./c"
       +Added "./f1"
       +Added "./f2"
       +Added "./f3"
       +FAILED ./f1
       +Ignoring directory "a"
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./a/.lumidify_archive_cksums
       +OK ./a/.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f1
       +OK ./f2
       +OK ./f3
   DIR diff --git a/tests/extract.sh b/tests/extract.sh
       t@@ -0,0 +1,21 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +mkdir a
       +mkdir b
       +mkdir c
       +
       +touch f1
       +touch f2
       +touch f3
       +
       +../../lumia.pl addnew -q
       +mkdir bob
       +../../lumia.pl extract bob
       +find bob | sort
       +cat bob/.lumidify_archive_cksums | sort
       +
       +cd ..
       +rm -r tmp
   DIR diff --git a/tests/extract.txt b/tests/extract.txt
       t@@ -0,0 +1,19 @@
       +bob
       +bob/.lumidify_archive_cksums
       +bob/.lumidify_archive_cksums.cksum
       +bob/.lumidify_archive_dirs
       +bob/a
       +bob/a/.lumidify_archive_cksums
       +bob/a/.lumidify_archive_cksums.cksum
       +bob/a/.lumidify_archive_dirs
       +bob/b
       +bob/b/.lumidify_archive_cksums
       +bob/b/.lumidify_archive_cksums.cksum
       +bob/b/.lumidify_archive_dirs
       +bob/c
       +bob/c/.lumidify_archive_cksums
       +bob/c/.lumidify_archive_cksums.cksum
       +bob/c/.lumidify_archive_dirs
       +4294967295 0 "f1"
       +4294967295 0 "f2"
       +4294967295 0 "f3"
   DIR diff --git a/tests/mkdir.sh b/tests/mkdir.sh
       t@@ -0,0 +1,11 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +../../lumia.pl addnew
       +../../lumia.pl mkdir -- a b -c
       +../../lumia.pl check | sort
       +
       +cd ..
       +rm -r tmp
   DIR diff --git a/tests/mkdir.txt b/tests/mkdir.txt
       t@@ -0,0 +1,8 @@
       +OK ./-c/.lumidify_archive_cksums
       +OK ./-c/.lumidify_archive_dirs
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./a/.lumidify_archive_cksums
       +OK ./a/.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
   DIR diff --git a/tests/rm.sh b/tests/rm.sh
       t@@ -0,0 +1,27 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +mkdir a
       +mkdir b
       +mkdir c
       +
       +touch f1
       +touch f2
       +touch f3
       +
       +../../lumia.pl addnew | sort
       +../../lumia.pl rm f1
       +# Note: this doesn't check what happens when you try to remove this
       +# file without '-f', since it seems to be a paint to try to make
       +# rm believe that we're in a tty
       +chmod 444 f2
       +../../lumia.pl rm -f f2
       +echo "a" > a/meh
       +../../lumia.pl addnew a
       +../../lumia.pl rm a f3 c
       +../../lumia.pl check | sort
       +
       +cd ..
       +rm -rf tmp
   DIR diff --git a/tests/rm.txt b/tests/rm.txt
       t@@ -0,0 +1,11 @@
       +Added "./a"
       +Added "./b"
       +Added "./c"
       +Added "./f1"
       +Added "./f2"
       +Added "./f3"
       +Added "a/meh"
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
   DIR diff --git a/tests/rmckold.sh b/tests/rmckold.sh
       t@@ -0,0 +1,27 @@
       +#!/bin/sh
       +
       +mkdir tmp
       +cd tmp
       +
       +mkdir a
       +mkdir b
       +mkdir c
       +
       +touch f1
       +touch f2
       +touch f3
       +
       +../../lumia.pl addnew | sort
       +rm f1
       +../../lumia.pl check | sort
       +../../lumia.pl checkold
       +../../lumia.pl rmold
       +../../lumia.pl check | sort
       +rm -r a
       +../../lumia.pl check | sort
       +../../lumia.pl checkold
       +../../lumia.pl rmold -q
       +../../lumia.pl check | sort
       +
       +cd ..
       +rm -r tmp
   DIR diff --git a/tests/rmckold.txt b/tests/rmckold.txt
       t@@ -0,0 +1,50 @@
       +Added "./a"
       +Added "./b"
       +Added "./c"
       +Added "./f1"
       +Added "./f2"
       +Added "./f3"
       +ERROR getting cksum for file "./f1":
       +cksum: cannot open ./f1: No such file or directory
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./a/.lumidify_archive_cksums
       +OK ./a/.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f2
       +OK ./f3
       +Nonexistent file: "./f1"!
       +Removed "./f1" from "./.lumidify_archive_cksums"
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./a/.lumidify_archive_cksums
       +OK ./a/.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f2
       +OK ./f3
       +ERROR: Directory "./a" mentioned in "./.lumidify_archive_dirs" does not exist or is not directory.
       +ERROR: Unable to open file "./a/.lumidify_archive_cksums.cksum": No such file or directory
       +ERROR: Unable to open file "./a/.lumidify_archive_cksums": No such file or directory
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f2
       +OK ./f3
       +Nonexistent directory: "./a"!
       +OK ./.lumidify_archive_cksums
       +OK ./.lumidify_archive_dirs
       +OK ./b/.lumidify_archive_cksums
       +OK ./b/.lumidify_archive_dirs
       +OK ./c/.lumidify_archive_cksums
       +OK ./c/.lumidify_archive_dirs
       +OK ./f2
       +OK ./f3