Title: [202433] trunk/Tools
Revision
202433
Author
[email protected]
Date
2016-06-24 11:34:20 -0700 (Fri, 24 Jun 2016)

Log Message

parser_unittests.pl should not hardcode list of tests
<https://webkit.org/b/159074>

Reviewed by Daniel Bates.

* Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl:
Update to read the list of tests from the 'resources' directory,
and instead map file extensions to subroutine names.  Switch to
use File::Basename::fileparse() to get basename and file
extension for each test.
(readTestFiles): Added.  Reads files from the directory passed
in and ignores: hidden files, anything that isn't a plain file,
and expected test results files.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (202432 => 202433)


--- trunk/Tools/ChangeLog	2016-06-24 18:31:05 UTC (rev 202432)
+++ trunk/Tools/ChangeLog	2016-06-24 18:34:20 UTC (rev 202433)
@@ -1,3 +1,19 @@
+2016-06-24  David Kilzer  <[email protected]>
+
+        parser_unittests.pl should not hardcode list of tests
+        <https://webkit.org/b/159074>
+
+        Reviewed by Daniel Bates.
+
+        * Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl:
+        Update to read the list of tests from the 'resources' directory,
+        and instead map file extensions to subroutine names.  Switch to
+        use File::Basename::fileparse() to get basename and file
+        extension for each test.
+        (readTestFiles): Added.  Reads files from the directory passed
+        in and ignores: hidden files, anything that isn't a plain file,
+        and expected test results files.
+
 2016-06-23  Simon Fraser  <[email protected]>
 
         Fix Windows build.

Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl (202432 => 202433)


--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl	2016-06-24 18:31:05 UTC (rev 202432)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl	2016-06-24 18:34:20 UTC (rev 202433)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl -w
 #
 # Copyright (C) 2011 Google Inc.  All rights reserved.
+# Copyright (C) 2015-2016 Apple Inc.  All rights reserved.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -18,7 +19,7 @@
 # Boston, MA 02110-1301, USA.
 
 # This script tests the parser of prepare-ChangeLog (i.e. get_function_line_ranges_for_XXXX()).
-# This script runs the unittests specified in @testFiles.
+# This script runs the unittests in the 'resources' subdirectory.
 
 use strict;
 use warnings;
@@ -35,27 +36,34 @@
 
 sub captureOutput($);
 sub convertAbsolutepathToWebKitPath($);
+sub readTestFiles($);
 
-my %testFiles = ("perl_unittests.pl" => "get_function_line_ranges_for_perl",
-                 "python_unittests.py" => "get_function_line_ranges_for_python",
-                 "java_unittests.java" => "get_function_line_ranges_for_java",
-                 "cpp_unittests.cpp" => "get_function_line_ranges_for_cpp",
-                 "_javascript__unittests.js" => "get_function_line_ranges_for_javascript",
-                 "css_unittests.css" => "get_selector_line_ranges_for_css",
-                 "css_unittests_warning.css" => "get_selector_line_ranges_for_css",
-                 "swift_unittests.swift" => "get_function_line_ranges_for_swift",
-                );
+use constant EXPECTED_RESULTS_SUFFIX => "-expected.txt";
 
+my %methodForFileExtension = (
+    ".cpp" => "get_function_line_ranges_for_cpp",
+    ".css" => "get_selector_line_ranges_for_css",
+    ".java" => "get_function_line_ranges_for_java",
+    ".js" => "get_function_line_ranges_for_javascript",
+    ".pl" => "get_function_line_ranges_for_perl",
+    ".py" => "get_function_line_ranges_for_python",
+    ".swift" => "get_function_line_ranges_for_swift",
+);
+
 my $resetResults;
 GetOptions('reset-results' => \$resetResults);
 
+my $resourcesDirectory = File::Spec->catdir($FindBin::Bin, "resources");
+my @suffixList = keys %methodForFileExtension;
+my @testFiles = readTestFiles($resourcesDirectory);
 my @testSet;
-foreach my $testFile (sort keys %testFiles) {
-    my $basename = $testFile;
-    $basename = $1 if $basename =~ /^(.*)\.[^\.]*$/;
-    push @testSet, {method => $testFiles{$testFile},
-                    inputFile => File::Spec->catdir($FindBin::Bin, "resources", $testFile),
-                    expectedFile => File::Spec->catdir($FindBin::Bin, "resources", $basename . "-expected.txt")};
+foreach my $testFile (sort @testFiles) {
+    my ($basename, undef, $extension) = fileparse($testFile, @suffixList);
+    push @testSet, {
+        method => $methodForFileExtension{$extension},
+        inputFile => File::Spec->catfile($resourcesDirectory, $testFile),
+        expectedFile => File::Spec->catfile($resourcesDirectory, $basename . EXPECTED_RESULTS_SUFFIX),
+    };
 }
 
 plan(tests => scalar @testSet);
@@ -130,3 +138,18 @@
     $string =~ s/$sourceDir//g;
     return $string;
 }
+
+sub readTestFiles($)
+{
+    my ($directory) = @_;
+    my @files;
+    opendir(DIR, $directory) || die "Could not open $directory: $!";
+    while (readdir(DIR)) {
+        next if /^\./;
+        next if ! -f File::Spec->catfile($directory, $_);
+        next if /\Q@{[EXPECTED_RESULTS_SUFFIX]}\E$/;
+        push @files, $_;
+    }
+    closedir(DIR);
+    return @files;
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to