Skip to content

Commit f9f683f

Browse files
rbrigbrail
authored andcommitted
Clean up test output and some unused code
better output of the interpreted mode, code cleanup, make some methods private Also, remove an unused test class better output of the interpreted mode, code cleanup, make some methods private
1 parent 34a209e commit f9f683f

3 files changed

Lines changed: 24 additions & 89 deletions

File tree

tests/src/test/java/org/mozilla/javascript/drivers/TestUtils.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.io.IOException;
1111
import java.io.InputStream;
1212
import java.util.ArrayList;
13-
import java.util.Arrays;
1413
import java.util.List;
1514
import java.util.Properties;
1615
import org.mozilla.javascript.ContextFactory;
@@ -50,22 +49,22 @@ public static void addTestsFromFile(String filename, List<String> list) throws I
5049
addTestsFromStream(new FileInputStream(new File(filename)), list);
5150
}
5251

53-
public static void addTestsFromStream(InputStream in, List<String> list) throws IOException {
52+
private static void addTestsFromStream(InputStream in, List<String> list) throws IOException {
5453
Properties props = new Properties();
5554
props.load(in);
5655
for (Object obj : props.keySet()) {
5756
list.add(obj.toString());
5857
}
5958
}
6059

61-
public static String[] loadTestsFromResource(String resource, String[] inherited)
62-
throws IOException {
63-
List<String> list =
64-
inherited == null
65-
? new ArrayList<String>()
66-
: new ArrayList<String>(Arrays.asList(inherited));
60+
public static String[] loadTestsFromResource(String resource) throws IOException {
6761
InputStream in = JsTestsBase.class.getResourceAsStream(resource);
68-
if (in != null) addTestsFromStream(in, list);
62+
if (in == null) {
63+
return new String[0];
64+
}
65+
66+
List<String> list = new ArrayList<String>();
67+
addTestsFromStream(in, list);
6968
return list.toArray(new String[0]);
7069
}
7170

tests/src/test/java/org/mozilla/javascript/tests/JsTestsTest.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/src/test/java/org/mozilla/javascript/tests/MozillaSuiteTest.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.io.File;
88
import java.io.FileFilter;
99
import java.io.FileNotFoundException;
10-
import java.io.FileReader;
1110
import java.io.IOException;
1211
import java.io.PrintStream;
1312
import java.net.URL;
@@ -52,7 +51,7 @@ public MozillaSuiteTest(File jsFile, boolean interpretedMode) {
5251
ShellTest.cacheFramework();
5352
}
5453

55-
public static File getTestDir() throws IOException {
54+
private static File getTestDir() throws IOException {
5655
File testDir = null;
5756
if (System.getProperty("mozilla.js.tests") != null) {
5857
testDir = new File(System.getProperty("mozilla.js.tests"));
@@ -81,36 +80,29 @@ public static File getTestDir() throws IOException {
8180
return testDir;
8281
}
8382

84-
public static String getTestFilename(boolean interpretedMode) {
83+
private static String getTestFilename(boolean interpretedMode) {
8584
return interpretedMode ? "interpreted.tests" : "compiled.tests";
8685
}
8786

88-
public static File[] getTestFiles(boolean interpretedMode) throws IOException {
87+
private static File[] getTestFiles(boolean interpretedMode) throws IOException {
8988
File testDir = getTestDir();
90-
String[] tests =
91-
TestUtils.loadTestsFromResource("/" + getTestFilename(interpretedMode), null);
92-
Arrays.sort(tests);
93-
File[] files = new File[tests.length];
94-
for (int i = 0; i < files.length; i++) {
95-
files[i] = new File(testDir, tests[i]);
96-
}
97-
if (files.length == 0) {
89+
String[] tests = TestUtils.loadTestsFromResource("/" + getTestFilename(interpretedMode));
90+
if (tests.length == 0) {
9891
throw new IOException(
9992
"No Mozilla Suite tests found in "
10093
+ testDir
10194
+ ". Check mozilla.js.tests property");
10295
}
103-
return files;
104-
}
10596

106-
public static String loadFile(File f) throws IOException {
107-
int length = (int) f.length(); // don't worry about very long files
108-
char[] buf = new char[length];
109-
new FileReader(f).read(buf, 0, length);
110-
return new String(buf);
97+
Arrays.sort(tests);
98+
File[] files = new File[tests.length];
99+
for (int i = 0; i < files.length; i++) {
100+
files[i] = new File(testDir, tests[i]);
101+
}
102+
return files;
111103
}
112104

113-
@Parameters(name = "{index}, js={0}, opt={1}")
105+
@Parameters(name = "{index}, js={0}, interpreted={1}")
114106
public static Collection<Object[]> mozillaSuiteValues() throws IOException {
115107
List<Object[]> result = new ArrayList<Object[]>();
116108
for (boolean im : new boolean[] {false, true}) {
@@ -122,19 +114,6 @@ public static Collection<Object[]> mozillaSuiteValues() throws IOException {
122114
return result;
123115
}
124116

125-
// move "@Parameters" to this method to test a single Mozilla test
126-
// @Parameters(name = "{index}, js={0}, opt={1}")
127-
public static Collection<Object[]> singleDoctest() throws IOException {
128-
final String SINGLE_TEST_FILE = "...";
129-
130-
List<Object[]> result = new ArrayList<Object[]>();
131-
for (boolean im : new boolean[] {false, true}) {
132-
File f = new File(getTestDir(), SINGLE_TEST_FILE);
133-
result.add(new Object[] {f, im});
134-
}
135-
return result;
136-
}
137-
138117
private static class ShellTestParameters extends ShellTest.Parameters {
139118
@Override
140119
public int getTimeoutMilliseconds() {
@@ -204,7 +183,7 @@ public void runMozillaTest() throws Exception {
204183
public static void main(String[] args) throws IOException {
205184
try (PrintStream out = new PrintStream("fix-tests-files.sh")) {
206185
try {
207-
for (boolean im : new boolean[] {false, true}) {
186+
for (boolean interpretedMode : new boolean[] {false, true}) {
208187
File testDir = getTestDir();
209188
File[] allTests =
210189
TestUtils.recursiveListFiles(
@@ -217,13 +196,13 @@ public boolean accept(File pathname) {
217196
}
218197
});
219198
HashSet<File> diff = new HashSet<File>(Arrays.asList(allTests));
220-
File testFiles[] = getTestFiles(im);
199+
File testFiles[] = getTestFiles(interpretedMode);
221200
diff.removeAll(Arrays.asList(testFiles));
222201
ArrayList<String> skippedPassed = new ArrayList<String>();
223202
int absolutePathLength = testDir.getAbsolutePath().length() + 1;
224203
for (File testFile : diff) {
225204
try {
226-
(new MozillaSuiteTest(testFile, im)).runMozillaTest();
205+
new MozillaSuiteTest(testFile, interpretedMode).runMozillaTest();
227206
// strip off testDir
228207
String canonicalized =
229208
testFile.getAbsolutePath().substring(absolutePathLength);
@@ -237,7 +216,7 @@ public boolean accept(File pathname) {
237216
// skipped but now pass. Print out shell commands to update the
238217
// appropriate *.tests file.
239218
if (skippedPassed.size() > 0) {
240-
out.println("cat >> " + getTestFilename(im) + " <<EOF");
219+
out.println("cat >> " + getTestFilename(interpretedMode) + " <<EOF");
241220
String[] sorted = skippedPassed.toArray(new String[0]);
242221
Arrays.sort(sorted);
243222
for (int j = 0; j < sorted.length; j++) {

0 commit comments

Comments
 (0)