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
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ script:
- echo no | android create avd --force -n $EMULATOR_NAME-$EMULATOR_API_LEVEL -t android-$EMULATOR_API_LEVEL --abi $ANDROID_ABI -c 12M
- emulator -avd $EMULATOR_NAME-$EMULATOR_API_LEVEL -no-skin -no-audio -no-window &
- android-wait-for-emulator
- cd android-static-binding-generator
- "npm install"
- "node run-tests"
- cd ..
- "android-static-binding-generator/project/staticbindinggenerator/gradlew clean test --project-dir android-static-binding-generator/project/staticbindinggenerator/"
- "cd test-app && ./gradlew runtest --stacktrace"
- adb -e logcat -d 300
- cd ..
8 changes: 5 additions & 3 deletions android-static-binding-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "static_analysis",
"version": "1.0.0",
"description": "",
"main": "project/parse.js",
"main": "project/parser",
"scripts": {
"test": "jasmine JASMINE_CONFIG_PATH=jasmine.json"
"test": "node run-tests.js"
},
"repository": "https://github.com/NativeScript/android-runtime/",
"author": "",
"license": "ISC",
"dependencies": {
Expand All @@ -15,6 +16,7 @@
"lazy": "^1.0.11"
},
"devDependencies": {
"jasmine-node": "^1.14.5"
"jasmine": "2.8.0",
"jasmine-node": "1.14.5"
}
}
36 changes: 36 additions & 0 deletions android-static-binding-generator/run-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(function () {
let { spawnSync, execSync } = require('child_process');

console.log("Installing JavaScript parser test dependencies.");

let npmInstallResult = execSync('npm install');

console.log(npmInstallResult.toString());

console.log("Executing JavaScript parser tests using Jasmine.");

const subprocess = spawnSync('node', ['./node_modules/jasmine/bin/jasmine.js', 'JASMINE_CONFIG_PATH=jasmine.json'], { cwd: __dirname });

let stdout = subprocess.stdout.toString();
let stderr = subprocess.stderr.toString();
let code = subprocess.status;
let err = subprocess.error;

if (code !== 0) {
console.log("Tests runner exited with a non-zero code.");

let errorString = stdout;

if (err) {
errorString = err;
}

if (stderr) {
errorString = stderr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't override error string, but rather throw an object with both the supbrpocess.error and subprocess.stderr so we don't loose information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that both are set at the same time though? My understanding is that subprocess.error is raised when something goes wrong while spawning the process, whereas stderr is a result of an error thrown inside the process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not sure if both can be present. It's just a suggestion when I look at the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an object results in [object Object] in the logs, which is not very helpful.

}

throw new Error(errorString);
}

console.log(stdout);
}());
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';

var exec = require("child_process").exec,
const exec = require("child_process").exec,
path = require("path"),
fs = require("fs"),
prefix = path.resolve(__dirname, "../cases/"),
interfaceNames = path.resolve(__dirname, "../interfaces-names.txt"),
gradleTraverse = path.resolve(__dirname, "../../project"),
gradleTaskName = "traverseJsFilesArgs",
parser = path.resolve(__dirname, "../../project/parser/js_parser.js");
parser = path.resolve(__dirname, "../../project/parser/js_parser.js"),
gradleExecutable = path.resolve(__dirname, "../../project/staticbindinggenerator/gradlew");

function execGradle(inputPath, bindingsOutput, jsFilesInput, callback) {
exec("gradle -p " + gradleTraverse + " " + gradleTaskName + " -Ptest -PjsCodeDir=\"" + inputPath + "\" -PbindingsFilePath=\"" + bindingsOutput + "\" -PinterfaceNamesFilePath=\"" + interfaceNames + "\" -PjsParserPath=\"" + parser + "\" -PjsFilesParameter=\"" + jsFilesInput + "\"", callback);
exec(`${gradleExecutable} -p ${gradleTraverse} ${gradleTaskName} -Ptest -PjsCodeDir="${inputPath}" -PbindingsFilePath="${bindingsOutput}" -PinterfaceNamesFilePath="${interfaceNames}" -PjsParserPath="${parser}" -PjsFilesParameter="${jsFilesInput}"`, callback);
}

function logExecResult(stdout, stderr) {
Expand All @@ -35,9 +34,11 @@ function clearOutput(bindingsOutput, jsFilesInput) {
}

describe("parser/js_parser tests", function () {
beforeAll(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20 * 1000; // give enough time to start the gradle daemon
});

describe("js_parser tests", function () {

describe("Traversal tests", function () {
it("Analyse files only in the correct folder structure", function (done) {

let input = path.normalize(prefix + "/mini_app/app"),
Expand Down Expand Up @@ -213,7 +214,6 @@ describe("parser/js_parser tests", function () {
console.error(`exec error: ${error}`);
return;
}

logExecResult(stdout, stderr)

let bindingsContent = fs.readFileSync(output, "utf-8").toString().trim().split('\n');
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,16 @@ task generateStaticBindingGeneratorJar(type: Exec) {
doFirst {
workingDir "$rootDir/android-static-binding-generator/project/staticbindinggenerator"


def commandArgs = ["assemble"]

if (isWinOs) {
commandLine "cmd", "/c", "gradlew", "assemble"
commandLine "cmd", "/c", "gradlew"
} else {
commandLine "./gradlew", "assemble"
commandLine "./gradlew"
}

args commandArgs
}

}
Expand Down