summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominique Dumont <dod@debian.org>2020-07-01 18:52:11 +0200
committerDominique Dumont <dod@debian.org>2020-07-01 19:08:55 +0200
commitf5a6fcb71928f3b3890e69bad13d0afcb77ecc8c (patch)
treed44168eb0c21252562c018a3c451806ec3fa3dc3
parent2adb030e3907c40da5b398224d79bcbba5ea2265 (diff)
test new cleanup
-rw-r--r--t/copyright-from-scratch.t85
-rw-r--r--t/license-short-name.t12
-rw-r--r--t/model_tests.d/dpkg-copyright-test-conf.pl8
3 files changed, 104 insertions, 1 deletions
diff --git a/t/copyright-from-scratch.t b/t/copyright-from-scratch.t
new file mode 100644
index 00000000..f8126e74
--- /dev/null
+++ b/t/copyright-from-scratch.t
@@ -0,0 +1,85 @@
+# -*- cperl -*-
+
+use ExtUtils::testlib;
+use Test::More ;
+use Test::Memory::Cycle;
+use Config::Model ;
+use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
+use Path::Tiny;
+use Software::LicenseMoreUtils;
+use Test::LongString;
+use 5.10.0;
+
+use warnings;
+use strict;
+
+$::_use_log4perl_to_warn = 1;
+
+my ($model, $trace) = init_test();
+
+my $wr_dir = setup_test_dir();
+
+$wr_dir->child("debian")->mkpath() ;
+
+my $art_2_text = Software::LicenseMoreUtils->new_from_short_name({
+ short_name =>'Artistic-2',
+ holder => 'X. Ample'
+})->summary_or_text;
+$art_2_text =~ s/\t/ /g;
+$art_2_text =~ s!\n +\n!\n\n!g;
+chomp($art_2_text);
+
+# instance to check one dependency at a time
+my $inst = $model->instance (
+ root_class_name => 'Dpkg::Copyright',
+ root_dir => $wr_dir,
+ instance_name => "create_test",
+);
+
+my $unit = $inst->config_root;
+
+subtest 'Creation of debian/copyright' => sub {
+ is($unit->instance->initial_load,0,"initial load is done");
+
+ my $moarvm = path('t/scanner/examples/moarvm.in') ;
+ $unit->update(in => $moarvm, quiet => 1);
+
+ my $art2_obj = $unit->grab("License:Artistic-2.0 text");
+
+ # should be undef
+ my $default = $art2_obj->fetch() ;
+ is_string($default,$art_2_text,"check license text brought by Software::License");
+ is($art2_obj->fetch(mode => 'custom'),undef,'check lic text');
+ is($art2_obj->fetch_custom,undef,'check lic text');
+
+ # store identical text
+ $unit->instance->initial_load_start;
+ $art2_obj->store($default);
+ $unit->instance->initial_load_stop;
+ # custom text should still be undef
+ is($art2_obj->fetch_custom,undef,'check lic text');
+
+ $inst->write_back;
+};
+
+subtest 'Read and check debian/copyright' => sub {
+
+ my $inst = $model->instance (
+ root_class_name => 'Dpkg::Copyright',
+ root_dir => $wr_dir,
+ instance_name => "readtest",
+ );
+
+ my $unit = $inst->config_root;
+
+ my $art2_obj = $unit->grab("License:Artistic-2.0 text");
+
+ # should be undef
+ my $default = $art2_obj->fetch() ;
+ is_string($default,$art_2_text,"check license text brought by Software::License");
+ is($art2_obj->fetch_custom,undef,'check lic text');
+};
+
+memory_cycle_ok($model, "memory cycles");
+
+done_testing;
diff --git a/t/license-short-name.t b/t/license-short-name.t
index 56e87bb6..99e0907c 100644
--- a/t/license-short-name.t
+++ b/t/license-short-name.t
@@ -11,6 +11,8 @@ use warnings;
use strict;
use Test::More;
use Test::Exception;
+use Software::LicenseMoreUtils;
+use Test::LongString;
$::_use_log4perl_to_warn = 1;
@@ -36,11 +38,19 @@ my $root = $model->instance (
my $lic = $root->fetch_element('License');
my $gpl3_ex = "GPL-3+ with Font exception";
-
foreach my $name (qw/GPL-3+ GPL-2+ Artistic-2.0 BSD-3-clause Expat/, $gpl3_ex) {
ok($lic->fetch_with_id($name),"fetch «$name» license object");
}
+my $art_2_text = Software::LicenseMoreUtils->new_from_short_name({
+ short_name =>'Artistic-2',
+ holder => 'X. Ample'
+})->summary_or_text;
+chomp($art_2_text);
+$art_2_text =~ s/\t/ /g;
+$art_2_text =~ s!\n +\n!\n\n!g;
+is_string($root->grab_value("License:Artistic-2 text"), $art_2_text, "check that license text was not reformatted");
+
# this license index is not a valid short name. But the check is done
# by short name object, not by this hash element
ok($lic->fetch_with_id("GPL-3+ with Font-exception-2.0"), "check license with bad font exception");
diff --git a/t/model_tests.d/dpkg-copyright-test-conf.pl b/t/model_tests.d/dpkg-copyright-test-conf.pl
index 266fb0e3..63219566 100644
--- a/t/model_tests.d/dpkg-copyright-test-conf.pl
+++ b/t/model_tests.d/dpkg-copyright-test-conf.pl
@@ -288,10 +288,18 @@ in ‘/usr/share/common-licenses/GPL-1’.",
check => {
'License:ISC text' => qr/Please fill/,
'License:BSD-2-clause text' => qr/Please fill/,
+ 'License:"Artistic-2.0" text' => [
+ qr/The Artistic License 2.0/,
+ {mode => 'custom', value => undef},
+ ],
'Files:"3rdparty/libuv/samples/*" License short_name' => "BSD-3-clause and/or Expat",
},
wr_check => {
qq!Files:"3rdparty/dyncall/*" License full_license! => undef,
+ 'License:"Artistic-2.0" text' => [
+ qr/The Artistic License 2.0/,
+ {mode => 'custom', value => undef},
+ ],
},
has_not_key => [ License => qr!and/or! ],
file_contents_unlike => {