Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
89 changes: 70 additions & 19 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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Builder",
"version": "3.2.0",
"version": "3.3.0",
"description": "Builder Language Implementation",
"main": "src/index.js",
"bin": {
Expand All @@ -10,6 +10,7 @@
"test": "jasmine",
"test:bitbucket-server": "node ./spec/BitbucketServerExecutor.js",
"test:azure-repos": "node ./spec/AzureReposExecutor.js",
"test:git-local": "node ./spec/GitLocalExecutor.js",
"build": "src/cli.js input"
},
"repository": {
Expand Down
75 changes: 75 additions & 0 deletions spec/GitLocal/GitLocalReader.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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 fs = require('fs');
const Log = require('log');
const eol = require('eol');
const path = require('path');
const GitLocalReader = require('../../src/Readers/GitLocalReader');

describe('GitLocalReader', () => {
let reader;

beforeEach(function() {
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
fail('Some of the required environment variables are not set');
return;
}

reader = new GitLocalReader();

// @see https://www.npmjs.com/package/log#log-levels
reader.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
});

it('should read sample#1 from local git repo', () => {
const expectedContent = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
let resultContent;

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut`);
expect(resultContent).toEqual(expectedContent);

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut`);
expect(resultContent).toEqual(expectedContent);

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/./spec/../spec/fixtures/sample-1/input.nut@master`);
expect(resultContent).toEqual(expectedContent);
});

it('should read sample#1 from local git repo with refs', () => {
const expectedContent = eol.lf(fs.readFileSync(__dirname + '/../fixtures/sample-1/input.nut', 'utf-8'));
let resultContent;

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@master`);
expect(resultContent).toEqual(expectedContent);

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@v0.1.0`);
expect(resultContent).toEqual(expectedContent);

resultContent = reader.read(`git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut@20454c4dcb9621252d248d8a833ceb1ca79c3730`);
expect(resultContent).toEqual(expectedContent);
});
});
86 changes: 86 additions & 0 deletions spec/GitLocal/dependencies.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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';

require('jasmine-expect');

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

const dependenciesFile = path.join(process.cwd(), 'save_dependencies.json');

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

beforeEach(function () {
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
fail('Some of the required environment variables are not set');
return;
}

const builder = new Builder();
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
machine = builder.machine;
});

it('Create and read dependencies JSON file', () => {
const rev1Hash = "618bb5ecb831762ed085486f39496502f7b22700";
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 rev0Hash = "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 = `git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/input.nut.out@v2.2.2`.replace(/\\/g, '/');

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

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

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

// replace the actual (rev1) commit ID to rev0 commit ID
rev1Map.set(url, rev0Hash);
fs.writeFileSync(dependenciesFile, JSON.stringify([...rev1Map], null, 2), 'utf-8');

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

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

// unlink dependencies file to avoid conflicts with unit-tests below
fs.unlinkSync(dependenciesFile);
});
});
65 changes: 65 additions & 0 deletions spec/GitLocal/remote-relative-includes.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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';

// require('jasmine-expect');

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

// File inc-a.nut contains `@include "inc-b.nut"`
const gitlocalPathA = `git-local:${process.env.SPEC_GIT_LOCAL_REPO_PATH}/spec/fixtures/sample-1/inc-a.nut`.replace(/\\/g, '/');

describe('remote-relative-includes', () => {
let machine;

beforeEach(function () {
if (!process.env.SPEC_GIT_LOCAL_REPO_PATH) {
fail('Some of the required environment variables are not set');
return;
}

const builder = new Builder();
builder.logger = new Log(process.env.SPEC_LOGLEVEL || 'error');
machine = builder.machine;
});

it('fetch local include from local git repo', () => {
const fileNotFoundMessage = `Local file "inc-b.nut" not found (${gitlocalPathA}:2)`;
try {
eol.lf(machine.execute(`@include once "${gitlocalPathA}"`));
fail();
} catch (e) {
expect(backslashToSlash(e.message)).toEqual(fileNotFoundMessage);
}

// Enable remote-relative-includes feature
machine.remoteRelativeIncludes = true;
const res = eol.lf(machine.execute(`@include once "${gitlocalPathA}"`));
expect(res).toEqual('// included file a\n// included file b\n');
});
});
36 changes: 36 additions & 0 deletions spec/GitLocalExecutor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.

const Jasmine = require('jasmine');

const jasmine = new Jasmine();
jasmine.loadConfig({
'spec_dir': 'spec',
'spec_files': [
"GitLocal/**/*[sS]pec.js"
],
"random": false,
"stopSpecOnExpectationFailure": true
});
jasmine.execute();
3 changes: 2 additions & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"spec_files": [
"**/*[sS]pec.js",
"!BitbucketServer/**/*[sS]pec.js",
"!AzureRepos/**/*[sS]pec.js"
"!AzureRepos/**/*[sS]pec.js",
"!GitLocal/**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
Expand Down
2 changes: 1 addition & 1 deletion src/FileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FileCache {
}

/**
* Transform url or github/bitbucket link to path and filename
* Transform url or github/bitbucket/azure link to path and filename
* It is important, that path and filename are unique,
* because collision can break the build
* @param {string} link link to the file
Expand Down
Loading