3 # Copyright (C) 2011 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
26 # Script to create a new HTML file for a monolithic test using js-test machinery.
31 use lib $FindBin::Bin;
37 sub makePathToSharedSources;
43 my $result = GetOptions(
47 if (!$result || $showHelp || !scalar(@ARGV) || $ARGV[0] !~ m/\.html$/) {
48 print STDERR "Usage: " . basename($0) . " [-h|--help] pathname\n";
49 print STDERR "\nExamples:\n";
50 print STDERR " " . basename($0) . " new-test.html (will create the test in current directory)\n";
51 print STDERR " " . basename($0) . " fast/loader/new-test.html (a relative path is always from LayoutTests directory)\n";
52 print STDERR " " . basename($0) . " /Volumes/Data/WebKit/LayoutTests/fast/loader/new-test.html\n";
56 my $providedPath = $ARGV[0];
60 # If only a file name is provided, create the test in current directory.
61 $testAbsolutePath = File::Spec->rel2abs($providedPath) if (!(File::Spec->splitpath($providedPath))[1]);
63 # Otherwise, it's either absolute, or relative to LayoutTests directory.
66 $testAbsolutePath = File::Spec->rel2abs($providedPath) if (!$testAbsolutePath);
70 print "$testAbsolutePath\n";
75 sub makePathToSharedSources
77 my $layoutTestsPath = getcwd();
78 $testAbsolutePath =~ m/^$layoutTestsPath/ or die "Path $testAbsolutePath is not in LayoutTests directory.\n";
79 my $isHTTPTest = $testAbsolutePath =~ m/^$layoutTestsPath\/http/;
81 return "/js-test-resources";
83 return File::Spec->abs2rel("fast/js/resources/", dirname($testAbsolutePath));
89 die "Test $testAbsolutePath already exists.\n" if (-e $testAbsolutePath);
91 my $pathToSharedSources = makePathToSharedSources();
93 open TEST, ">", ${testAbsolutePath} or die "Cannot create test file at $testAbsolutePath.\n";
98 <meta charset="utf-8">
99 <script src="$pathToSharedSources/js-test-pre.js"></script>
104 description("TEST DESCRIPTION HERE");
106 // Your test script here. Feel free to modify surrounding HTML code if necessary.
109 <script src="$pathToSharedSources/js-test-post.js"></script>
116 sub openTestInEditor()
118 my $editor = $ENV{EDITOR};
119 exec ($editor, $testAbsolutePath) if ($editor);