aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@962: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. attila@962: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). attila@962: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@962: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * This is not a test - but a framework to run other tests. aoqi@0: * aoqi@0: * @subtest aoqi@0: */ aoqi@0: aoqi@0: // Assert is TestNG's Assert class attila@962: Object.defineProperty(this, "Assert", { attila@963: configurable: true, aoqi@0: enumerable: false, aoqi@0: writable: true, aoqi@0: value: Packages.org.testng.Assert aoqi@0: }); aoqi@0: aoqi@0: // fail function to call TestNG Assert.fail aoqi@0: Object.defineProperty(this, "fail", { attila@963: configurable: true, aoqi@0: enumerable: false, aoqi@0: writable: true, attila@962: // 'error' is optional. if present it has to be aoqi@0: // an ECMAScript Error object or java Throwable object aoqi@0: value: function (message, error) { aoqi@0: var throwable = null; aoqi@0: if (typeof error != 'undefined') { aoqi@0: if (error instanceof java.lang.Throwable) { aoqi@0: throwable = error; aoqi@0: } else if (error.nashornException instanceof java.lang.Throwable) { aoqi@0: throwable = error.nashornException; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (throwable != null) { aoqi@0: // call the fail version that accepts Throwable argument aoqi@0: Assert.fail(message, throwable); aoqi@0: } else { aoqi@0: // call the fail version that accepts just message aoqi@0: Assert.fail(message); aoqi@0: } aoqi@0: } aoqi@0: }); aoqi@0: aoqi@0: Object.defineProperty(this, "printError", { attila@963: configurable: true, aoqi@0: enumerable: false, aoqi@0: writable: true, aoqi@0: value: function (e) { aoqi@0: var msg = e.message; aoqi@0: var str = e.name + ':'; aoqi@0: if (e.lineNumber > 0) { aoqi@0: str += e.lineNumber + ':'; aoqi@0: } aoqi@0: if (e.columnNumber > 0) { aoqi@0: str += e.columnNumber + ':'; aoqi@0: } aoqi@0: str += msg.substring(msg.indexOf(' ') + 1); aoqi@0: print(str); aoqi@0: } aoqi@0: }); aoqi@0: