Remove excessive copyright/license boilerplate
[platform/upstream/nodejs.git] / test / parallel / test-process-env.js
1 // first things first, set the timezone; see tzset(3)
2 process.env.TZ = 'Europe/Amsterdam';
3
4 var common = require('../common');
5 var assert = require('assert');
6 var spawn = require('child_process').spawn;
7
8 /* For the moment we are not going to support setting the timezone via the
9  * environment variables. The problem is that various V8 platform backends
10  * deal with timezone in different ways. The windows platform backend caches
11  * the timezone value while the Linux one hits libc for every query.
12
13 https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-linux.cc#L339-345
14 https://github.com/joyent/node/blob/08782931205bc4f6d28102ebc29fd806e8ccdf1f/deps/v8/src/platform-win32.cc#L590-596
15
16
17 // time difference between Greenwich and Amsterdam is +2 hours in the summer
18 date = new Date('Fri, 10 Sep 1982 03:15:00 GMT');
19 assert.equal(3, date.getUTCHours());
20 assert.equal(5, date.getHours());
21 */
22
23
24 // changes in environment should be visible to child processes
25 if (process.argv[2] == 'you-are-the-child') {
26   // failed assertion results in process exiting with status code 1
27   assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);
28   assert.equal(42, process.env.NODE_PROCESS_ENV);
29   assert.equal('asdf', process.env.hasOwnProperty);
30   var hasOwnProperty = Object.prototype.hasOwnProperty;
31   var has = hasOwnProperty.call(process.env, 'hasOwnProperty');
32   assert.equal(true, has);
33   process.exit(0);
34 } else {
35   assert.equal(Object.prototype.hasOwnProperty, process.env.hasOwnProperty);
36   var has = process.env.hasOwnProperty('hasOwnProperty');
37   assert.equal(false, has);
38
39   process.env.hasOwnProperty = 'asdf';
40
41   process.env.NODE_PROCESS_ENV = 42;
42   assert.equal(42, process.env.NODE_PROCESS_ENV);
43
44   process.env.NODE_PROCESS_ENV_DELETED = 42;
45   assert.equal(true, 'NODE_PROCESS_ENV_DELETED' in process.env);
46
47   delete process.env.NODE_PROCESS_ENV_DELETED;
48   assert.equal(false, 'NODE_PROCESS_ENV_DELETED' in process.env);
49
50   var child = spawn(process.argv[0], [process.argv[1], 'you-are-the-child']);
51   child.stdout.on('data', function(data) { console.log(data.toString()); });
52   child.stderr.on('data', function(data) { console.log(data.toString()); });
53   child.on('exit', function(statusCode) {
54     if (statusCode != 0) {
55       process.exit(statusCode);  // failed assertion in child process
56     }
57   });
58 }