Skip to content

Commit 6c6de2a

Browse files
author
Andy
authored
Merge pull request #9990 from Microsoft/lint_tests
Lint tests helper files
2 parents 030fbdc + a485aab commit 6c6de2a

File tree

6 files changed

+150
-142
lines changed

6 files changed

+150
-142
lines changed

Gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ const lintTargets = [
956956
"src/server/**/*.ts",
957957
"scripts/tslint/**/*.ts",
958958
"src/services/**/*.ts",
959+
"tests/*.ts", "tests/webhost/*.ts" // Note: does *not* descend recursively
959960
];
960961

961962

Jakefile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ var lintTargets = compilerSources
10411041
.concat(serverCoreSources)
10421042
.concat(tslintRulesFiles)
10431043
.concat(servicesSources)
1044-
.concat(["Gulpfile.ts"]);
1044+
.concat(["Gulpfile.ts"])
1045+
.concat([nodeServerInFile, perftscPath, "tests/perfsys.ts", webhostPath]);
10451046

10461047

10471048
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");

tests/perfsys.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/// <reference path="..\src\compiler\sys.ts"/>
22
/// <reference path="..\src\compiler\types.ts"/>
33

4-
module perftest {
5-
4+
namespace perftest {
65
interface IOLog {
76
resolvePath: ts.Map<string>;
87
fileNames: string[];
@@ -12,20 +11,20 @@ module perftest {
1211
getOut(): string;
1312
}
1413

15-
export var readFile = ts.sys.readFile;
16-
var writeFile = ts.sys.writeFile;
17-
export var write = ts.sys.write;
18-
var resolvePath = ts.sys.resolvePath;
19-
export var getExecutingFilePath = ts.sys.getExecutingFilePath;
20-
export var getCurrentDirectory = ts.sys.getCurrentDirectory;
21-
var exit = ts.sys.exit;
14+
export const readFile = ts.sys.readFile;
15+
const writeFile = ts.sys.writeFile;
16+
export const write = ts.sys.write;
17+
const resolvePath = ts.sys.resolvePath;
18+
export const getExecutingFilePath = ts.sys.getExecutingFilePath;
19+
export const getCurrentDirectory = ts.sys.getCurrentDirectory;
20+
// const exit = ts.sys.exit;
2221

23-
var args = ts.sys.args;
22+
const args = ts.sys.args;
2423

2524
// augment sys so first ts.executeCommandLine call will be finish silently
2625
ts.sys.write = (s: string) => { };
2726
ts.sys.exit = (code: number) => { };
28-
ts.sys.args = []
27+
ts.sys.args = [];
2928

3029
export function restoreSys() {
3130
ts.sys.args = args;
@@ -44,19 +43,19 @@ module perftest {
4443
return args.slice(1);
4544
}
4645

47-
var resolvePathLog: ts.Map<string> = {};
48-
46+
const resolvePathLog: ts.Map<string> = {};
47+
4948
export function interceptIO() {
5049
ts.sys.resolvePath = (s) => {
51-
var result = resolvePath(s);
50+
const result = resolvePath(s);
5251
resolvePathLog[s] = result;
5352
return result;
5453
};
5554
}
5655

5756
export function writeIOLog(fileNames: string[]) {
58-
var path = args[1];
59-
var log: IOLog = {
57+
const path = args[1];
58+
const log: IOLog = {
6059
fileNames: fileNames,
6160
resolvePath: resolvePathLog
6261
};
@@ -65,36 +64,36 @@ module perftest {
6564
}
6665

6766
export function prepare(): IO {
68-
var log = <IOLog>JSON.parse(readFile(args[0]));
67+
const log = <IOLog>JSON.parse(readFile(args[0]));
68+
69+
const files: ts.Map<string> = {};
70+
log.fileNames.forEach(f => { files[f] = readFile(f); });
6971

70-
var files: ts.Map<string> = {};
71-
log.fileNames.forEach(f => { files[f] = readFile(f); })
72-
7372
ts.sys.createDirectory = (s: string) => { };
7473
ts.sys.directoryExists = (s: string) => true;
7574
ts.sys.fileExists = (s: string) => true;
7675

77-
var currentDirectory = ts.sys.getCurrentDirectory();
76+
const currentDirectory = ts.sys.getCurrentDirectory();
7877
ts.sys.getCurrentDirectory = () => currentDirectory;
7978

80-
var executingFilePath = ts.sys.getExecutingFilePath();
79+
const executingFilePath = ts.sys.getExecutingFilePath();
8180
ts.sys.getExecutingFilePath = () => executingFilePath;
8281

8382
ts.sys.readFile = (s: string) => {
8483
return files[s];
85-
}
84+
};
8685

8786
ts.sys.resolvePath = (s: string) => {
88-
var path = log.resolvePath[s];
87+
const path = log.resolvePath[s];
8988
if (!path) {
9089
throw new Error("Unexpected path '" + s + "'");
9190
}
92-
return path
93-
}
91+
return path;
92+
};
9493

9594
ts.sys.writeFile = (path: string, data: string) => { };
9695

97-
var out: string = "";
96+
let out = "";
9897

9998
ts.sys.write = (s: string) => { out += s; };
10099

tests/perftsc.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
if (perftest.hasLogIOFlag()) {
66
perftest.interceptIO();
77

8-
var compilerHost: ts.CompilerHost = {
8+
const compilerHost: ts.CompilerHost = {
99
getSourceFile: (s, v) => {
10-
var content = perftest.readFile(s);
10+
const content = perftest.readFile(s);
1111
return content !== undefined ? ts.createSourceFile(s, content, v) : undefined;
1212
},
1313
getDefaultLibFileName: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"),
@@ -18,13 +18,13 @@ if (perftest.hasLogIOFlag()) {
1818
getNewLine: () => ts.sys.newLine
1919
};
2020

21-
var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag());
22-
var program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost);
23-
var fileNames = program.getSourceFiles().map(f => f.fileName);
21+
const commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag());
22+
const program = ts.createProgram(commandLine.fileNames, commandLine.options, compilerHost);
23+
const fileNames = program.getSourceFiles().map(f => f.fileName);
2424
perftest.writeIOLog(fileNames);
2525
}
2626
else {
27-
var io = perftest.prepare();
27+
const io = perftest.prepare();
2828
ts.executeCommandLine(perftest.getArgsWithoutIOLogFile());
2929
perftest.write(io.getOut());
3030
}

0 commit comments

Comments
 (0)