1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23require('../common'); 24const fixtures = require('../common/fixtures'); 25const assert = require('assert'); 26const execFile = require('child_process').execFile; 27const depmod = fixtures.path('deprecated.js'); 28const node = process.execPath; 29 30const depUserlandFunction = 31 fixtures.path('deprecated-userland-function.js'); 32 33const depUserlandClass = 34 fixtures.path('deprecated-userland-class.js'); 35 36const depUserlandSubClass = 37 fixtures.path('deprecated-userland-subclass.js'); 38 39const normal = [depmod]; 40const noDep = ['--no-deprecation', depmod]; 41const traceDep = ['--trace-deprecation', depmod]; 42 43execFile(node, normal, function(er, stdout, stderr) { 44 console.error('normal: show deprecation warning'); 45 assert.strictEqual(er, null); 46 assert.strictEqual(stdout, ''); 47 assert.match(stderr, /this function is deprecated/); 48 console.log('normal ok'); 49}); 50 51execFile(node, noDep, function(er, stdout, stderr) { 52 console.error('--no-deprecation: silence deprecations'); 53 assert.strictEqual(er, null); 54 assert.strictEqual(stdout, ''); 55 assert.strictEqual(stderr.trim(), 'This is deprecated'); 56 console.log('silent ok'); 57}); 58 59execFile(node, traceDep, function(er, stdout, stderr) { 60 console.error('--trace-deprecation: show stack'); 61 assert.strictEqual(er, null); 62 assert.strictEqual(stdout, ''); 63 const stack = stderr.trim().split('\n'); 64 // Just check the top and bottom. 65 assert.match(stack[1], /this function is deprecated/); 66 assert.match(stack[0], /This is deprecated/); 67 console.log('trace ok'); 68}); 69 70execFile(node, [depUserlandFunction], function(er, stdout, stderr) { 71 console.error('normal: testing deprecated userland function'); 72 assert.strictEqual(er, null); 73 assert.strictEqual(stdout, ''); 74 assert.match(stderr, /deprecatedFunction is deprecated/); 75 console.error('normal: ok'); 76}); 77 78execFile(node, [depUserlandClass], function(er, stdout, stderr) { 79 assert.strictEqual(er, null); 80 assert.strictEqual(stdout, ''); 81 assert.match(stderr, /deprecatedClass is deprecated/); 82}); 83 84execFile(node, [depUserlandSubClass], function(er, stdout, stderr) { 85 assert.strictEqual(er, null); 86 assert.strictEqual(stdout, ''); 87 assert.match(stderr, /deprecatedClass is deprecated/); 88}); 89