Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #60

Merged
merged 52 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
aa531a2
CSE-711: Initial version of use-directives feature.
Mar 23, 2019
80ddee9
CSE-711: Starting implementation of --use-dependencies feature.
Mar 23, 2019
88bb517
CSE-711: Very initial version of --use-dependencies feature.
Mar 25, 2019
3401a7e
Update @octokit/rest version.
Mar 26, 2019
46079a5
Remove deprecated arguments from Octokit() constructor.
Mar 26, 2019
eb11e2e
Update new features description.
Mar 26, 2019
cca92d5
More comments + some refactoring.
Mar 26, 2019
5acac24
Merge develop with '--suppress-duplicate-includes-warning' feature wi…
Mar 27, 2019
79a5eb2
Prepare --use-dependencies option test file, step 1.
Mar 27, 2019
b8e3179
Prepare --use-dependencies option test file, step 2.
Mar 27, 2019
d3a0bd2
Command line tool script formatting fixes.
Mar 27, 2019
e9635eb
Misc fixes before unit-tests implementation.
Mar 28, 2019
732fb24
Add unit-tests for 'reproducible artifacts built from github' feature.
Mar 28, 2019
14a51c0
Fix formattig.
Apr 1, 2019
760bc64
Use new CLI options specification for 'directives'.
Apr 1, 2019
ace1a21
Use git blob IDs instead of commit IDs.
Apr 1, 2019
ab3bda3
Move dependencies JSON file manipulations logic out of GitHubReader c…
Apr 2, 2019
c56bf5b
Do not use file cache if dependencies are provided.
Apr 3, 2019
d95b81d
Fix unit-tests for 'dependencies' feature according new implementation.
Apr 3, 2019
a49caa2
Fix formatting in the different places.
Apr 3, 2019
06fbd40
Merge branch 'develop' of https://github.com/electricimp/Builder into…
Apr 3, 2019
2e1eed6
Fix pleasebuild command line options description.
Apr 3, 2019
df271da
Add additional test-case to 'dependencies' feature + fix GithubReader…
Apr 3, 2019
7637fef
Fix comments in the unit-tests.
Apr 3, 2019
a0ae239
Update README.md + pass to the processError() function additional arg…
Apr 3, 2019
4cbb625
Some features refactoring + add note about --catch option to README.md
Apr 5, 2019
1220198
Make directives/dependencies values optional.
Apr 5, 2019
7e647e0
Misc fixes in the command line interface.
Apr 6, 2019
7c25bb9
Fix typo in the default file name.
Apr 9, 2019
8207c7b
Merge pull request #24 from nobitlost/CSE-711
FedorUporov Apr 9, 2019
86cfec9
Merge with upstream master.
Apr 9, 2019
8ec9f10
re-writed Running Builder, added TODOs
alexey-nbl Apr 10, 2019
9d5d4fa
README.md: Add more detailed options description.
Apr 10, 2019
0f69163
partial cleanup of readme
alexey-nbl Apr 11, 2019
f0bdbe0
readme: minor update
alexey-nbl Apr 11, 2019
c3720ad
readme: removed JSON from options descr
alexey-nbl Apr 14, 2019
207ea65
Make CLI 'help' description consistent with README.md.
Apr 14, 2019
aa53b92
Make CLI 'usage' compatible with README.md.
Apr 14, 2019
95b77d9
Increase the version + misc CLI 'help' fixes.
Apr 14, 2019
017d64e
Merge pull request #27 from nobitlost/develop
FedorUporov Apr 14, 2019
a9d3db2
Merge README.md with EI deelop.
Apr 14, 2019
27f63d4
Merge branch 'master' of https://github.com/nobitlost/Builder into no…
Apr 15, 2019
db8a710
Merge branch 'nobitlost-master' into feature/docs
Apr 15, 2019
04aa1f6
Initial edit: style and language fixes.
smittytone Apr 16, 2019
e3d4639
Merge pull request #59 from nobitlost/master
Apr 16, 2019
f00fbc6
updated file examples
Apr 16, 2019
a1d1254
Merge pull request #61 from electricimp/feature/docs
Apr 16, 2019
5618a46
Increase minimum nodejs version and do not use object spread operators.
Apr 18, 2019
5bd149f
Merge pull request #29 from nobitlost/develop
FedorUporov Apr 18, 2019
e9e2458
Merge with EI/develop.
Apr 18, 2019
90957cf
Fix incorrect README.md merge.
Apr 18, 2019
db45590
Merge pull request #62 from nobitlost/master
Apr 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 172 additions & 69 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Builder",
"version": "2.6.0",
"version": "2.7.0",
"description": "Builder Language Implementation",
"main": "src/index.js",
"bin": {
Expand All @@ -22,8 +22,9 @@
"homepage": "https://github.com/electricimp/Builder#readme",
"dependencies": {
"clone": "^1.0.2",
"@octokit/rest": "^15.2.6",
"@octokit/rest": "^16.20.0",
"glob": "^7.1.2",
"https-proxy-agent": "^2.2.1",
"jsep": "^0.3.1",
"request": "^2.71.0",
"md5": "^2.2.1",
Expand Down
6 changes: 3 additions & 3 deletions spec/Machine/suppress-duplicate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Machine', () => {

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

const res = eol.lf(machine.execute(
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
`@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder"
@include once "${backslashToSlash(__dirname)}/../fixtures/lib/a.builder_copy"`
));
expect(res).toEqual(`a.builder\na.builder\n`);
expect(res).toEqual(`a.builder\na.builder\n`);
} catch (e) {
fail(e);
}
Expand Down
152 changes: 152 additions & 0 deletions spec/Machine/use-dependencies.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright (c) 2016-2019 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

'use strict';

require('jasmine-expect');

const fs = require('fs');
const path = require('path');
const Fixture = require('fixture-stdout');
const stderrFixture = new Fixture({ stream: process.stderr });
const init = require('./init')('main');
const eol = require('eol');
const backslashToSlash = require('../backslashToSlash');

const dependenciesUseFile = path.join(process.cwd(), 'use_dependencies.json');
const dependenciesSaveFile = path.join(process.cwd(), 'save_dependencies.json');

describe('Machine', () => {
let machine;

beforeEach(() => {
machine = init.createMachine();
});

it('Create and read dependencies JSON file', () => {
const rev1GitBlobID = "c22db87f08ae30a4a0d3450daabb34029b3d50e7";
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";
const rev0GitBlobID = "9db26aa9017943a7812ab6751a699cd1c7247370";
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";
const url = 'github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out';

// ensure that test dependencies JSON file does not exist
if (fs.existsSync(dependenciesSaveFile)) {
fs.unlinkSync(dependenciesSaveFile);
}

machine.dependenciesSaveFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);

// check dependencies JSON file content
const rev1Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
expect(rev1Map.size).toEqual(1);
expect(rev1Map.get(url)).toEqual(rev1GitBlobID);

// replace the actual commit ID to previous
rev1Map.set(url, rev0GitBlobID);
fs.writeFileSync(dependenciesSaveFile, JSON.stringify([...rev1Map], null, 2), 'utf-8');

machine.dependenciesUseFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);

// check dependencies JSON file content again
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
expect(rev0Map.size).toEqual(1);
expect(rev0Map.get(url)).toEqual(rev0GitBlobID);

// unlink dependencies file to avoid conflicts with unit-tests below
fs.unlinkSync(dependenciesSaveFile);
});

it('Check dependencies JSON if github ref already provided', () => {
const rev0GitBlobID = "9db26aa9017943a7812ab6751a699cd1c7247370";
const rev0CommitID = "e2a5b434b34b5737b2ff52f51a92c5bbcc9f83bf";
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";
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out@${rev0CommitID}`;

// ensure that test dependencies JSON file does not exist
if (fs.existsSync(dependenciesSaveFile)) {
fs.unlinkSync(dependenciesSaveFile);
}

machine.dependenciesSaveFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev0Content);

// check dependencies JSON file content again
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
expect(rev0Map.size).toEqual(1);
expect(rev0Map.get(url)).toEqual(rev0GitBlobID);

// unlink dependencies file to avoid conflicts with unit-tests below
fs.unlinkSync(dependenciesSaveFile);
});

it('Check ---save-dependecies/--use-dependencies options combination', () => {
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";
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out`;

// ensure that test dependencies JSON file does not exist
if (fs.existsSync(dependenciesUseFile)) {
fs.unlinkSync(dependenciesUseFile);
}

machine.dependenciesSaveFile = dependenciesUseFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);

// check that dependencies JSON file was created
if (!fs.existsSync(dependenciesUseFile)) {
fail(`The ${dependenciesUseFile} file does not exist.`);
}

machine.dependenciesUseFile = dependenciesUseFile;
machine.dependenciesSaveFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);

// check that dependencies JSON file was created
if (!fs.existsSync(dependenciesSaveFile)) {
fail(`The ${dependenciesSaveFile} file does not exist.`);
}

// check that files are identical
expect(fs.readFileSync(dependenciesUseFile)).toEqual(fs.readFileSync(dependenciesSaveFile));

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(dependenciesSaveFile);
fs.unlinkSync(dependenciesUseFile);
});

it('Check case when dependencies JSON file is corrupted', () => {
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";
const url = `github:nobitlost/Builder/spec/fixtures/sample-1/input.nut.out`;

// ensure that test dependencies JSON file does not exist
if (fs.existsSync(dependenciesSaveFile)) {
fs.unlinkSync(dependenciesSaveFile);
}

machine.dependenciesSaveFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);

// Check dependencies JSON file content again
const rev0Map = new Map(JSON.parse(fs.readFileSync(dependenciesSaveFile)));
expect(rev0Map.size).toEqual(1);

// corrupt the file
fs.appendFileSync(dependenciesSaveFile, ']');

const fileCorruptedMessage = `The dependencies JSON file '${dependenciesSaveFile}' cannot be used: Unexpected token ] in JSON at position 127`;

// check exception error message
try {
machine.dependenciesUseFile = dependenciesSaveFile;
expect(eol.lf(machine.execute(`@include "${url}"`))).toBe(rev1Content);
} catch (e) {
expect(e.message).toEqual(fileCorruptedMessage);
}

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(dependenciesSaveFile);
});
});
175 changes: 175 additions & 0 deletions spec/Machine/use-directives.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) 2016-2019 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

'use strict';

require('jasmine-expect');

const fs = require('fs');
const path = require('path');
const init = require('./init')('main');
const eol = require('eol');

const directivesUseFile = path.join(process.cwd(), 'use_directives.json');
const directivesSaveFile = path.join(process.cwd(), 'save_directives.json');

describe('Machine', () => {
let machine;

beforeEach(() => {
machine = init.createMachine();
});

it('Create and read directives JSON file', () => {
const directives = {
IntType: 34,
FloatType: 34.456,
ExponentType1: 3E4,
ExponentType2: 3e-2,
StringType1: "str1",
StringType2: "\"str2\"",
BoolTypeTrue: true,
BoolTypeFalse: false,
NullType: null
};

const directivesSource = "@{IntType} @{FloatType} @{ExponentType1} @{ExponentType2} @{StringType1} @{StringType2} @{BoolTypeTrue} @{BoolTypeFalse} @{NullType}";
const expectedOutput = `34 34.456 30000 0.03 str1 "str2" true false null`;

// ensure that test JSON file does not exist
if (fs.existsSync(directivesSaveFile)) {
fs.unlinkSync(directivesSaveFile);
}

// create directives file
machine.directivesSaveFile = directivesSaveFile;
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);

// check that JSON file was created
if (!fs.existsSync(directivesSaveFile)) {
fail(`The ${directivesSaveFile} file does not exist.`);
}

// check that we are able to read variables definitions from JSON file
machine.directivesUseFile = directivesSaveFile;
expect(eol.lf(machine.execute(directivesSource))).toBe(expectedOutput);

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(directivesSaveFile);
});

it('Check that directives JSON file content is able to be merged with additional variable definitions', () => {
const directives = {
Int0: 990,
Int1: 991,
};

const directivesSource = "@{Int0} @{Int1}";
const expectedOutput = `990 991`;

// ensure that test directives JSON file does not exist
if (fs.existsSync(directivesSaveFile)) {
fs.unlinkSync(directivesSaveFile);
}

// create directives file
machine.directivesSaveFile = directivesSaveFile;
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);

// check that JSON file was created
if (!fs.existsSync(directivesSaveFile)) {
fail(`The ${directivesSaveFile} file does not exist.`);
}

// check that we are able to read variables definitions from JSON file
machine.directivesUseFile = directivesSaveFile;
expect(eol.lf(machine.execute(directivesSource + " @{Int2}", {Int2: 992}))).toBe(expectedOutput + " 992");

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(directivesSaveFile);
});

it('Check ---save-directives/--use-directives options combination', () => {
const directives = {
Int0: 550,
Int1: 551,
Int2: 552,
};

const directivesSource = "@{Int0} @{Int1} @{Int2}";
const expectedOutput = `550 551 552`;

// ensure that test JSON file does not exist
if (fs.existsSync(directivesSaveFile)) {
fs.unlinkSync(directivesSaveFile);
}

// create directives file
machine.directivesSaveFile = directivesUseFile;
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);

// check that directives JSON file was created
if (!fs.existsSync(directivesUseFile)) {
fail(`The ${directivesUseFile} file does not exist.`);
}

machine.directivesUseFile = directivesUseFile;
machine.directivesSaveFile = directivesSaveFile;
eol.lf(machine.execute(directivesSource, directives));

// check that directives JSON file was created
if (!fs.existsSync(directivesSaveFile)) {
fail(`The ${directivesSaveFile} file does not exist.`);
}

// check that files are identical
expect(fs.readFileSync(directivesUseFile)).toEqual(fs.readFileSync(directivesSaveFile));

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(directivesSaveFile);
fs.unlinkSync(directivesUseFile);
});

it('Check case when directives JSON file appear to be corrupted', () => {
const directives = {
Int0: 550,
Int1: 551,
Int2: 552,
};

const directivesSource = "@{Int0} @{Int1} @{Int2}";
const expectedOutput = `550 551 552`;

// ensure that test JSON file does not exist
if (fs.existsSync(directivesSaveFile)) {
fs.unlinkSync(directivesSaveFile);
}

// create directives file
machine.directivesSaveFile = directivesSaveFile;
expect(eol.lf(machine.execute(directivesSource, directives))).toBe(expectedOutput);

// check that directives JSON file was created
if (!fs.existsSync(directivesSaveFile)) {
fail(`The ${directivesSaveFile} file does not exist.`);
}

// corrupt the file
fs.appendFileSync(directivesSaveFile, ']');

const fileCorruptedMessage = `The directives JSON file '${directivesSaveFile}' cannot be used: Unexpected token ] in JSON at position 47`;

// check exception error message
try {
machine.directivesSaveFile = undefined;
machine.directivesUseFile = directivesSaveFile;
eol.lf(machine.execute(directivesSource, directives));
} catch (e) {
expect(e.message).toEqual(fileCorruptedMessage);
}

// unlink directives file to avoid conflicts with unit-tests below
fs.unlinkSync(directivesSaveFile);
});
});
1 change: 1 addition & 0 deletions spec/fixtures/lib/g.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.builder.rev1
Loading