commit-queue@webkit.org | 026ee04 | 2018-01-04 07:18:18 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 2 | |
| 3 | # Copyright (C) 2011 Apple Inc. All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions |
| 7 | # are met: |
| 8 | # |
| 9 | # 1. Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in the |
| 13 | # documentation and/or other materials provided with the distribution. |
| 14 | # |
| 15 | # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 16 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 19 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | |
ap@apple.com | 7c99c18 | 2017-05-20 18:15:07 +0000 | [diff] [blame] | 26 | # Script to create a new HTML file using js-test machinery. |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 27 | |
| 28 | use strict; |
commit-queue@webkit.org | 026ee04 | 2018-01-04 07:18:18 +0000 | [diff] [blame] | 29 | use warnings; |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 30 | |
| 31 | use FindBin; |
| 32 | use lib $FindBin::Bin; |
| 33 | |
| 34 | use File::Basename; |
| 35 | use Getopt::Long; |
| 36 | use webkitdirs; |
| 37 | |
ap@apple.com | bb1d1b9 | 2012-01-19 22:04:55 +0000 | [diff] [blame] | 38 | sub makePathToSharedSources; |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 39 | sub openTestInEditor; |
| 40 | sub writeTestFile; |
| 41 | |
| 42 | my $showHelp; |
| 43 | |
| 44 | my $result = GetOptions( |
| 45 | "help" => \$showHelp, |
| 46 | ); |
| 47 | |
| 48 | if (!$result || $showHelp || !scalar(@ARGV) || $ARGV[0] !~ m/\.html$/) { |
| 49 | print STDERR "Usage: " . basename($0) . " [-h|--help] pathname\n"; |
| 50 | print STDERR "\nExamples:\n"; |
| 51 | print STDERR " " . basename($0) . " new-test.html (will create the test in current directory)\n"; |
| 52 | print STDERR " " . basename($0) . " fast/loader/new-test.html (a relative path is always from LayoutTests directory)\n"; |
| 53 | print STDERR " " . basename($0) . " /Volumes/Data/WebKit/LayoutTests/fast/loader/new-test.html\n"; |
| 54 | exit 1; |
| 55 | } |
| 56 | |
| 57 | my $providedPath = $ARGV[0]; |
| 58 | |
| 59 | my $testAbsolutePath; |
| 60 | |
| 61 | # If only a file name is provided, create the test in current directory. |
| 62 | $testAbsolutePath = File::Spec->rel2abs($providedPath) if (!(File::Spec->splitpath($providedPath))[1]); |
| 63 | |
| 64 | # Otherwise, it's either absolute, or relative to LayoutTests directory. |
| 65 | chdirWebKit(); |
| 66 | chdir "LayoutTests"; |
| 67 | $testAbsolutePath = File::Spec->rel2abs($providedPath) if (!$testAbsolutePath); |
| 68 | |
| 69 | writeTestFile(); |
| 70 | |
| 71 | print "$testAbsolutePath\n"; |
| 72 | openTestInEditor(); |
| 73 | |
| 74 | exit 0; |
| 75 | |
ap@apple.com | bb1d1b9 | 2012-01-19 22:04:55 +0000 | [diff] [blame] | 76 | sub makePathToSharedSources |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 77 | { |
| 78 | my $layoutTestsPath = getcwd(); |
| 79 | $testAbsolutePath =~ m/^$layoutTestsPath/ or die "Path $testAbsolutePath is not in LayoutTests directory.\n"; |
ap@apple.com | bb1d1b9 | 2012-01-19 22:04:55 +0000 | [diff] [blame] | 80 | my $isHTTPTest = $testAbsolutePath =~ m/^$layoutTestsPath\/http/; |
| 81 | if ($isHTTPTest) { |
| 82 | return "/js-test-resources"; |
| 83 | } else { |
mark.lam@apple.com | 0c04c97 | 2013-09-10 02:46:55 +0000 | [diff] [blame] | 84 | return File::Spec->abs2rel("resources/", dirname($testAbsolutePath)); |
ap@apple.com | bb1d1b9 | 2012-01-19 22:04:55 +0000 | [diff] [blame] | 85 | } |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | sub writeTestFile |
| 89 | { |
| 90 | die "Test $testAbsolutePath already exists.\n" if (-e $testAbsolutePath); |
| 91 | |
ap@apple.com | bb1d1b9 | 2012-01-19 22:04:55 +0000 | [diff] [blame] | 92 | my $pathToSharedSources = makePathToSharedSources(); |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 93 | |
| 94 | open TEST, ">", ${testAbsolutePath} or die "Cannot create test file at $testAbsolutePath.\n"; |
| 95 | print TEST << "EOF"; |
| 96 | <!DOCTYPE html> |
| 97 | <html> |
| 98 | <head> |
| 99 | <meta charset="utf-8"> |
ap@apple.com | 7c99c18 | 2017-05-20 18:15:07 +0000 | [diff] [blame] | 100 | <script src="$pathToSharedSources/js-test.js"></script> |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 101 | </head> |
| 102 | <body> |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 103 | <script> |
| 104 | |
arv@chromium.org | 0a48e05 | 2011-10-25 23:10:43 +0000 | [diff] [blame] | 105 | description("TEST DESCRIPTION HERE"); |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 106 | |
arv@chromium.org | 0a48e05 | 2011-10-25 23:10:43 +0000 | [diff] [blame] | 107 | // Your test script here. Feel free to modify surrounding HTML code if necessary. |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 108 | |
| 109 | </script> |
ap@apple.com | 5c610f6 | 2011-09-10 04:00:45 +0000 | [diff] [blame] | 110 | </body> |
| 111 | </html> |
| 112 | EOF |
| 113 | close TEST; |
| 114 | } |
| 115 | |
| 116 | sub openTestInEditor() |
| 117 | { |
| 118 | my $editor = $ENV{EDITOR}; |
| 119 | exec ($editor, $testAbsolutePath) if ($editor); |
| 120 | } |