ScriptTest.java revision 877:cf4d2252d444
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 26package jdk.nashorn.internal.test.framework; 27 28import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_INCLUDES; 29 30import java.io.File; 31import java.util.ArrayList; 32import java.util.List; 33import java.util.Locale; 34import java.util.Map; 35import java.util.Set; 36import java.util.TreeSet; 37import jdk.nashorn.internal.test.framework.TestFinder.TestFactory; 38import org.testng.ITest; 39import org.testng.annotations.Factory; 40import org.testng.annotations.Listeners; 41 42/** 43 * Simple test suite Factory for the JavaScript tests - runs tests in the name order. 44 */ 45@Listeners({ TestReorderInterceptor.class }) 46public final class ScriptTest { 47 /** 48 * Creates a test factory for the set of .js source tests. 49 * 50 * @return a Object[] of test objects. 51 */ 52 @Factory 53 public Object[] suite() throws Exception { 54 Locale.setDefault(new Locale("")); 55 56 final List<ITest> tests = new ArrayList<>(); 57 final Set<String> orphans = new TreeSet<>(); 58 59 final TestFactory<ITest> testFactory = new TestFactory<ITest>() { 60 @Override 61 public ITest createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> scriptArguments) { 62 return new ScriptRunnable(framework, testFile, engineOptions, testOptions, scriptArguments); 63 } 64 65 @Override 66 public void log(final String msg) { 67 org.testng.Reporter.log(msg, true); 68 } 69 }; 70 71 TestFinder.findAllTests(tests, orphans, testFactory); 72 73 if (System.getProperty(TEST_JS_INCLUDES) == null) { 74 tests.add(new OrphanTestFinder(orphans)); 75 } 76 77 return tests.toArray(); 78 } 79} 80