--- El vie 12-sep-08, Rafael Sanchez <[EMAIL PROTECTED]> escribió:
De:: Rafael Sanchez <[EMAIL PROTECTED]>
Asunto: Re: [perl #44457] [TODO] make sure files match test files for DYNPMCs
and DYNOPs etc
A: "Christoph Otto" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Fecha: viernes, 12 septiembre, 2008, 2:49 pm
--- El vie 12-sep-08, Christoph Otto <[EMAIL PROTECTED]> escribió:
De:: Christoph Otto <[EMAIL PROTECTED]>
Asunto: Re: [perl #44457] [TODO] make sure files match test files for DYNPMCs
and DYNOPs etc
A: [EMAIL PROTECTED], [EMAIL PROTECTED]
Fecha: viernes, 12 septiembre, 2008, 6:56 am
[EMAIL PROTECTED] via RT wrote:
>
> --- El mié 10-sep-08, Rafael Sanchez <[EMAIL PROTECTED]>
escribió:
> De:: Rafael Sanchez <[EMAIL PROTECTED]>
> Asunto: Re: [perl #44457] [TODO] make sure files match test files for
DYNPMCs and DYNOPs etc
> A: "Christoph Otto via RT"
<[EMAIL PROTECTED]>
> Cc: [email protected]
> Fecha: miércoles, 10 septiembre, 2008, 6:26 pm
> On Mon Aug 06 06:08:54 2007, pcoch wrote:
>> In the file t/distro/test_file_coverage.t there is the todo item:
>>
>> # TODO: DYNPMC, DYNOPS, etc
>>
>> This is in the context of making sure that the files match the test
>> files. This needs to be implemented.
>
> Is this as simple as writing a test to make sure every src/dynpmc/*.pmc
> and src/dynoplibs/*.ops has a matching
> t/dynpmc/*.t and t/dynoplibs/*.t ? If so, this would be an ideal task
> for one of our recent volunteers, since the code would be pure Perl.
>
>> Also, the test will fail without an exception for
src/dynpmc/rotest.pmc.
>> I don't know if a test should be written for this PMC or not.
>
>> I'm working in the script.
>
>> Igor
>
> I have a working script(with testing variables only).
>
> I have to filter de input (there are other types of files), and improbe
the reporting part.
>
> I don't know if I forgeting something.
>
> Igor
>
> The script is:
>
> #!/usr/bin/perl -w
>
> # Copyright (C) 2007-2008, The Perl Foundation.
> # $Id: Match.pl 2008-09-10 igor $
>
> =head1 NAME
>
> Match.pl
>
> =head1 DESCRIPTION
>
> Reports if doesn't mach a pmc file with a test file, there is not test
file
>
> =cut
>
> sub find_files {
> my ($base_dir,$dirpmc,$dirtest) = @_;
> opendir(DIRPMC, $base_dir.$dirpmc);
> opendir(DIRTEST,$base_dir.$dirtest);
>
> my @filespmc = grep { $_ ne '.' and $_ ne '..' }
readdir DIRPMC;
> my @filest = grep { $_ ne '.' and $_ ne '..' }
readdir DIRTEST;
>
> my @pmc_values = @{strip_ext([EMAIL PROTECTED])};
> my @t_values = @{strip_ext([EMAIL PROTECTED])};
>
> my %hash_t = map { $_ => $_ } @t_values;
>
> for (0 .. $#pmc_values) {
> if ( exists $hash_t{ $pmc_values[$_] } ) {
> print "element exist
".$pmc_values[$_]."\n";
> } else {
> print "element do not exist
".$pmc_values[$_]."\n";
> }
> }
>
> }
>
> sub strip_ext {
> my @ref_t = @{$_[0]};
> my @arr_stripped = ();
> for (my $i=0;$i<$#ref_t+1; $i++) {
> if ($ref_t[$i] =~ m/(\w+)[.]\w+/) { #Obtain names of
files without extension
> $arr_stripped[$i] = $1;
> } else {
> print "error";
> }
> }
> return [EMAIL PROTECTED];
> }
>
> my $base_dir = "/home/raf/parrot/";
> my $dirpmc = "src/dynpmc/";
> my $dirtest = "t/dynpmc/";
>
> #find_files($base_dir,$dirpmc,$dirtest);
>
>Hi Igor,
>First, thank you for taking the time to write this script.
>Unfortunately, the test needs to be added to t/distro/test_file_coverage.t
in
>Parrot. This ensures that it is run every time Parrot's test suite is
run
>via
>make test. It should be fairly easy to copy and modify the existing code
in
>t/distro/test_file_coverage.t to make it match dynpmc and dynops source
code
>to test files, but I'll be glad to help if you run into any issues.
>While you're working on the test, you can run it directly as a Perl
script
>or
>with prove. Note that you have to run perl Configure.pl before this test
will
>work.
>To learn how to contribute, I highly recommend the documentation in
>docs/project, especially cage_cleaners_guide.pod and committer_guide.pod.
>When modifying existing tests, it's best to work against svn trunk and
>update
>often. This avoids conflicts and makes it easy to generate patches.
>Once you have t/distro/test_file_coverage.t updated and working, create a
diff:
>svn diff >dynpmc_dynops_test_coverage.patch
>and attach that to a reply to this thread. You should also generally run
make
>codingstd_tests before submitting a patch, but I'll remember if you
>don't. ;)
>Again, thank you for contributing. I hope at least some of this
information
>is new to you.
>Christoph
>Hi Christoph,
>Actually all information you gave me is new to me,
>here in Mexico programmers(in companiies I've worked),
>don't use any testing software, In my last job we couldn't
>install subversion in a linux server(don't ask me why, "they had
>installed a windows server"), and in some gobernment
>offices is not possible to install free software
>on windows.
>I'm going to install parrot again, making all tests indicated
>in parrot wiki, and read all tests pods and install all test
>software.
>And in some days, I expect to send you my first patch.
>Sincerely,
>Igor
Hi Christoph,
I send you the patch attached.
Sincerely,
Igor
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
Regístrate ya - http://correo.yahoo.com.mx/
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
Regístrate ya - http://correo.yahoo.com.mx/ Index: test_file_coverage.t
===================================================================
--- test_file_coverage.t (revision 31278)
+++ test_file_coverage.t (working copy)
@@ -12,7 +12,8 @@
use File::Spec::Functions qw( catdir catfile );
use Parrot::Config;
-
+#my $base_dir = "/home/raf/parrot";
+my $base_dir = $PConfig{build_dir};
=head1 NAME
t/distro/test_file_coverage.t - make sure source files have matching tests
@@ -24,50 +25,195 @@
=head1 DESCRIPTION
Makes sure that specific source files have matching test files.
+And discard files that are not meant to match
=cut
## make sure PMC files match test files
-PMC: {
- my $pmc_dir = 'src/pmc';
- my $pmc_suffix = '.pmc';
+# remember to change the number of tests :-)
+#BEGIN { plan tests => 2; }
- my $test_dir = 't/pmc';
- my $test_suffix = '.t';
+=head1 SET PARAMETERS
+Parameters for matching are set in %tests hash where:
+
+
+my %tests = (
+ 'dynpmc' => #Hash dynpmc is an identifier can be anyone
+ ['src/dynpmc', #Directory for PMC files
+ '.pmc', #extension for pmc files
+ 'PMC1', #Text in output
+ 't/dynpmc', #Directory for test files
+ '.t', #extension for test files
+ 'test' #Text in output
+ ],
+ );
+
+=cut
+
+my %match_test = (
+ dynpmc => ['src/dynpmc','.pmc','PMC1','t/dynpmc','.t','test1'],
+ dynoplibs => ['src/dynoplibs','.pmc','PMC2','t/dynoplibs','.t','test2'],
+);
+
+my $num = keys %match_test;
+plan tests => $num * 2;
+
+=head1 DISCARDED FILES
+
+
+Discarded files(matching is not needed) are set in %dis_hash hash where
+
+my %dis_hash = (
+ 'dynpmc' => { 'pmc' => ['digest'],}, #for digest file, pmc extension, dynpmc test
+ 'dynpmc' => { 'test' => ['rotest'],}, #for rotest file, test extension, dynpmc test
+ 'dynoplibs => { 'pmc' => ['dan','myops']}, #for dan and myops files, pmc extension, dynoplibs test
+);
+
+=cut
+
+
+
+my %dis_hash = (
+# 'dynpmc' => { 'pmc' => ['digest'],},
+# 'dynoplibs' => { 'pmc' => ['dan'],},
+);
+
+
+
+# Discard function
+#
+# Discard files not used in testing, use %dis_hash
+# If tesre are not discarded files is better not to use this function
+#
+
+sub discard {
+my @temp_pmc = @{$_[0]};
+my @temp_test = @{$_[1]};
+my $dis_key = $_[2];
+
+my @result_array_pmc = ();
+my @result_array_test = ();
+
+ if (exists $dis_hash{$dis_key}{'pmc'}) {
+ my %vals_pmc = ();
+ %vals_pmc = map { $_ => 1 } @{$dis_hash{$dis_key}{'pmc'}};
+ my $i = $#temp_pmc;
+ my $pmc_cont = 0;
+
+ for (0 .. $i) {
+ if (!exists $vals_pmc{$temp_pmc[$_]}) {
+ $result_array_pmc[$pmc_cont] = $temp_pmc[$_];
+ $pmc_cont += 1;
+ }
+ }
+ } else {
+ @result_array_pmc = @temp_pmc;
+ }
+
+ if (exists $dis_hash{$dis_key}{'test'}) {
+ my %vals_test = ();
+ %vals_test = map { $_ => 1 } @{$dis_hash{$dis_key}{'test'}};
+ my $j = $#temp_test;
+ my $test_cont = 0;
+
+ for (0 .. $j) {
+ if (!exists $vals_test{$temp_test[$_]}) {
+ $result_array_test[$test_cont] = $temp_test[$_];
+ $test_cont += 1;
+ }
+ }
+ } else {
+ @result_array_test = @temp_test;
+ }
+ return ([EMAIL PROTECTED],[EMAIL PROTECTED]);
+}
+
+
+#function get_files
+#
+# Obtains the result of te match
+#if is used the third parameter return the text of the comparison
+#if is not used third parameters resturns a 1 or a 0 depending
+#on te array result
+#Array empty = all files match = 1
+#Array with elements = some file(s) don't match = 0
+sub get_files {
+ my $test_key = $_[0];
+ my @tests_array = @{ $match_test{$test_key} };
+ #my $test_key = $_[1];
+ my $test_type = $_[1];
+ my $out_type = $_[2];
+ #my $out_type = $_[3];
+ my $pmc_dir = $tests_array[0];
+ my $pmc_suffix = $tests_array[1];
+ my $pmc_string = $tests_array[2];
+ my $test_dir = $tests_array[3];
+ my $test_suffix = $tests_array[4];
+ my $test_string = $tests_array[5];
+
+ my $text = "";
my ( @pmc_files, @test_files );
# find pmc files
find {
no_chdir => 1,
wanted => sub { files_of_type( [EMAIL PROTECTED], $pmc_suffix ) },
- } => catdir( $PConfig{build_dir}, $pmc_dir );
+ } => catdir( $base_dir, $pmc_dir );
# find test files
find {
no_chdir => 1,
wanted => sub { files_of_type( [EMAIL PROTECTED], $test_suffix ) },
- } => catdir( $PConfig{build_dir}, $test_dir );
+ } => catdir( $base_dir, $test_dir );
my ( $pmc_miss, $test_miss ) = list_diff( [EMAIL PROTECTED], [EMAIL PROTECTED] );
+
+# Used with discard function
+ my ($temp_pmc,$temp_test) = discard($pmc_miss,$test_miss,$test_key);
+ my @result_array_pmc = @{$temp_pmc};
+ my @result_array_test = @{$temp_test};
+# Used without discard function
+# my @result_array_pmc = @{$pmc_miss};
+# my @result_array_test = @{$test_miss};
+
local $" = "\n\t";
-
-TODO: {
- local $TODO = "not yet implemented";
- ok( [EMAIL PROTECTED], "there are test files for all PMC files in $pmc_dir" )
- or diag "files in $test_dir but not in PMC dir:[EMAIL PROTECTED]";
+ if ($test_type eq 'pmc') {
+ if (@result_array_pmc) {
+ if (defined $out_type) {
+ $text = "files in $test_dir but not in $pmc_string dir:[EMAIL PROTECTED]";
+ } else {
+ $text = 0;
+ }
+ } else {
+ if (defined $out_type) {
+ $text = "there are $pmc_string files for all $test_string files in $test_dir";
+ } else {
+ $text = 1;
+ }
+ }
+ } else {
+ if (@result_array_test) {
+ if (defined $out_type) {
+ $text = "files in $pmc_dir but not in $test_string dir:[EMAIL PROTECTED]";
+ } else {
+ $text = 0;
+ }
+ } else {
+ if (defined $out_type) {
+ $text = "there are $pmc_string files for all $test_string files in $test_dir";
+ } else {
+ $text = 1;
+ }
+ }
}
- ok( [EMAIL PROTECTED], "there are PMC files for all test files in $test_dir" )
- or diag "files in $pmc_dir but not in test dir:[EMAIL PROTECTED]";
+ return $text;
+}
+#} # PMC
-} # PMC
-
# RT#44457: DYNPMC, DYNOPS, etc.
-# remember to change the number of tests :-)
-BEGIN { plan tests => 2; }
-
sub files_of_type {
my ( $listref, $ext ) = @_;
@@ -89,6 +235,36 @@
);
}
+#Main loop
+=pod
+ print get_files('dynpmc','pmc','print')."\n";
+ print get_files('dynpmc','test','print')."\n";
+ print get_files('dynoplibs','pmc','print')."\n";
+ print get_files('dynoplibs','test','print')."\n";
+
+
+ print get_files('dynpmc','pmc')."\n";
+ print get_files('dynpmc','test')."\n";
+ print get_files('dynoplibs','pmc')."\n";
+ print get_files('dynoplibs','test')."\n";
+=cut
+
+ #ok( get_files('dynpmc','pmc') , get_files('dynpmc','pmc','print') );
+ #ok( get_files('dynpmc','test') , get_files('dynpmc','test','print') );
+ #ok( get_files('dynoplibs','pmc') , get_files('dynoplibs','pmc','print') );
+ #ok( get_files('dynoplibs','test') , get_files('dynoplibs','test','print') );
+
+#TODO: {
+# local $TODO = 'Not yet implemented';
+
+ foreach (keys %match_test) {
+ ok( get_files($_,'pmc') , get_files($_,'pmc','print') );
+ ok( get_files($_,'test') , get_files($_,'test','print') );
+ }
+
+#}
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4