1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.nashorn.internal.test.framework; 27 28 import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_INCLUDES; 29 import java.io.File; 30 import java.util.ArrayList; 31 import java.util.List; 32 import java.util.Locale; 33 import java.util.Map; 34 import java.util.Set; 35 import java.util.TreeSet; 36 import jdk.nashorn.internal.test.framework.TestFinder.TestFactory; 37 import org.testng.ITest; 38 import org.testng.annotations.Factory; 39 import org.testng.annotations.Listeners; 40 41 /** 42 * Simple test suite Factory for the JavaScript tests - runs tests in the name order. 43 */ 44 @Listeners({ TestReorderInterceptor.class }) 45 public final class ScriptTest { 46 /** 47 * Creates a test factory for the set of .js source tests. 48 * 49 * @return a Object[] of test objects. 50 * @throws Exception upon failure 51 */ 52 @SuppressWarnings("static-method") 53 @Factory 54 public Object[] suite() throws Exception { 55 Locale.setDefault(new Locale("")); 56 57 final List<ITest> tests = new ArrayList<>(); 58 final Set<String> orphans = new TreeSet<>(); 59 60 final TestFactory<ITest> testFactory = new TestFactory<ITest>() { 61 @Override 62 public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) { 63 return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments); 64 } 65 66 @Override 67 public void log(final String msg) { 68 org.testng.Reporter.log(msg, true); 69 } 70 }; 71 72 TestFinder.findAllTests(tests, orphans, testFactory); 73 74 if (System.getProperty(TEST_JS_INCLUDES) == null) { 75 tests.add(new OrphanTestFinder(orphans)); 76 } 77 78 return tests.toArray(); 79 } 80 }