Path: blob/aarch64-shenandoah-jdk8u272-b10/nashorn/test/script/assert.js
32278 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* This is not a test - but a framework to run other tests.25*26* @subtest27*/2829// Assert is TestNG's Assert class30Object.defineProperty(this, "Assert", {31configurable: true,32enumerable: false,33writable: true,34value: Packages.org.testng.Assert35});3637// fail function to call TestNG Assert.fail38Object.defineProperty(this, "fail", {39configurable: true,40enumerable: false,41writable: true,42// 'error' is optional. if present it has to be43// an ECMAScript Error object or java Throwable object44value: function (message, error) {45var throwable = null;46if (typeof error != 'undefined') {47if (error instanceof java.lang.Throwable) {48throwable = error;49} else if (error.nashornException instanceof java.lang.Throwable) {50throwable = error.nashornException;51}52}5354if (throwable != null) {55// call the fail version that accepts Throwable argument56Assert.fail(message, throwable);57} else {58// call the fail version that accepts just message59Assert.fail(message);60}61}62});6364Object.defineProperty(this, "printError", {65configurable: true,66enumerable: false,67writable: true,68value: function (e) {69var msg = e.message;70var str = e.name + ':';71if (e.lineNumber > 0) {72str += e.lineNumber + ':';73}74if (e.columnNumber > 0) {75str += e.columnNumber + ':';76}77str += msg.substring(msg.indexOf(' ') + 1);78print(str);79}80});81828384