Changeset 202433 in webkit


Ignore:
Timestamp:
Jun 24, 2016 11:34:20 AM (8 years ago)
Author:
ddkilzer@apple.com
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.

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r202418 r202433  
     12016-06-24  David Kilzer  <ddkilzer@apple.com>
     2
     3        parser_unittests.pl should not hardcode list of tests
     4        <https://webkit.org/b/159074>
     5
     6        Reviewed by Daniel Bates.
     7
     8        * Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl:
     9        Update to read the list of tests from the 'resources' directory,
     10        and instead map file extensions to subroutine names.  Switch to
     11        use File::Basename::fileparse() to get basename and file
     12        extension for each test.
     13        (readTestFiles): Added.  Reads files from the directory passed
     14        in and ignores: hidden files, anything that isn't a plain file,
     15        and expected test results files.
     16
    1172016-06-23  Simon Fraser  <simon.fraser@apple.com>
    218
  • trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl

    r189355 r202433  
    22#
    33# Copyright (C) 2011 Google Inc.  All rights reserved.
     4# Copyright (C) 2015-2016 Apple Inc.  All rights reserved.
    45#
    56# This library is free software; you can redistribute it and/or
     
    1920
    2021# This script tests the parser of prepare-ChangeLog (i.e. get_function_line_ranges_for_XXXX()).
    21 # This script runs the unittests specified in @testFiles.
     22# This script runs the unittests in the 'resources' subdirectory.
    2223
    2324use strict;
     
    3637sub captureOutput($);
    3738sub convertAbsolutepathToWebKitPath($);
     39sub readTestFiles($);
    3840
    39 my %testFiles = ("perl_unittests.pl" => "get_function_line_ranges_for_perl",
    40                  "python_unittests.py" => "get_function_line_ranges_for_python",
    41                  "java_unittests.java" => "get_function_line_ranges_for_java",
    42                  "cpp_unittests.cpp" => "get_function_line_ranges_for_cpp",
    43                  "javascript_unittests.js" => "get_function_line_ranges_for_javascript",
    44                  "css_unittests.css" => "get_selector_line_ranges_for_css",
    45                  "css_unittests_warning.css" => "get_selector_line_ranges_for_css",
    46                  "swift_unittests.swift" => "get_function_line_ranges_for_swift",
    47                 );
     41use constant EXPECTED_RESULTS_SUFFIX => "-expected.txt";
     42
     43my %methodForFileExtension = (
     44    ".cpp" => "get_function_line_ranges_for_cpp",
     45    ".css" => "get_selector_line_ranges_for_css",
     46    ".java" => "get_function_line_ranges_for_java",
     47    ".js" => "get_function_line_ranges_for_javascript",
     48    ".pl" => "get_function_line_ranges_for_perl",
     49    ".py" => "get_function_line_ranges_for_python",
     50    ".swift" => "get_function_line_ranges_for_swift",
     51);
    4852
    4953my $resetResults;
    5054GetOptions('reset-results' => \$resetResults);
    5155
     56my $resourcesDirectory = File::Spec->catdir($FindBin::Bin, "resources");
     57my @suffixList = keys %methodForFileExtension;
     58my @testFiles = readTestFiles($resourcesDirectory);
    5259my @testSet;
    53 foreach my $testFile (sort keys %testFiles) {
    54     my $basename = $testFile;
    55     $basename = $1 if $basename =~ /^(.*)\.[^\.]*$/;
    56     push @testSet, {method => $testFiles{$testFile},
    57                     inputFile => File::Spec->catdir($FindBin::Bin, "resources", $testFile),
    58                     expectedFile => File::Spec->catdir($FindBin::Bin, "resources", $basename . "-expected.txt")};
     60foreach my $testFile (sort @testFiles) {
     61    my ($basename, undef, $extension) = fileparse($testFile, @suffixList);
     62    push @testSet, {
     63        method => $methodForFileExtension{$extension},
     64        inputFile => File::Spec->catfile($resourcesDirectory, $testFile),
     65        expectedFile => File::Spec->catfile($resourcesDirectory, $basename . EXPECTED_RESULTS_SUFFIX),
     66    };
    5967}
    6068
     
    131139    return $string;
    132140}
     141
     142sub readTestFiles($)
     143{
     144    my ($directory) = @_;
     145    my @files;
     146    opendir(DIR, $directory) || die "Could not open $directory: $!";
     147    while (readdir(DIR)) {
     148        next if /^\./;
     149        next if ! -f File::Spec->catfile($directory, $_);
     150        next if /\Q@{[EXPECTED_RESULTS_SUFFIX]}\E$/;
     151        push @files, $_;
     152    }
     153    closedir(DIR);
     154    return @files;
     155}
Note: See TracChangeset for help on using the changeset viewer.