• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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';
23
24const common = require('../common');
25
26// Checks that the internal process.config is equivalent to the config.gypi file
27// created when we run configure.
28
29const assert = require('assert');
30const fs = require('fs');
31const path = require('path');
32
33// Check for existence of `process.config`.
34assert(Object.hasOwn(process, 'config'));
35
36// Ensure that `process.config` is an Object.
37assert.strictEqual(Object(process.config), process.config);
38
39const configPath = path.resolve(__dirname, '..', '..', 'config.gypi');
40
41if (!fs.existsSync(configPath)) {
42  common.skip('config.gypi does not exist.');
43}
44
45let config = fs.readFileSync(configPath, 'utf8');
46
47// Clean up comment at the first line.
48config = config.split('\n').slice(1).join('\n');
49config = config.replace(/"/g, '\\"');
50config = config.replace(/'/g, '"');
51config = JSON.parse(config, (key, value) => {
52  if (value === 'true') return true;
53  if (value === 'false') return false;
54  return value;
55});
56
57try {
58  assert.deepStrictEqual(config, process.config);
59} catch (e) {
60  // If the assert fails, it only shows 3 lines. We need all the output to
61  // compare.
62  console.log('config:', config);
63  console.log('process.config:', process.config);
64
65  throw e;
66}
67