@@ -1483,14 +1483,9 @@ namespace Harness {
1483
1483
}
1484
1484
1485
1485
export function doErrorBaseline ( baselinePath : string , inputFiles : ReadonlyArray < TestFile > , errors : ReadonlyArray < ts . Diagnostic > , pretty ?: boolean ) {
1486
- Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? $ / , ".errors.txt" ) , ( ) : string | null => {
1487
- if ( ! errors || ( errors . length === 0 ) ) {
1488
- /* tslint:disable:no-null-keyword */
1489
- return null ;
1490
- /* tslint:enable:no-null-keyword */
1491
- }
1492
- return getErrorBaseline ( inputFiles , errors , pretty ) ;
1493
- } ) ;
1486
+ Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? $ / , ".errors.txt" ) ,
1487
+ // tslint:disable-next-line no-null-keyword
1488
+ ! errors || ( errors . length === 0 ) ? null : getErrorBaseline ( inputFiles , errors , pretty ) ) ;
1494
1489
}
1495
1490
1496
1491
export function doTypeAndSymbolBaseline ( baselinePath : string , program : ts . Program , allFiles : { unitName : string , content : string } [ ] , opts ?: Baseline . BaselineOptions , multifile ?: boolean , skipTypeBaselines ?: boolean , skipSymbolBaselines ?: boolean ) {
@@ -1552,7 +1547,7 @@ namespace Harness {
1552
1547
1553
1548
if ( ! multifile ) {
1554
1549
const fullBaseLine = generateBaseLine ( isSymbolBaseLine , isSymbolBaseLine ? skipSymbolBaselines : skipTypeBaselines ) ;
1555
- Baseline . runBaseline ( outputFileName + fullExtension , ( ) => fullBaseLine , opts ) ;
1550
+ Baseline . runBaseline ( outputFileName + fullExtension , fullBaseLine , opts ) ;
1556
1551
}
1557
1552
else {
1558
1553
Baseline . runMultifileBaseline ( outputFileName , fullExtension , ( ) => {
@@ -1637,22 +1632,21 @@ namespace Harness {
1637
1632
throw new Error ( "Number of sourcemap files should be same as js files." ) ;
1638
1633
}
1639
1634
1640
- Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? / , ".js.map" ) , ( ) => {
1641
- if ( ( options . noEmitOnError && result . diagnostics . length !== 0 ) || result . maps . size === 0 ) {
1642
- // We need to return null here or the runBaseLine will actually create a empty file.
1643
- // Baselining isn't required here because there is no output.
1644
- /* tslint:disable:no-null-keyword */
1645
- return null ;
1646
- /* tslint:enable:no-null-keyword */
1647
- }
1648
-
1649
- let sourceMapCode = "" ;
1635
+ let sourceMapCode : string | null ;
1636
+ if ( ( options . noEmitOnError && result . diagnostics . length !== 0 ) || result . maps . size === 0 ) {
1637
+ // We need to return null here or the runBaseLine will actually create a empty file.
1638
+ // Baselining isn't required here because there is no output.
1639
+ /* tslint:disable:no-null-keyword */
1640
+ sourceMapCode = null ;
1641
+ /* tslint:enable:no-null-keyword */
1642
+ }
1643
+ else {
1644
+ sourceMapCode = "" ;
1650
1645
result . maps . forEach ( sourceMap => {
1651
1646
sourceMapCode += fileOutput ( sourceMap , harnessSettings ) ;
1652
1647
} ) ;
1653
-
1654
- return sourceMapCode ;
1655
- } ) ;
1648
+ }
1649
+ Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? / , ".js.map" ) , sourceMapCode ) ;
1656
1650
}
1657
1651
}
1658
1652
@@ -1662,49 +1656,40 @@ namespace Harness {
1662
1656
}
1663
1657
1664
1658
// check js output
1665
- Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? / , ts . Extension . Js ) , ( ) => {
1666
- let tsCode = "" ;
1667
- const tsSources = otherFiles . concat ( toBeCompiled ) ;
1668
- if ( tsSources . length > 1 ) {
1669
- tsCode += "//// [" + header + "] ////\r\n\r\n" ;
1670
- }
1671
- for ( let i = 0 ; i < tsSources . length ; i ++ ) {
1672
- tsCode += "//// [" + ts . getBaseFileName ( tsSources [ i ] . unitName ) + "]\r\n" ;
1673
- tsCode += tsSources [ i ] . content + ( i < ( tsSources . length - 1 ) ? "\r\n" : "" ) ;
1674
- }
1659
+ let tsCode = "" ;
1660
+ const tsSources = otherFiles . concat ( toBeCompiled ) ;
1661
+ if ( tsSources . length > 1 ) {
1662
+ tsCode += "//// [" + header + "] ////\r\n\r\n" ;
1663
+ }
1664
+ for ( let i = 0 ; i < tsSources . length ; i ++ ) {
1665
+ tsCode += "//// [" + ts . getBaseFileName ( tsSources [ i ] . unitName ) + "]\r\n" ;
1666
+ tsCode += tsSources [ i ] . content + ( i < ( tsSources . length - 1 ) ? "\r\n" : "" ) ;
1667
+ }
1675
1668
1676
- let jsCode = "" ;
1677
- result . js . forEach ( file => {
1678
- jsCode += fileOutput ( file , harnessSettings ) ;
1679
- } ) ;
1669
+ let jsCode = "" ;
1670
+ result . js . forEach ( file => {
1671
+ jsCode += fileOutput ( file , harnessSettings ) ;
1672
+ } ) ;
1680
1673
1681
- if ( result . dts . size > 0 ) {
1682
- jsCode += "\r\n\r\n" ;
1683
- result . dts . forEach ( declFile => {
1684
- jsCode += fileOutput ( declFile , harnessSettings ) ;
1685
- } ) ;
1686
- }
1674
+ if ( result . dts . size > 0 ) {
1675
+ jsCode += "\r\n\r\n" ;
1676
+ result . dts . forEach ( declFile => {
1677
+ jsCode += fileOutput ( declFile , harnessSettings ) ;
1678
+ } ) ;
1679
+ }
1687
1680
1688
- const declFileContext = prepareDeclarationCompilationContext (
1689
- toBeCompiled , otherFiles , result , harnessSettings , options , /*currentDirectory*/ undefined
1690
- ) ;
1691
- const declFileCompilationResult = compileDeclarationFiles ( declFileContext , result . symlinks ) ;
1681
+ const declFileContext = prepareDeclarationCompilationContext (
1682
+ toBeCompiled , otherFiles , result , harnessSettings , options , /*currentDirectory*/ undefined
1683
+ ) ;
1684
+ const declFileCompilationResult = compileDeclarationFiles ( declFileContext , result . symlinks ) ;
1692
1685
1693
- if ( declFileCompilationResult && declFileCompilationResult . declResult . diagnostics . length ) {
1694
- jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n" ;
1695
- jsCode += "\r\n\r\n" ;
1696
- jsCode += getErrorBaseline ( tsConfigFiles . concat ( declFileCompilationResult . declInputFiles , declFileCompilationResult . declOtherFiles ) , declFileCompilationResult . declResult . diagnostics ) ;
1697
- }
1686
+ if ( declFileCompilationResult && declFileCompilationResult . declResult . diagnostics . length ) {
1687
+ jsCode += "\r\n\r\n//// [DtsFileErrors]\r\n" ;
1688
+ jsCode += "\r\n\r\n" ;
1689
+ jsCode += getErrorBaseline ( tsConfigFiles . concat ( declFileCompilationResult . declInputFiles , declFileCompilationResult . declOtherFiles ) , declFileCompilationResult . declResult . diagnostics ) ;
1690
+ }
1698
1691
1699
- if ( jsCode . length > 0 ) {
1700
- return tsCode + "\r\n\r\n" + jsCode ;
1701
- }
1702
- else {
1703
- /* tslint:disable:no-null-keyword */
1704
- return null ;
1705
- /* tslint:enable:no-null-keyword */
1706
- }
1707
- } ) ;
1692
+ Baseline . runBaseline ( baselinePath . replace ( / \. t s x ? / , ts . Extension . Js ) , jsCode . length > 0 ? tsCode + "\r\n\r\n" + jsCode : null ) ; // tslint:disable-line no-null-keyword
1708
1693
}
1709
1694
1710
1695
function fileOutput ( file : documents . TextDocument , harnessSettings : TestCaseParser . CompilerSettings ) : string {
@@ -2027,16 +2012,6 @@ namespace Harness {
2027
2012
}
2028
2013
2029
2014
const fileCache : { [ idx : string ] : boolean } = { } ;
2030
- function generateActual ( generateContent : ( ) => string | null ) : string | null {
2031
-
2032
- const actual = generateContent ( ) ;
2033
-
2034
- if ( actual === undefined ) {
2035
- throw new Error ( "The generated content was \"undefined\". Return \"null\" if no baselining is required.\"" ) ;
2036
- }
2037
-
2038
- return actual ;
2039
- }
2040
2015
2041
2016
function compareToBaseline ( actual : string | null , relativeFileName : string , opts : BaselineOptions | undefined ) {
2042
2017
// actual is now either undefined (the generator had an error), null (no file requested),
@@ -2100,9 +2075,11 @@ namespace Harness {
2100
2075
}
2101
2076
}
2102
2077
2103
- export function runBaseline ( relativeFileName : string , generateContent : ( ) => string | null , opts ?: BaselineOptions ) : void {
2078
+ export function runBaseline ( relativeFileName : string , actual : string | null , opts ?: BaselineOptions ) : void {
2104
2079
const actualFileName = localPath ( relativeFileName , opts && opts . Baselinefolder , opts && opts . Subfolder ) ;
2105
- const actual = generateActual ( generateContent ) ;
2080
+ if ( actual === undefined ) {
2081
+ throw new Error ( "The generated content was \"undefined\". Return \"null\" if no baselining is required.\"" ) ;
2082
+ }
2106
2083
const comparison = compareToBaseline ( actual , relativeFileName , opts ) ;
2107
2084
writeComparison ( comparison . expected , comparison . actual , relativeFileName , actualFileName ) ;
2108
2085
}
0 commit comments