@@ -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
405405module 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