Skip to content

Commit 68d6d8c

Browse files
committed
use Harness.IO instead of sys in harness
1 parent 425ad02 commit 68d6d8c

9 files changed

Lines changed: 89 additions & 80 deletions

File tree

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
"clean": "jake clean"
4646
},
4747
"browser": {
48-
"buffer": false,
49-
"fs": false,
50-
"os": false,
51-
"path": false
52-
}
48+
"fs": false
49+
}
5350
}

src/harness/fourslash.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ module FourSlash {
373373
this.formatCodeOptions = {
374374
IndentSize: 4,
375375
TabSize: 4,
376-
NewLineCharacter: ts.sys.newLine,
376+
NewLineCharacter: Harness.IO.newLine(),
377377
ConvertTabsToSpaces: true,
378378
InsertSpaceAfterCommaDelimiter: true,
379379
InsertSpaceAfterSemicolonInForStatements: true,
@@ -551,7 +551,7 @@ module FourSlash {
551551
errors.forEach(function (error: ts.Diagnostic) {
552552
Harness.IO.log(" minChar: " + error.start +
553553
", limChar: " + (error.start + error.length) +
554-
", message: " + ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine) + "\n");
554+
", message: " + ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine()) + "\n");
555555
});
556556
}
557557

@@ -1262,21 +1262,21 @@ module FourSlash {
12621262
emitFiles.forEach(emitFile => {
12631263
let emitOutput = this.languageService.getEmitOutput(emitFile.fileName);
12641264
// Print emitOutputStatus in readable format
1265-
resultString += "EmitSkipped: " + emitOutput.emitSkipped + ts.sys.newLine;
1265+
resultString += "EmitSkipped: " + emitOutput.emitSkipped + Harness.IO.newLine();
12661266

12671267
if (emitOutput.emitSkipped) {
1268-
resultString += "Diagnostics:" + ts.sys.newLine;
1268+
resultString += "Diagnostics:" + Harness.IO.newLine();
12691269
let diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram());
12701270
for (let i = 0, n = diagnostics.length; i < n; i++) {
1271-
resultString += " " + diagnostics[0].messageText + ts.sys.newLine;
1271+
resultString += " " + diagnostics[0].messageText + Harness.IO.newLine();
12721272
}
12731273
}
12741274

12751275
emitOutput.outputFiles.forEach((outputFile, idx, array) => {
1276-
let fileName = "FileName : " + outputFile.name + ts.sys.newLine;
1276+
let fileName = "FileName : " + outputFile.name + Harness.IO.newLine();
12771277
resultString = resultString + fileName + outputFile.text;
12781278
});
1279-
resultString += ts.sys.newLine;
1279+
resultString += Harness.IO.newLine();
12801280
});
12811281

12821282
return resultString;
@@ -1313,7 +1313,7 @@ module FourSlash {
13131313
Harness.IO.log(
13141314
"start: " + err.start +
13151315
", length: " + err.length +
1316-
", message: " + ts.flattenDiagnosticMessageText(err.messageText, ts.sys.newLine));
1316+
", message: " + ts.flattenDiagnosticMessageText(err.messageText, Harness.IO.newLine()));
13171317
});
13181318
}
13191319
}
@@ -1887,9 +1887,9 @@ module FourSlash {
18871887
}
18881888

18891889
function jsonMismatchString() {
1890-
return ts.sys.newLine +
1891-
"expected: '" + ts.sys.newLine + JSON.stringify(expected, (k, v) => v, 2) + "'" + ts.sys.newLine +
1892-
"actual: '" + ts.sys.newLine + JSON.stringify(actual, (k, v) => v, 2) + "'";
1890+
return Harness.IO.newLine() +
1891+
"expected: '" + Harness.IO.newLine() + JSON.stringify(expected, (k, v) => v, 2) + "'" + Harness.IO.newLine() +
1892+
"actual: '" + Harness.IO.newLine() + JSON.stringify(actual, (k, v) => v, 2) + "'";
18931893
}
18941894
}
18951895

@@ -2398,7 +2398,7 @@ module FourSlash {
23982398
let host = Harness.Compiler.createCompilerHost([{ unitName: Harness.Compiler.fourslashFileName, content: undefined }],
23992399
(fn, contents) => fourslashJsOutput = contents,
24002400
ts.ScriptTarget.Latest,
2401-
ts.sys.useCaseSensitiveFileNames);
2401+
Harness.IO.useCaseSensitiveFileNames());
24022402

24032403
let program = ts.createProgram([Harness.Compiler.fourslashFileName], { noResolve: true, target: ts.ScriptTarget.ES3 }, host);
24042404

@@ -2420,7 +2420,7 @@ module FourSlash {
24202420
],
24212421
(fn, contents) => result = contents,
24222422
ts.ScriptTarget.Latest,
2423-
ts.sys.useCaseSensitiveFileNames);
2423+
Harness.IO.useCaseSensitiveFileNames());
24242424

24252425
let program = ts.createProgram([Harness.Compiler.fourslashFileName, fileName], { out: "fourslashTestOutput.js", noResolve: true, target: ts.ScriptTarget.ES3 }, host);
24262426

@@ -2429,7 +2429,7 @@ module FourSlash {
24292429
let diagnostics = ts.getPreEmitDiagnostics(program, sourceFile);
24302430
if (diagnostics.length > 0) {
24312431
throw new Error(`Error compiling ${fileName}: ` +
2432-
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, ts.sys.newLine)).join("\r\n"));
2432+
diagnostics.map(e => ts.flattenDiagnosticMessageText(e.messageText, Harness.IO.newLine())).join("\r\n"));
24332433
}
24342434

24352435
program.emit(sourceFile);

src/harness/harness.ts

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module Utils {
102102

103103
let content: string = undefined;
104104
try {
105-
content = ts.sys.readFile(Harness.userSpecifiedRoot + path);
105+
content = Harness.IO.readFile(Harness.userSpecifiedRoot + path);
106106
}
107107
catch (err) {
108108
return undefined;
@@ -190,7 +190,7 @@ module Utils {
190190
return {
191191
start: diagnostic.start,
192192
length: diagnostic.length,
193-
messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine),
193+
messageText: ts.flattenDiagnosticMessageText(diagnostic.messageText, Harness.IO.newLine()),
194194
category: (<any>ts).DiagnosticCategory[diagnostic.category],
195195
code: diagnostic.code
196196
};
@@ -323,8 +323,8 @@ module Utils {
323323
assert.equal(d1.start, d2.start, "d1.start !== d2.start");
324324
assert.equal(d1.length, d2.length, "d1.length !== d2.length");
325325
assert.equal(
326-
ts.flattenDiagnosticMessageText(d1.messageText, ts.sys.newLine),
327-
ts.flattenDiagnosticMessageText(d2.messageText, ts.sys.newLine), "d1.messageText !== d2.messageText");
326+
ts.flattenDiagnosticMessageText(d1.messageText, Harness.IO.newLine()),
327+
ts.flattenDiagnosticMessageText(d2.messageText, Harness.IO.newLine()), "d1.messageText !== d2.messageText");
328328
assert.equal(d1.category, d2.category, "d1.category !== d2.category");
329329
assert.equal(d1.code, d2.code, "d1.code !== d2.code");
330330
}
@@ -404,6 +404,10 @@ module Harness.Path {
404404

405405
module Harness {
406406
export interface IO {
407+
newLine(): string;
408+
getCurrentDirectory(): string;
409+
useCaseSensitiveFileNames(): boolean;
410+
resolvePath(path: string): string;
407411
readFile(path: string): string;
408412
writeFile(path: string, contents: string): void;
409413
directoryName(path: string): string;
@@ -433,12 +437,17 @@ module Harness {
433437
fso = {};
434438
}
435439

436-
export let readFile: typeof IO.readFile = ts.sys.readFile;
437-
export let writeFile: typeof IO.writeFile = ts.sys.writeFile;
438-
export let directoryName: typeof IO.directoryName = fso.GetParentFolderName;
439-
export let directoryExists: typeof IO.directoryExists = fso.FolderExists;
440-
export let fileExists: typeof IO.fileExists = fso.FileExists;
441-
export let log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
440+
export const resolvePath = (path: string) => ts.sys.resolvePath(path);
441+
export const getCurrentDirectory = () => ts.sys.getCurrentDirectory();
442+
export const newLine = () => ts.sys.newLine;
443+
export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames;
444+
445+
export const readFile: typeof IO.readFile = path => ts.sys.readFile(path);
446+
export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content);
447+
export const directoryName: typeof IO.directoryName = fso.GetParentFolderName;
448+
export const directoryExists: typeof IO.directoryExists = fso.FolderExists;
449+
export const fileExists: typeof IO.fileExists = fso.FileExists;
450+
export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine;
442451

443452
export function createDirectory(path: string) {
444453
if (directoryExists(path)) {
@@ -493,11 +502,16 @@ module Harness {
493502
} else {
494503
fs = pathModule = {};
495504
}
505+
506+
export const resolvePath = (path: string) => ts.sys.resolvePath(path);
507+
export const getCurrentDirectory = () => ts.sys.getCurrentDirectory();
508+
export const newLine = () => ts.sys.newLine;
509+
export const useCaseSensitiveFileNames = () => ts.sys.useCaseSensitiveFileNames;
496510

497-
export let readFile: typeof IO.readFile = ts.sys.readFile;
498-
export let writeFile: typeof IO.writeFile = ts.sys.writeFile;
499-
export let fileExists: typeof IO.fileExists = fs.existsSync;
500-
export let log: typeof IO.log = s => console.log(s);
511+
export const readFile: typeof IO.readFile = path => ts.sys.readFile(path);
512+
export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content);
513+
export const fileExists: typeof IO.fileExists = fs.existsSync;
514+
export const log: typeof IO.log = s => console.log(s);
501515

502516
export function createDirectory(path: string) {
503517
if (!directoryExists(path)) {
@@ -562,9 +576,9 @@ module Harness {
562576
export module Network {
563577
let serverRoot = "http://localhost:8888/";
564578

565-
// Unused?
566-
let newLine = "\r\n";
567-
let currentDirectory = () => "";
579+
export const newLine = () => "\r\n";
580+
export const useCaseSensitiveFileNames = () => false;
581+
export const getCurrentDirectory = () => "";
568582
let supportsCodePage = () => false;
569583

570584
module Http {
@@ -616,6 +630,7 @@ module Harness {
616630
xhr.send(contents);
617631
}
618632
catch (e) {
633+
log(`XHR Error: ${e}`);
619634
return { status: 500, responseText: null };
620635
}
621636

@@ -655,6 +670,7 @@ module Harness {
655670
return dirPath;
656671
}
657672
export let directoryName: typeof IO.directoryName = Utils.memoize(directoryNameImpl);
673+
export const resolvePath = (path: string) => directoryName(path);
658674

659675
export function fileExists(path: string): boolean {
660676
let response = Http.getFileFromServerSync(serverRoot + path);
@@ -840,7 +856,7 @@ module Harness {
840856
export let fourslashSourceFile: ts.SourceFile;
841857

842858
export function getCanonicalFileName(fileName: string): string {
843-
return ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
859+
return Harness.IO.useCaseSensitiveFileNames() ? fileName : fileName.toLowerCase();
844860
}
845861

846862
export function createCompilerHost(
@@ -858,7 +874,7 @@ module Harness {
858874
}
859875

860876
let filemap: { [fileName: string]: ts.SourceFile; } = {};
861-
let getCurrentDirectory = currentDirectory === undefined ? ts.sys.getCurrentDirectory : () => currentDirectory;
877+
let getCurrentDirectory = currentDirectory === undefined ? Harness.IO.getCurrentDirectory : () => currentDirectory;
862878

863879
// Register input files
864880
function register(file: { unitName: string; content: string; }) {
@@ -895,7 +911,7 @@ module Harness {
895911
let newLine =
896912
newLineKind === ts.NewLineKind.CarriageReturnLineFeed ? carriageReturnLineFeed :
897913
newLineKind === ts.NewLineKind.LineFeed ? lineFeed :
898-
ts.sys.newLine;
914+
Harness.IO.newLine();
899915

900916
return {
901917
getCurrentDirectory,
@@ -988,7 +1004,7 @@ module Harness {
9881004
// Treat them as library files, so include them in build, but not in baselines.
9891005
let includeBuiltFiles: { unitName: string; content: string }[] = [];
9901006

991-
let useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
1007+
let useCaseSensitiveFileNames = Harness.IO.useCaseSensitiveFileNames();
9921008
this.settings.forEach(setCompilerOptionForSetting);
9931009

9941010
let fileOutputs: GeneratedFile[] = [];
@@ -1006,11 +1022,9 @@ module Harness {
10061022
let errors = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
10071023
this.lastErrors = errors;
10081024

1009-
let result = new CompilerResult(fileOutputs, errors, program, ts.sys.getCurrentDirectory(), emitResult.sourceMaps);
1025+
let result = new CompilerResult(fileOutputs, errors, program, Harness.IO.getCurrentDirectory(), emitResult.sourceMaps);
10101026
onComplete(result, program);
10111027

1012-
// reset what newline means in case the last test changed it
1013-
ts.sys.newLine = newLine;
10141028
return options;
10151029

10161030
function setCompilerOptionForSetting(setting: Harness.TestCaseParser.CompilerSetting) {
@@ -1273,7 +1287,7 @@ module Harness {
12731287
errorOutput += diagnostic.file.fileName + "(" + (lineAndCharacter.line + 1) + "," + (lineAndCharacter.character + 1) + "): ";
12741288
}
12751289

1276-
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
1290+
errorOutput += ts.DiagnosticCategory[diagnostic.category].toLowerCase() + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, Harness.IO.newLine()) + Harness.IO.newLine();
12771291
});
12781292

12791293
return errorOutput;
@@ -1286,7 +1300,7 @@ module Harness {
12861300
let totalErrorsReported = 0;
12871301

12881302
function outputErrorText(error: ts.Diagnostic) {
1289-
let message = ts.flattenDiagnosticMessageText(error.messageText, ts.sys.newLine);
1303+
let message = ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine());
12901304

12911305
let errLines = RunnerBase.removeFullPaths(message)
12921306
.split("\n")
@@ -1383,7 +1397,7 @@ module Harness {
13831397
assert.equal(totalErrorsReported + numLibraryDiagnostics + numTest262HarnessDiagnostics, diagnostics.length, "total number of errors");
13841398

13851399
return minimalDiagnosticsToString(diagnostics) +
1386-
ts.sys.newLine + ts.sys.newLine + outputLines.join("\r\n");
1400+
Harness.IO.newLine() + Harness.IO.newLine() + outputLines.join("\r\n");
13871401
}
13881402

13891403
export function collateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): string {

0 commit comments

Comments
 (0)