[Buildroot] [PATCH 2/8] scancpan: add generation of test

Francois Perrad fperrad at gmail.com
Wed Nov 21 19:58:16 UTC 2018


Signed-off-by: Francois Perrad <francois.perrad at gadz.org>
---
 utils/scancpan | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/utils/scancpan b/utils/scancpan
index 78ea08c6e..0c5d6ac7a 100755
--- a/utils/scancpan
+++ b/utils/scancpan
@@ -575,6 +575,32 @@ sub find_license_files {
     return @license_files;
 }
 
+sub want_test {
+    my ($distname) = @_;
+    return 1 if $need_dlopen{$distname} && scalar @{$deps_runtime{$distname}} > 1;
+}
+
+sub get_dependencies {
+    my ($distname) = @_;
+    my %dep = map { $_ => 1 } @{$deps_runtime{$distname}};
+    for my $direct (@{$deps_runtime{$distname}}) {
+        for (get_dependencies( $direct )) {
+            $dep{$_} = 1;
+        }
+    }
+    return keys %dep;
+}
+
+sub get_indirect_dependencies {
+    my ($distname) = @_;
+    my %indirect;
+    my %direct = map { $_ => 1 } @{$deps_runtime{$distname}};
+    for my $dep (get_dependencies( $distname )) {
+        $indirect{$dep} = 1 unless exists $direct{$dep};
+    }
+    return keys %indirect;
+}
+
 sub fetch {
     my ($name, $need_target, $need_host, $top) = @_;
     $need_target{$name} = $need_target if $need_target;
@@ -688,6 +714,7 @@ while (my ($distname, $dist) = each %dist) {
     my $mkname = $dirname . q{/} . $fsname . q{.mk};
     my $hashname = $dirname . q{/} . $fsname . q{.hash};
     my $brname = brname( $fsname );
+    my $testname = q{support/testing/tests/package/test_} . lc $brname . q{.py};
     unless (-d $dirname) {
         mkdir $dirname;
         $new_pkgs = 1;
@@ -779,6 +806,45 @@ while (my ($distname, $dist) = each %dist) {
         }
         close $fh;
     }
+    if (want_test( $distname ) && ($force || !-f $testname)) {
+        my $classname = $distname;
+        $classname =~ s|-||g;
+        my $modname = $distname;
+        $modname =~ s|-|::|g;
+        my @indirect = (get_indirect_dependencies( $distname ));
+        say qq{write ${testname}} unless $quiet;
+        open my $fh, q{>}, $testname;
+        say {$fh} qq{from tests.package.test_perl import TestPerl};
+        say {$fh} qq{};
+        say {$fh} qq{};
+        say {$fh} qq{class TestPerl${classname}(TestPerl):};
+        say {$fh} qq{    """};
+        say {$fh} qq{    package:};
+        say {$fh} qq{        ${distname}};
+        say {$fh} qq{    direct dependencies:};
+        foreach my $dep (sort @{$deps_runtime{$distname}}) {
+            my $mark = want_test( $dep ) ? q{ *} : q{};
+            say {$fh} qq{        ${dep}${mark}};
+        }
+        if (scalar @indirect > 0) {
+            say {$fh} qq{    indirect dependencies:};
+            foreach my $dep (sort @indirect) {
+                my $mark = want_test( $dep ) ? q{ *} : q{};
+                say {$fh} qq{        ${dep}${mark}};
+            }
+        }
+        say {$fh} qq{    """};
+        say {$fh} qq{};
+        say {$fh} qq{    config = TestPerl.config + \\};
+        say {$fh} qq{        """};
+        say {$fh} qq{        BR2_PACKAGE_${brname}=y};
+        say {$fh} qq{        """};
+        say {$fh} qq{};
+        say {$fh} qq{    def test_run(self):};
+        say {$fh} qq{        self.login()};
+        say {$fh} qq{        self.module_test("${modname}")};
+        close $fh;
+    }
 }
 
 if ($new_pkgs) {
-- 
2.17.1




More information about the buildroot mailing list