Skip to content

Commit 37b0b8c

Browse files
committed
Added some more cli tests
Added tests for some untested lines in cliparser
1 parent fde8214 commit 37b0b8c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/CommandLineParser.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,17 @@ function addTSTLOptions(commandLine: ts.ParsedCommandLine,
118118
/** Check the current state of the ParsedCommandLine for errors */
119119
function runDiagnostics(commandLine: ts.ParsedCommandLine) {
120120
const tsInvalidCompilerOptionErrorCode = 5023;
121-
122121
if (commandLine.errors.length !== 0) {
123122
// Generate a list of valid option names and aliases
124123
const optionNames: string[] = [];
125-
for (const key in optionDeclarations) {
126-
if (optionDeclarations[key]) {
127-
optionNames.push(key);
128-
const alias = optionDeclarations[key].alias;
129-
if (alias) {
130-
if (typeof alias === "string") {
131-
optionNames.push(alias);
132-
} else {
133-
optionNames.push(...alias);
134-
}
124+
for (const key of Object.keys(optionDeclarations)) {
125+
optionNames.push(key);
126+
const alias = optionDeclarations[key].alias;
127+
if (alias) {
128+
if (typeof alias === "string") {
129+
optionNames.push(alias);
130+
} else {
131+
optionNames.push(...alias);
135132
}
136133
}
137134
}

test/unit/cli.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Expect, Test, TestCase, Teardown } from "alsatian";
22

33
import { CompilerOptions, findConfigFile, parseCommandLine, ParsedCommandLine } from "../../src/CommandLineParser";
44

5-
65
export class CLITests {
76

87
@Test("defaultOption")
@@ -17,6 +16,12 @@ export class CLITests {
1716
Expect(expected).toBe(parsedCommandLine.options[option]);
1817
}
1918

19+
@Test("ValidLuaTarget")
20+
public validLuaTarget() {
21+
let parsedCommandLine = parseCommandLine(['--luaTarget', '5.3']);
22+
Expect(parsedCommandLine.options["luaTarget"]).toBe("5.3");
23+
}
24+
2025
@Test("InvalidLuaTarget")
2126
public invalidLuaTarget() {
2227
// Don't check error message because the yargs library messes the message up.

0 commit comments

Comments
 (0)