Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cfa54fe
include relative file
YaroslavYaroslavtsev Jul 6, 2020
2a49db8
include relative file
YaroslavYaroslavtsev Jul 6, 2020
d067a2a
Merge branch 'feature/ADO-310-includes-enhancement' of https://github…
YaroslavYaroslavtsev Jul 6, 2020
699be77
local relative path builder tests completed
YaroslavYaroslavtsev Jul 8, 2020
b3541e2
__PATH__ variable implementation and appropriate tests fixed
vadim-galeev Jul 6, 2020
f676ba1
Merge branch 'feature/ADO-310-includes-enhancement' of https://github…
vadim-galeev Jul 9, 2020
769150f
IncludeRelativeLocal.spec.js fixes and licenses update
vadim-galeev Jul 10, 2020
32c69b9
Tests fixes for Windows
vadim-galeev Jul 10, 2020
17490fd
Some changes in algorithm of finding an included file
vadim-galeev Jul 15, 2020
10229c1
Little fixes
vadim-galeev Jul 15, 2020
e526c4f
include remote path tests added
YaroslavYaroslavtsev Jul 17, 2020
69534e8
Merge branch 'feature/ADO-310-includes-enhancement' of https://github…
YaroslavYaroslavtsev Jul 17, 2020
4a7ec04
remote path test and path variable tests added
YaroslavYaroslavtsev Jul 18, 2020
def626e
__PATH__ variable tests is refactored
YaroslavYaroslavtsev Jul 19, 2020
54b1ee8
update test files
YaroslavYaroslavtsev Jul 19, 2020
5f6b2af
all include tests is completed
YaroslavYaroslavtsev Jul 20, 2020
13100aa
small fix for linux platform
YaroslavYaroslavtsev Jul 20, 2020
64677e2
small fix for linux platform
YaroslavYaroslavtsev Jul 20, 2020
124ae1b
Little fixes
vadim-galeev Jul 20, 2020
ec1b48d
Some fixes for weblink paths
vadim-galeev Jul 21, 2020
be9d481
Update README.md
alexey-nbl Jul 22, 2020
6802a4d
Update README.md
alexey-nbl Jul 22, 2020
3dced84
A bit of refactoring
ragrus-nbl Jul 23, 2020
55f493f
Little fix
vadim-galeev Jul 23, 2020
37de5bb
root check added
YaroslavYaroslavtsev Jul 24, 2020
f366543
git-local path variable check added
YaroslavYaroslavtsev Jul 25, 2020
660b815
A bunch of fixes
vadim-galeev Jul 26, 2020
504e27d
Update README.md
vadim-galeev Jul 26, 2020
1869046
Some fixes for context.__PATH__ behaviour
vadim-galeev Jul 30, 2020
0b1c200
Improve the bugfix
ragrus-nbl Jul 30, 2020
e4b88e0
Improve the file searching
ragrus-nbl Jul 31, 2020
20e9a40
Update README.md
ragrus-nbl Jul 31, 2020
4dde70e
Change test dir name in fixture files
ragrus-nbl Jul 31, 2020
3f5f79a
Change test dir name in the spec file
ragrus-nbl Jul 31, 2020
30271b5
Redirect links to EI repo
ragrus-nbl Jul 31, 2020
70d4e53
Merge pull request #91 from EatonGMBD/feature/ADO-310-includes-enhanc…
zandr Aug 5, 2020
0fc0416
4.0.0
zandr Aug 5, 2020
def898d
v4.0.0
zandr Aug 6, 2020
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
667 changes: 427 additions & 240 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Builder",
"version": "3.3.0",
"version": "4.0.0",
"description": "Builder Language Implementation",
"main": "src/index.js",
"bin": {
Expand Down
8 changes: 6 additions & 2 deletions spec/Builder.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) 2016-2017 Electric Imp
// Copyright (c) 2016-2020 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

'use strict';

const Builder = require('../src');
const Machine = require('../src/Machine');
const path = require('path');

const contextPath = path.resolve(__dirname, './..').replace(/\\/g, '/');
const filePath = path.join(contextPath, 'main').replace(/\\/g, '/');

describe('Builder', () => {

Expand All @@ -21,7 +25,7 @@ describe('Builder', () => {
expect(builder.machine instanceof Machine).toBeTruthy();
builder.machine.generateLineControlStatements = true;
expect(builder.machine.execute('@{__FILE__}:@{__LINE__}'))
.toBe('#line 1 "main"\nmain:1');
.toBe('#line 1 "' + filePath + '"\nmain:1');
});

it('should execute "escape" filter', () => {
Expand Down
71 changes: 71 additions & 0 deletions spec/Include/IncludePath.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// MIT License
//
// Copyright 2020 Electric Imp
//
// SPDX-License-Identifier: MIT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

'use strict';

const Builder = require('../../src');
const backslashToSlash = require('../backslashToSlash');
const Log = require('log');
const path = require('path');
const fs = require('fs');

const LOCAL_REPO_NOT_DEFINED_MESSAGE = "SPEC_GIT_LOCAL_REPO_PATH is not defined. Test will be skipped";

describe('__PATH__ variable - ', () => {

let builder;
const contextPath = path.resolve(__dirname + "/../fixtures/lib/").replace(/\\/g, '/');

beforeEach(() => {
builder = new Builder();
builder.machine.path = contextPath;
builder.machine.readers.github.username = process.env.SPEC_GITHUB_USERNAME;
builder.machine.readers.github.token = process.env.SPEC_GITHUB_PASSWORD || process.env.SPEC_GITHUB_TOKEN;
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
});

it('__PATH__ should be a local path', () => {
let output = builder.machine.execute(`@include "${backslashToSlash(__dirname)}/../fixtures/lib/path.builder"`);
expect(output).toContain(contextPath + "#path.builder@1");
});

it('__PATH__ should be a git-local path', () => {
if (process.env.SPEC_GIT_LOCAL_REPO_PATH != undefined) {
let output = builder.machine.execute(`@include "git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/lib/path.builder@develop"`);
expect(output).toContain("git-local:" + backslashToSlash(process.env.SPEC_GIT_LOCAL_REPO_PATH) + "/spec/fixtures/lib#path.builder@1");
} else {
console.log(LOCAL_REPO_NOT_DEFINED_MESSAGE);
}
});

it('__PATH__ should be a remote repository path', () => {
let output = builder.machine.execute(`@include "github:electricimp/Builder/spec/fixtures/lib/path.builder@develop"`);
expect(output).toContain('github:electricimp/Builder/spec/fixtures/lib#path.builder@1\n');
});

it('__PATH__ should be a web link', () => {
let output = builder.machine.execute(`@include "https://raw.githubusercontent.com/electricimp/Builder/develop/spec/fixtures/lib/path.builder"`);
expect(output).toContain('https://raw.githubusercontent.com/electricimp/Builder/develop/spec/fixtures/lib#path.builder@1\n');
});
});
146 changes: 146 additions & 0 deletions spec/Include/IncludeRelativeLocal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// MIT License
//
// Copyright 2020 Electric Imp
//
// SPDX-License-Identifier: MIT
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

'use strict';

const Builder = require('../../src');
const backslashToSlash = require('../backslashToSlash');
const Log = require('log');
const path = require('path');
const fs = require('fs');

describe('Builder is called for file in included directory - ', () => {

let builder;
const contextPath = path.resolve(__dirname + "/../fixtures/include/sample-1/").replace(/\\/g, '/');

beforeEach(() => {
builder = new Builder();
builder.machine.path = contextPath;
builder.machine.readers.file.runDir = contextPath;
builder.machine.readers.file.inputFileDir = path.join(contextPath + '/dirZ');
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
});

it('should search Y file in directory where X file located', () => {
let output = builder.machine.execute(`@include "dirZ/file_case1.nut"`);
expect(output).toContain('// y.nut (case 1)\n');
});

it('should search Y file in directory where processing file located', () => {
let output = builder.machine.execute(`@include "dirZ/file_case2.nut"`);
expect(output).toContain('// y.nut (case 2)\n');
});

it('should search Y file in directory where builder called', () => {
let output = builder.machine.execute(`@include "dirZ/file_case3.nut"`);
expect(output).toContain('// y.nut (case 3)\n');
});

it('file not found', () => {
const filePath = path.join(contextPath, 'dirX/x_case4.nut').replace(/\\/g, '/');
const fileNotFoundMessage = `Local file "dirD/y4.nut" not found (${filePath}:1)`;
try {
builder.machine.execute(`@include "dirZ/file_case4.nut"`);
fail();
} catch (e) {
expect(backslashToSlash(e.message)).toEqual(fileNotFoundMessage);
}
});
});

describe('Builder is called for file in current directory - ', () => {

let builder;
const contextPath = path.resolve(__dirname + "/../fixtures/include/sample-1/dirZ").replace(/\\/g, '/');

beforeEach(() => {
builder = new Builder();
builder.machine.path = contextPath;
builder.machine.readers.file.runDir = contextPath;
builder.machine.readers.file.inputFileDir = path.join(contextPath);
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
});

it('should search Y file in directory where X file located', () => {
let output = builder.machine.execute(`@include "file_case1.nut"`);
expect(output).toContain('// y.nut (case 1)\n');
});

it('should search Y file in directory where processing file located', () => {
let output = builder.machine.execute(`@include "file_case2.nut"`);
expect(output).toContain('// y.nut (case 2)\n');
});

it('should search Y file in directory where builder called', () => {
const filePath = path.join(contextPath, '/../dirX/x_case3.nut').replace(/\\/g, '/');
const fileNotFoundMessage = `Local file "dirD/y3.nut" not found (${filePath}:1)`;
try {
builder.machine.execute(`@include "file_case3.nut"`);
fail();
} catch (e) {
expect(backslashToSlash(e.message)).toEqual(fileNotFoundMessage);
}
});
});

describe('Builder is called for file in deep included directory - ', () => {

let builder;
const contextPath = path.resolve(__dirname + "/../fixtures/include/").replace(/\\/g, '/');

beforeEach(() => {
builder = new Builder();
builder.machine.path = contextPath;
builder.machine.readers.file.runDir = contextPath;
builder.machine.readers.file.inputFileDir = path.join(contextPath + '/sample-1/dirZ');
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
});

it('should search Y file in directory where X file located', () => {
let output = builder.machine.execute(`@include "sample-1/dirZ/file_case1.nut"`);
expect(output).toContain('// y.nut (case 1)\n');
});

it('should search Y file in directory where processing file located', () => {
let output = builder.machine.execute(`@include "sample-1/dirZ/file_case2.nut"`);
expect(output).toContain('// y.nut (case 2)\n');
});

it('file not found', () => {
const filePath = path.join(contextPath, 'sample-1/dirX/x_case3.nut').replace(/\\/g, '/');
const fileNotFoundMessage = `Local file "dirD/y3.nut" not found (${filePath}:1)`;
try {
builder.machine.execute(`@include "sample-1/dirZ/file_case3.nut"`);
fail();
} catch (e) {
expect(backslashToSlash(e.message)).toEqual(fileNotFoundMessage);
}
});

it('should search Y file in directory where builder called', () => {
let output = builder.machine.execute(`@include "sample-1/dirZ/file_case4.nut"`);
expect(output).toContain('// y.nut (case 4)\n');
});
});
Loading