11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst path = require('path'); 61cb0ef41Sopenharmony_ciconst util = require('util'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst message = 'message'; 91cb0ef41Sopenharmony_ciconst testFunction1 = common.mustNotCall(message); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst testFunction2 = common.mustNotCall(message); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst createValidate = (line, args = []) => common.mustCall((e) => { 141cb0ef41Sopenharmony_ci const prefix = `${message} at `; 151cb0ef41Sopenharmony_ci assert.ok(e.message.startsWith(prefix)); 161cb0ef41Sopenharmony_ci if (process.platform === 'win32') { 171cb0ef41Sopenharmony_ci e.message = e.message.substring(2); // remove 'C:' 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci const msg = e.message.substring(prefix.length); 201cb0ef41Sopenharmony_ci const firstColon = msg.indexOf(':'); 211cb0ef41Sopenharmony_ci const fileName = msg.substring(0, firstColon); 221cb0ef41Sopenharmony_ci const rest = msg.substring(firstColon + 1); 231cb0ef41Sopenharmony_ci assert.strictEqual(path.basename(fileName), 'test-common-must-not-call.js'); 241cb0ef41Sopenharmony_ci const argsInfo = args.length > 0 ? 251cb0ef41Sopenharmony_ci `\ncalled with arguments: ${args.map(util.inspect).join(', ')}` : ''; 261cb0ef41Sopenharmony_ci assert.strictEqual(rest, line + argsInfo); 271cb0ef41Sopenharmony_ci}); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciconst validate1 = createValidate('9'); 301cb0ef41Sopenharmony_citry { 311cb0ef41Sopenharmony_ci testFunction1(); 321cb0ef41Sopenharmony_ci} catch (e) { 331cb0ef41Sopenharmony_ci validate1(e); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciconst validate2 = createValidate('11', ['hello', 42]); 371cb0ef41Sopenharmony_citry { 381cb0ef41Sopenharmony_ci testFunction2('hello', 42); 391cb0ef41Sopenharmony_ci} catch (e) { 401cb0ef41Sopenharmony_ci validate2(e); 411cb0ef41Sopenharmony_ci} 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciassert.throws( 441cb0ef41Sopenharmony_ci () => new Proxy({ prop: Symbol() }, { get: common.mustNotCall() }).prop, 451cb0ef41Sopenharmony_ci { code: 'ERR_ASSERTION' } 461cb0ef41Sopenharmony_ci); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci{ 491cb0ef41Sopenharmony_ci const { inspect } = util; 501cb0ef41Sopenharmony_ci delete util.inspect; 511cb0ef41Sopenharmony_ci assert.throws( 521cb0ef41Sopenharmony_ci () => common.mustNotCall()(null), 531cb0ef41Sopenharmony_ci { code: 'ERR_ASSERTION' } 541cb0ef41Sopenharmony_ci ); 551cb0ef41Sopenharmony_ci util.inspect = inspect; 561cb0ef41Sopenharmony_ci} 57