mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-08 01:48:32 +00:00
Added unit test for getExecPath
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
"@theia/search-in-workspace": "next",
|
||||
"@theia/terminal": "next",
|
||||
"@theia/workspace": "next",
|
||||
"@types/google-protobuf": "^3.7.1",
|
||||
"@types/dateformat": "^3.0.1",
|
||||
"@types/google-protobuf": "^3.7.1",
|
||||
"@types/ps-tree": "^1.1.0",
|
||||
"@types/react-select": "^3.0.0",
|
||||
"@types/which": "^1.3.1",
|
||||
@@ -47,19 +47,37 @@
|
||||
"generate-protocol": "node ./scripts/generate-protocol.js",
|
||||
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
|
||||
"build": "tsc && ncp ./src/node/cli-protocol/ ./lib/node/cli-protocol/ && yarn lint",
|
||||
"watch": "tsc -w"
|
||||
"watch": "tsc -w",
|
||||
"test": "mocha \"./test/**/*.test.ts\""
|
||||
},
|
||||
"mocha": {
|
||||
"require": [
|
||||
"ts-node/register",
|
||||
"reflect-metadata/Reflect"
|
||||
],
|
||||
"reporter": "spec",
|
||||
"colors": true,
|
||||
"watch-extensions": "ts,tsx",
|
||||
"timeout": 10000
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.7",
|
||||
"@types/chai-string": "^1.4.2",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"chai": "^4.2.0",
|
||||
"chai-string": "^1.5.0",
|
||||
"decompress": "^4.2.0",
|
||||
"decompress-targz": "^4.1.1",
|
||||
"decompress-unzip": "^4.0.1",
|
||||
"download": "^7.1.0",
|
||||
"grpc-tools": "^1.8.0",
|
||||
"grpc_tools_node_protoc_ts": "^2.5.8",
|
||||
"mocha": "^7.0.0",
|
||||
"moment": "^2.24.0",
|
||||
"ncp": "^2.0.0",
|
||||
"rimraf": "^2.6.1",
|
||||
"shelljs": "^0.8.3",
|
||||
"ts-node": "^8.6.2",
|
||||
"tslint": "^5.5.0",
|
||||
"typescript": "3.5.3",
|
||||
"uuid": "^3.2.1",
|
||||
|
||||
32
arduino-ide-extension/test/node/exec-util.test.ts
Normal file
32
arduino-ide-extension/test/node/exec-util.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as os from 'os';
|
||||
import { expect, use } from 'chai';
|
||||
import { NullLogger } from './logger';
|
||||
import { getExecPath } from '../../lib/node/exec-util'
|
||||
|
||||
use(require('chai-string'));
|
||||
|
||||
describe('getExecPath', () => {
|
||||
it('should resolve arduino-cli', async () => {
|
||||
const path = await getExecPath('arduino-cli', new NullLogger(), 'version');
|
||||
if (os.platform() === 'win32')
|
||||
expect(path).to.endsWith('\\arduino-cli.exe');
|
||||
else
|
||||
expect(path).to.endsWith('/arduino-cli');
|
||||
});
|
||||
|
||||
it('should resolve arduino-language-server', async () => {
|
||||
const path = await getExecPath('arduino-language-server', new NullLogger());
|
||||
if (os.platform() === 'win32')
|
||||
expect(path).to.endsWith('\\arduino-language-server.exe');
|
||||
else
|
||||
expect(path).to.endsWith('/arduino-language-server');
|
||||
});
|
||||
|
||||
it('should resolve clangd', async () => {
|
||||
const path = await getExecPath('clangd', new NullLogger(), '--version', os.platform() !== 'win32');
|
||||
if (os.platform() === 'win32')
|
||||
expect(path).to.endsWith('\\clangd.exe');
|
||||
else
|
||||
expect(path).to.endsWith('/clangd');
|
||||
});
|
||||
});
|
||||
89
arduino-ide-extension/test/node/logger.ts
Normal file
89
arduino-ide-extension/test/node/logger.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { ILogger, Loggable, LogLevel } from '@theia/core';
|
||||
|
||||
export class NullLogger implements ILogger {
|
||||
logLevel = 0;
|
||||
|
||||
setLogLevel(logLevel: number): Promise<void> {
|
||||
this.logLevel = logLevel;
|
||||
return Promise.resolve();
|
||||
}
|
||||
getLogLevel(): Promise<number> {
|
||||
return Promise.resolve(this.logLevel);
|
||||
}
|
||||
isEnabled(logLevel: number): Promise<boolean> {
|
||||
return Promise.resolve(logLevel >= this.logLevel);
|
||||
}
|
||||
ifEnabled(logLevel: number): Promise<void> {
|
||||
if (logLevel >= this.logLevel)
|
||||
return Promise.resolve();
|
||||
else
|
||||
return Promise.reject();
|
||||
}
|
||||
log(logLevel: any, loggable: any, ...rest: any[]) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
isTrace(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.TRACE);
|
||||
}
|
||||
ifTrace(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.TRACE);
|
||||
}
|
||||
trace(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.TRACE, arg, ...params);
|
||||
}
|
||||
|
||||
isDebug(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.DEBUG);
|
||||
}
|
||||
ifDebug(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.DEBUG);
|
||||
}
|
||||
debug(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.DEBUG, arg, ...params);
|
||||
}
|
||||
|
||||
isInfo(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.INFO);
|
||||
}
|
||||
ifInfo(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.INFO);
|
||||
}
|
||||
info(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.INFO, arg, ...params);
|
||||
}
|
||||
|
||||
isWarn(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.WARN);
|
||||
}
|
||||
ifWarn(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.WARN);
|
||||
}
|
||||
warn(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.WARN, arg, ...params);
|
||||
}
|
||||
|
||||
isError(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.ERROR);
|
||||
}
|
||||
ifError(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.ERROR);
|
||||
}
|
||||
error(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.ERROR, arg, ...params);
|
||||
}
|
||||
|
||||
isFatal(): Promise<boolean> {
|
||||
return this.isEnabled(LogLevel.FATAL);
|
||||
}
|
||||
ifFatal(): Promise<void> {
|
||||
return this.ifEnabled(LogLevel.FATAL);
|
||||
}
|
||||
fatal(arg: any | Loggable, ...params: any[]): Promise<void> {
|
||||
return this.log(LogLevel.FATAL, arg, ...params);
|
||||
}
|
||||
|
||||
child(name: string): ILogger {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user