This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=659bfca2ab7fe06ff056e298a877cfbb0ca5e35c commit 659bfca2ab7fe06ff056e298a877cfbb0ca5e35c Author: Guillem Jover <[email protected]> AuthorDate: Wed Oct 26 22:10:07 2022 +0200 test: Add Dpkg::File unit tests --- scripts/Makefile.am | 1 + scripts/t/Dpkg_File.t | 32 ++++++++++++++++++++++++++++++-- scripts/t/Dpkg_File/slurp-me | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d023fd2c1..862af6cb9 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -279,6 +279,7 @@ test_data = \ t/Dpkg_Dist_Files/files-byhand \ t/Dpkg_Dist_Files/files-fragment-a \ t/Dpkg_Dist_Files/files-fragment-b \ + t/Dpkg_File/slurp-me \ t/Dpkg_OpenPGP/package_1.0.orig.tar \ t/Dpkg_OpenPGP/package_1.0.orig.tar.asc \ t/Dpkg_OpenPGP/package_1.0.orig.tar.sig \ diff --git a/scripts/t/Dpkg_File.t b/scripts/t/Dpkg_File.t index 1db6ee9f6..b36356105 100644 --- a/scripts/t/Dpkg_File.t +++ b/scripts/t/Dpkg_File.t @@ -16,12 +16,40 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 4; +use Test::Dpkg qw(:paths); BEGIN { use_ok('Dpkg::File'); } -# TODO: Add actual test cases. +my $datadir = test_get_data_path(); + +my ($data, $data_ref, $data_fh); + +$data = file_slurp("$datadir/slurp-me"); +$data_ref = <<'DATA'; +first line +next line +final line +DATA +is($data, $data_ref, 'slurped data'); + +open $data_fh, '<', "$datadir/slurp-me" + or die "cannot open $datadir/slurp-me for reading: $!"; +my $discard = <$data_fh>; +$data = file_slurp($data_fh); +close $data_fh; +$data_ref = <<'DATA'; +next line +final line +DATA +is($data, $data_ref, 'slurped partial data'); + +$data = undef; +eval { + $data = file_slurp("$datadir/non-existent"); +}; +ok($@, 'cannot slurp missing file'); 1; diff --git a/scripts/t/Dpkg_File/slurp-me b/scripts/t/Dpkg_File/slurp-me new file mode 100644 index 000000000..8840ed422 --- /dev/null +++ b/scripts/t/Dpkg_File/slurp-me @@ -0,0 +1,3 @@ +first line +next line +final line -- Dpkg.Org's dpkg

