Files: 65191f9a9664f013ebe726bb95a1a54b086e1bd5 / test / test-50-spawn / main.js
1839 bytesRaw
1 | |
2 | |
3 | 'use strict'; |
4 | |
5 | const fs = require('fs'); |
6 | const path = require('path'); |
7 | const assert = require('assert'); |
8 | const utils = require('../utils.js'); |
9 | |
10 | assert(!module.parent); |
11 | assert(__dirname === process.cwd()); |
12 | |
13 | const host = 'node' + process.version.match(/^v(\d+)/)[1]; |
14 | const target = process.argv[2] || host; |
15 | |
16 | function rnd () { |
17 | return Math.random().toString().slice(-6); |
18 | } |
19 | |
20 | const pairs = fs.readdirSync('.').filter(function (f) { |
21 | return (/\.js$/.test(f)) && |
22 | (f !== 'main.js') && |
23 | (!(/-child\.js$/.test(f))); |
24 | }).map(function (f) { |
25 | return ({ |
26 | input: f, output: './test-output-' + rnd() + '.exe' |
27 | }); |
28 | }); |
29 | |
30 | assert(pairs.length > 6); |
31 | |
32 | function stripTraceOpt (lines) { |
33 | return lines.split('\n').filter(function (line) { |
34 | return (line.indexOf('[disabled optimization') < 0) && |
35 | (line.indexOf('[marking') < 0) && |
36 | (line.indexOf('[compiling method') < 0) && |
37 | (line.indexOf('[optimizing') < 0) && |
38 | (line.indexOf('[completed optimizing') < 0) && |
39 | (line.indexOf('einfo:') < 0); |
40 | }).join('\n'); |
41 | } |
42 | |
43 | pairs.some(function (pair) { |
44 | const input = pair.input; |
45 | const output = pair.output; |
46 | |
47 | let left, right; |
48 | utils.mkdirp.sync(path.dirname(output)); |
49 | |
50 | left = utils.spawn.sync( |
51 | 'node', [ path.basename(input) ], |
52 | { cwd: path.dirname(input) } |
53 | ); |
54 | |
55 | utils.pkg.sync([ |
56 | '--target', target, |
57 | '--output', output, input |
58 | ]); |
59 | |
60 | right = utils.spawn.sync( |
61 | './' + path.basename(output), [], |
62 | { cwd: path.dirname(output) } |
63 | ); |
64 | |
65 | right = stripTraceOpt(right); |
66 | left = stripTraceOpt(left); |
67 | if (left !== right) { |
68 | console.log(JSON.stringify(pair)); |
69 | console.log('<<left<<\n' + left); |
70 | console.log('>>right>>\n' + right); |
71 | throw new Error('Assertion'); |
72 | } |
73 | |
74 | utils.vacuum.sync(output); |
75 | console.log(__dirname, input, 'ok'); |
76 | }); |
77 |
Built with git-ssb-web