summaryrefslogtreecommitdiff
path: root/t/reference_licenses.t
diff options
context:
space:
mode:
authorRené Scheibe <rene.scheibe@gmail.com>2014-10-02 22:51:58 +0200
committerRené Scheibe <rene.scheibe@gmail.com>2014-10-02 22:51:58 +0200
commit079cf73208e44b6e0909b1a7540cba4c32059682 (patch)
tree9520a1576ea4cd78641bf89b2c6ecd83e0e4f9ad /t/reference_licenses.t
parentb689e53e4d55994661a3ce810b3e9b40afc6b56c (diff)
downloadninka-079cf73208e44b6e0909b1a7540cba4c32059682.tar.gz
1st test based on license reference files from fossology
- the expected output is based on Ninka's trunk (b689e53e4d55994661a3ce810b3e9b40afc6b56c)
Diffstat (limited to 't/reference_licenses.t')
-rw-r--r--t/reference_licenses.t55
1 files changed, 55 insertions, 0 deletions
diff --git a/t/reference_licenses.t b/t/reference_licenses.t
new file mode 100644
index 0000000..c01b64b
--- /dev/null
+++ b/t/reference_licenses.t
@@ -0,0 +1,55 @@
+use strict;
+use warnings;
+use Test::More;
+use File::Temp qw(tempdir);
+
+my $pwd = `pwd`; chomp $pwd;
+my $ninka_cmd = "$pwd/ninka.pl";
+my $licenses_dir = "$pwd/t/data/licenses";
+my $expected_output_dir = "$pwd/t/data/expected_output";
+my $temp_dir = tempdir(CLEANUP => 1);
+
+`cp $licenses_dir/* $temp_dir`;
+my @license_files = sort(list_files_in_dir($licenses_dir));
+
+plan tests => scalar(@license_files);
+
+foreach my $license_file (@license_files) {
+ subtest $license_file => sub {
+ my $input_file = "$temp_dir/$license_file";
+ my $output_file_expected = "$expected_output_dir/$license_file";
+ my $output_file_actual = "$temp_dir/$license_file.license";
+
+ ok -e $input_file, "input file exists: '$input_file'";
+
+ my $output_expected = read_file_as_string($output_file_expected);
+ my $output_ninka_stdout = `$ninka_cmd '$input_file'`; chomp $output_ninka_stdout;
+ my $output_ninka_file = read_file_as_string($output_file_actual);
+
+ is $output_ninka_stdout => "$temp_dir/$license_file;$output_expected", 'stdout is as expected';
+ is $output_ninka_file => $output_expected, 'file is as expected';
+ };
+}
+
+done_testing(scalar(@license_files));
+
+sub read_file_as_string {
+ my $file = shift;
+
+ open my $fh, '<', $file or die "can't open file '$file': $!";
+ my $content = do { local $/; <$fh> };
+ chomp $content;
+ close $fh or die "can't close file '$file': $!";
+
+ return $content;
+}
+
+sub list_files_in_dir {
+ my $dir = shift;
+
+ opendir my $dh, $dir or die "can't open dir '$dir': $!";
+ my @files = grep { /^[^.]/ && -f "$dir/$_" } readdir($dh);
+ closedir $dh or die "can't close dir '$dir': $!";
+
+ return @files;
+}