Skip to content

Commit 7f149f2

Browse files
author
betzrhodes
authored
Merge pull request #60 from electricimp/develop
Develop
2 parents b457298 + db45590 commit 7f149f2

10 files changed

+783
-152
lines changed

Diff for: README.md

+172-69
Large diffs are not rendered by default.

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Builder",
3-
"version": "2.6.0",
3+
"version": "2.7.0",
44
"description": "Builder Language Implementation",
55
"main": "src/index.js",
66
"bin": {
@@ -22,8 +22,9 @@
2222
"homepage": "https://github.com/electricimp/Builder#readme",
2323
"dependencies": {
2424
"clone": "^1.0.2",
25-
"@octokit/rest": "^15.2.6",
25+
"@octokit/rest": "^16.20.0",
2626
"glob": "^7.1.2",
27+
"https-proxy-agent": "^2.2.1",
2728
"jsep": "^0.3.1",
2829
"request": "^2.71.0",
2930
"md5": "^2.2.1",

Diff for: spec/Machine/suppress-duplicate.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Machine', () => {
4444

4545
machine.suppressDupWarning = false;
4646
const res = eol.lf(machine.execute(
47-
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
47+
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
4848
@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder_copy"`
4949
));
5050
expect(res).toEqual(`a.builder\na.builder\n`);
@@ -64,10 +64,10 @@ describe('Machine', () => {
6464
});
6565

6666
const res = eol.lf(machine.execute(
67-
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
67+
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
6868
@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder_copy"`
6969
));
70-
expect(res).toEqual(`a.builder\na.builder\n`);
70+
expect(res).toEqual(`a.builder\na.builder\n`);
7171
} catch (e) {
7272
fail(e);
7373
}

Diff for: spec/Machine/use-dependencies.spec.js

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright (c) 2016-2019 Electric Imp
2+
// This file is licensed under the MIT License
3+
// http://opensource.org/licenses/MIT
4+
5+
'use strict';
6+
7+
require('jasmine-expect');
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
const Fixture = require('fixture-stdout');
12+
const stderrFixture = new Fixture({ stream: process.stderr });
13+
const init = require('./init')('main');
14+
const eol = require('eol');
15+
const backslashToSlash = require('../backslashToSlash');
16+
17+
const dependenciesUseFile = path.join(process.cwd(), 'use_dependencies.json');
18+
const dependenciesSaveFile = path.join(process.cwd(), 'save_dependencies.json');
19+
20+
describe('Machine', () => {
21+
let machine;
22+
23+
beforeEach(() => {
24+
machine = init.createMachine();
25+
});
26+
27+
it('Create and read dependencies JSON file', () => {
28+
const rev1GitBlobID = "c22db87f08ae30a4a0d3450daabb34029b3d50e7";
29+
const rev1Content = "// included file a\n// included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
30+
const rev0GitBlobID = "9db26aa9017943a7812ab6751a699cd1c7247370";
31+
const rev0Content = "// included file a\n // included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
32+
const url = 'github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out';
33+
34+
// ensure that test dependencies JSON file does not exist
35+
if (fs.existsSync(dependenciesSaveFile)) {
36+
fs.unlinkSync(dependenciesSaveFile);
37+
}
38+
39+
machine.dependenciesSaveFile = dependenciesSaveFile;
40+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
41+
42+
// check dependencies JSON file content
43+
const rev1Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
44+
expect(rev1Map.size).toEqual(1);
45+
expect(rev1Map.get(url)).toEqual(rev1GitBlobID);
46+
47+
// replace the actual commit ID to previous
48+
rev1Map.set(url, rev0GitBlobID);
49+
fs.writeFileSync(dependenciesSaveFile, JSON.stringify([...rev1Map], null, 2), 'utf-8');
50+
51+
machine.dependenciesUseFile = dependenciesSaveFile;
52+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);
53+
54+
// check dependencies JSON file content again
55+
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
56+
expect(rev0Map.size).toEqual(1);
57+
expect(rev0Map.get(url)).toEqual(rev0GitBlobID);
58+
59+
// unlink dependencies file to avoid conflicts with unit-tests below
60+
fs.unlinkSync(dependenciesSaveFile);
61+
});
62+
63+
it('Check dependencies JSON if github ref already provided', () => {
64+
const rev0GitBlobID = "9db26aa9017943a7812ab6751a699cd1c7247370";
65+
const rev0CommitID = "e2a5b434b34b5737b2ff52f51a92c5bbcc9f83bf";
66+
const rev0Content = "// included file a\n // included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
67+
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out@${rev0CommitID}`;
68+
69+
// ensure that test dependencies JSON file does not exist
70+
if (fs.existsSync(dependenciesSaveFile)) {
71+
fs.unlinkSync(dependenciesSaveFile);
72+
}
73+
74+
machine.dependenciesSaveFile = dependenciesSaveFile;
75+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);
76+
77+
// check dependencies JSON file content again
78+
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
79+
expect(rev0Map.size).toEqual(1);
80+
expect(rev0Map.get(url)).toEqual(rev0GitBlobID);
81+
82+
// unlink dependencies file to avoid conflicts with unit-tests below
83+
fs.unlinkSync(dependenciesSaveFile);
84+
});
85+
86+
it('Check ---save-dependecies/--use-dependencies options combination', () => {
87+
const rev1Content = "// included file a\n// included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
88+
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out`;
89+
90+
// ensure that test dependencies JSON file does not exist
91+
if (fs.existsSync(dependenciesUseFile)) {
92+
fs.unlinkSync(dependenciesUseFile);
93+
}
94+
95+
machine.dependenciesSaveFile = dependenciesUseFile;
96+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
97+
98+
// check that dependencies JSON file was created
99+
if (!fs.existsSync(dependenciesUseFile)) {
100+
fail(`The ${dependenciesUseFile} file does not exist.`);
101+
}
102+
103+
machine.dependenciesUseFile = dependenciesUseFile;
104+
machine.dependenciesSaveFile = dependenciesSaveFile;
105+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
106+
107+
// check that dependencies JSON file was created
108+
if (!fs.existsSync(dependenciesSaveFile)) {
109+
fail(`The ${dependenciesSaveFile} file does not exist.`);
110+
}
111+
112+
// check that files are identical
113+
expect(fs.readFileSync(dependenciesUseFile)).toEqual(fs.readFileSync(dependenciesSaveFile));
114+
115+
// unlink directives file to avoid conflicts with unit-tests below
116+
fs.unlinkSync(dependenciesSaveFile);
117+
fs.unlinkSync(dependenciesUseFile);
118+
});
119+
120+
it('Check case when dependencies JSON file is corrupted', () => {
121+
const rev1Content = "// included file a\n// included file b\n\n\n // should be included\n\n // l2 else\n\n\n // should be included\n";
122+
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out`;
123+
124+
// ensure that test dependencies JSON file does not exist
125+
if (fs.existsSync(dependenciesSaveFile)) {
126+
fs.unlinkSync(dependenciesSaveFile);
127+
}
128+
129+
machine.dependenciesSaveFile = dependenciesSaveFile;
130+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
131+
132+
// Check dependencies JSON file content again
133+
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
134+
expect(rev0Map.size).toEqual(1);
135+
136+
// corrupt the file
137+
fs.appendFileSync(dependenciesSaveFile, ']');
138+
139+
const fileCorruptedMessage = `The dependencies JSON file '${dependenciesSaveFile}' cannot be used: Unexpected token ] in JSON at position 127`;
140+
141+
// check exception error message
142+
try {
143+
machine.dependenciesUseFile = dependenciesSaveFile;
144+
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
145+
} catch (e) {
146+
expect(e.message).toEqual(fileCorruptedMessage);
147+
}
148+
149+
// unlink directives file to avoid conflicts with unit-tests below
150+
fs.unlinkSync(dependenciesSaveFile);
151+
});
152+
});

Diff for: spec/Machine/use-directives.spec.js

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Copyright (c) 2016-2019 Electric Imp
2+
// This file is licensed under the MIT License
3+
// http://opensource.org/licenses/MIT
4+
5+
'use strict';
6+
7+
require('jasmine-expect');
8+
9+
const fs = require('fs');
10+
const path = require('path');
11+
const init = require('./init')('main');
12+
const eol = require('eol');
13+
14+
const directivesUseFile = path.join(process.cwd(), 'use_directives.json');
15+
const directivesSaveFile = path.join(process.cwd(), 'save_directives.json');
16+
17+
describe('Machine', () => {
18+
let machine;
19+
20+
beforeEach(() => {
21+
machine = init.createMachine();
22+
});
23+
24+
it('Create and read directives JSON file', () => {
25+
const directives = {
26+
IntType: 34,
27+
FloatType: 34.456,
28+
ExponentType1: 3E4,
29+
ExponentType2: 3e-2,
30+
StringType1: "str1",
31+
StringType2: "\"str2\"",
32+
BoolTypeTrue: true,
33+
BoolTypeFalse: false,
34+
NullType: null
35+
};
36+
37+
const directivesSource = "@{IntType} @{FloatType} @{ExponentType1} @{ExponentType2} @{StringType1} @{StringType2} @{BoolTypeTrue} @{BoolTypeFalse} @{NullType}";
38+
const expectedOutput = `34 34.456 30000 0.03 str1 "str2" true false null`;
39+
40+
// ensure that test JSON file does not exist
41+
if (fs.existsSync(directivesSaveFile)) {
42+
fs.unlinkSync(directivesSaveFile);
43+
}
44+
45+
// create directives file
46+
machine.directivesSaveFile = directivesSaveFile;
47+
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);
48+
49+
// check that JSON file was created
50+
if (!fs.existsSync(directivesSaveFile)) {
51+
fail(`The ${directivesSaveFile} file does not exist.`);
52+
}
53+
54+
// check that we are able to read variables definitions from JSON file
55+
machine.directivesUseFile = directivesSaveFile;
56+
expect(eol.lf(machine.execute(directivesSource))).toBe(expectedOutput);
57+
58+
// unlink directives file to avoid conflicts with unit-tests below
59+
fs.unlinkSync(directivesSaveFile);
60+
});
61+
62+
it('Check that directives JSON file content is able to be merged with additional variable definitions', () => {
63+
const directives = {
64+
Int0: 990,
65+
Int1: 991,
66+
};
67+
68+
const directivesSource = "@{Int0} @{Int1}";
69+
const expectedOutput = `990 991`;
70+
71+
// ensure that test directives JSON file does not exist
72+
if (fs.existsSync(directivesSaveFile)) {
73+
fs.unlinkSync(directivesSaveFile);
74+
}
75+
76+
// create directives file
77+
machine.directivesSaveFile = directivesSaveFile;
78+
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);
79+
80+
// check that JSON file was created
81+
if (!fs.existsSync(directivesSaveFile)) {
82+
fail(`The ${directivesSaveFile} file does not exist.`);
83+
}
84+
85+
// check that we are able to read variables definitions from JSON file
86+
machine.directivesUseFile = directivesSaveFile;
87+
expect(eol.lf(machine.execute(directivesSource + " @{Int2}", {Int2: 992}))).toBe(expectedOutput + " 992");
88+
89+
// unlink directives file to avoid conflicts with unit-tests below
90+
fs.unlinkSync(directivesSaveFile);
91+
});
92+
93+
it('Check ---save-directives/--use-directives options combination', () => {
94+
const directives = {
95+
Int0: 550,
96+
Int1: 551,
97+
Int2: 552,
98+
};
99+
100+
const directivesSource = "@{Int0} @{Int1} @{Int2}";
101+
const expectedOutput = `550 551 552`;
102+
103+
// ensure that test JSON file does not exist
104+
if (fs.existsSync(directivesSaveFile)) {
105+
fs.unlinkSync(directivesSaveFile);
106+
}
107+
108+
// create directives file
109+
machine.directivesSaveFile = directivesUseFile;
110+
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);
111+
112+
// check that directives JSON file was created
113+
if (!fs.existsSync(directivesUseFile)) {
114+
fail(`The ${directivesUseFile} file does not exist.`);
115+
}
116+
117+
machine.directivesUseFile = directivesUseFile;
118+
machine.directivesSaveFile = directivesSaveFile;
119+
eol.lf(machine.execute(directivesSource, directives));
120+
121+
// check that directives JSON file was created
122+
if (!fs.existsSync(directivesSaveFile)) {
123+
fail(`The ${directivesSaveFile} file does not exist.`);
124+
}
125+
126+
// check that files are identical
127+
expect(fs.readFileSync(directivesUseFile)).toEqual(fs.readFileSync(directivesSaveFile));
128+
129+
// unlink directives file to avoid conflicts with unit-tests below
130+
fs.unlinkSync(directivesSaveFile);
131+
fs.unlinkSync(directivesUseFile);
132+
});
133+
134+
it('Check case when directives JSON file appear to be corrupted', () => {
135+
const directives = {
136+
Int0: 550,
137+
Int1: 551,
138+
Int2: 552,
139+
};
140+
141+
const directivesSource = "@{Int0} @{Int1} @{Int2}";
142+
const expectedOutput = `550 551 552`;
143+
144+
// ensure that test JSON file does not exist
145+
if (fs.existsSync(directivesSaveFile)) {
146+
fs.unlinkSync(directivesSaveFile);
147+
}
148+
149+
// create directives file
150+
machine.directivesSaveFile = directivesSaveFile;
151+
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);
152+
153+
// check that directives JSON file was created
154+
if (!fs.existsSync(directivesSaveFile)) {
155+
fail(`The ${directivesSaveFile} file does not exist.`);
156+
}
157+
158+
// corrupt the file
159+
fs.appendFileSync(directivesSaveFile, ']');
160+
161+
const fileCorruptedMessage = `The directives JSON file '${directivesSaveFile}' cannot be used: Unexpected token ] in JSON at position 47`;
162+
163+
// check exception error message
164+
try {
165+
machine.directivesSaveFile = undefined;
166+
machine.directivesUseFile = directivesSaveFile;
167+
eol.lf(machine.execute(directivesSource, directives));
168+
} catch (e) {
169+
expect(e.message).toEqual(fileCorruptedMessage);
170+
}
171+
172+
// unlink directives file to avoid conflicts with unit-tests below
173+
fs.unlinkSync(directivesSaveFile);
174+
});
175+
});

Diff for: spec/fixtures/lib/g.builder

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
g.builder.rev1

0 commit comments

Comments
 (0)