11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cicommon.expectWarning(
71cb0ef41Sopenharmony_ci  'DeprecationWarning',
81cb0ef41Sopenharmony_ci  'assert.fail() with more than one argument is deprecated. ' +
91cb0ef41Sopenharmony_ci    'Please use assert.strictEqual() instead or only pass a message.',
101cb0ef41Sopenharmony_ci  'DEP0094'
111cb0ef41Sopenharmony_ci);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// Two args only, operator defaults to '!='
141cb0ef41Sopenharmony_ciassert.throws(() => {
151cb0ef41Sopenharmony_ci  assert.fail('first', 'second');
161cb0ef41Sopenharmony_ci}, {
171cb0ef41Sopenharmony_ci  code: 'ERR_ASSERTION',
181cb0ef41Sopenharmony_ci  name: 'AssertionError',
191cb0ef41Sopenharmony_ci  message: '\'first\' != \'second\'',
201cb0ef41Sopenharmony_ci  operator: '!=',
211cb0ef41Sopenharmony_ci  actual: 'first',
221cb0ef41Sopenharmony_ci  expected: 'second',
231cb0ef41Sopenharmony_ci  generatedMessage: true
241cb0ef41Sopenharmony_ci});
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// Three args
271cb0ef41Sopenharmony_ciassert.throws(() => {
281cb0ef41Sopenharmony_ci  assert.fail('ignored', 'ignored', 'another custom message');
291cb0ef41Sopenharmony_ci}, {
301cb0ef41Sopenharmony_ci  code: 'ERR_ASSERTION',
311cb0ef41Sopenharmony_ci  name: 'AssertionError',
321cb0ef41Sopenharmony_ci  message: 'another custom message',
331cb0ef41Sopenharmony_ci  operator: 'fail',
341cb0ef41Sopenharmony_ci  actual: 'ignored',
351cb0ef41Sopenharmony_ci  expected: 'ignored',
361cb0ef41Sopenharmony_ci  generatedMessage: false
371cb0ef41Sopenharmony_ci});
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci// Three args with custom Error
401cb0ef41Sopenharmony_ciassert.throws(() => {
411cb0ef41Sopenharmony_ci  assert.fail(typeof 1, 'object', new TypeError('another custom message'));
421cb0ef41Sopenharmony_ci}, {
431cb0ef41Sopenharmony_ci  name: 'TypeError',
441cb0ef41Sopenharmony_ci  message: 'another custom message'
451cb0ef41Sopenharmony_ci});
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci// No third arg (but a fourth arg)
481cb0ef41Sopenharmony_ciassert.throws(() => {
491cb0ef41Sopenharmony_ci  assert.fail('first', 'second', undefined, 'operator');
501cb0ef41Sopenharmony_ci}, {
511cb0ef41Sopenharmony_ci  code: 'ERR_ASSERTION',
521cb0ef41Sopenharmony_ci  name: 'AssertionError',
531cb0ef41Sopenharmony_ci  message: '\'first\' operator \'second\'',
541cb0ef41Sopenharmony_ci  operator: 'operator',
551cb0ef41Sopenharmony_ci  actual: 'first',
561cb0ef41Sopenharmony_ci  expected: 'second'
571cb0ef41Sopenharmony_ci});
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci// The stackFrameFunction should exclude the foo frame
601cb0ef41Sopenharmony_ciassert.throws(
611cb0ef41Sopenharmony_ci  function foo() { assert.fail('first', 'second', 'message', '!==', foo); },
621cb0ef41Sopenharmony_ci  (err) => !/^\s*at\sfoo\b/m.test(err.stack)
631cb0ef41Sopenharmony_ci);
64