From 18f143459991e44e10137fed501d162ae54274f8 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 12 Mar 2017 16:41:47 +0100 Subject: Fix sort order of detected archives cmp sorts strings, <=> sorts numbers Signed-off-by: Florian Pritz --- lib/App/BorgRestore.pm | 2 +- t/04_find_archives.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 t/04_find_archives.t diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index a7bb37b..cf64859 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -115,7 +115,7 @@ sub find_archives { printf "\e[0;91mWarning:\e[0m Path '%s' not found in any archive.\n", $path; } - @ret = sort { $a->{modification_time} cmp $b->{modification_time} } @ret; + @ret = sort { $a->{modification_time} <=> $b->{modification_time} } @ret; return \@ret; } diff --git a/t/04_find_archives.t b/t/04_find_archives.t new file mode 100644 index 0000000..2d40eef --- /dev/null +++ b/t/04_find_archives.t @@ -0,0 +1,29 @@ +use strict; +use warnings; + +use Test::More; +use Test::MockObject; +use Test::Differences; + +use App::BorgRestore; + +my $db = Test::MockObject->new(); +$db->mock('get_archives_for_path', sub {return [ + { modification_time => 5, archive => "test2"}, + { modification_time => 2, archive => "test1"}, + { modification_time => 10, archive => "test3"}, + { modification_time => 10, archive => "test4"}, + { modification_time => 2, archive => "test1-1"}, + { modification_time => 15, archive => "test5"}, + ];}); + +my $app = App::BorgRestore->new_no_defaults({}, {db => $db}); + +eq_or_diff($app->find_archives('test/path'), [ + {archive => 'test1', modification_time => 2}, + {archive => 'test2', modification_time => 5}, + {archive => 'test3', modification_time => 10}, + {archive => 'test5', modification_time => 15}, +]); + +done_testing; -- cgit v1.2.3-24-g4f1b