Skip to content

Commit 6d969f7

Browse files
authored
Merge pull request #34525 from microsoft/testChanges
Converted more tsc and tsbuild tests to baseline
2 parents 4055689 + 575339c commit 6d969f7

File tree

202 files changed

+5881
-1762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+5881
-1762
lines changed

src/compiler/commandLineParser.ts

Lines changed: 16 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ namespace ts {
12271227
}
12281228

12291229
/*@internal*/
1230-
export function parseBuildCommand(args: string[]): ParsedBuildCommand {
1230+
export function parseBuildCommand(args: readonly string[]): ParsedBuildCommand {
12311231
let buildOptionNameMap: OptionNameMap | undefined;
12321232
const returnBuildOptionNameMap = () => (buildOptionNameMap || (buildOptionNameMap = createOptionNameMap(buildOpts)));
12331233
const { options, fileNames: projects, errors } = parseCommandLineWorker(returnBuildOptionNameMap, [
@@ -1258,125 +1258,12 @@ namespace ts {
12581258
return { buildOptions, projects, errors };
12591259
}
12601260

1261-
function getDiagnosticText(_message: DiagnosticMessage, ..._args: any[]): string {
1261+
/* @internal */
1262+
export function getDiagnosticText(_message: DiagnosticMessage, ..._args: any[]): string {
12621263
const diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
12631264
return <string>diagnostic.messageText;
12641265
}
12651266

1266-
/* @internal */
1267-
export function printVersion() {
1268-
sys.write(getDiagnosticText(Diagnostics.Version_0, version) + sys.newLine);
1269-
}
1270-
1271-
/* @internal */
1272-
export function printHelp(optionsList: readonly CommandLineOption[], syntaxPrefix = "") {
1273-
const output: string[] = [];
1274-
1275-
// We want to align our "syntax" and "examples" commands to a certain margin.
1276-
const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
1277-
const examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
1278-
let marginLength = Math.max(syntaxLength, examplesLength);
1279-
1280-
// Build up the syntactic skeleton.
1281-
let syntax = makePadding(marginLength - syntaxLength);
1282-
syntax += `tsc ${syntaxPrefix}[${getDiagnosticText(Diagnostics.options)}] [${getDiagnosticText(Diagnostics.file)}...]`;
1283-
1284-
output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax));
1285-
output.push(sys.newLine + sys.newLine);
1286-
1287-
// Build up the list of examples.
1288-
const padding = makePadding(marginLength);
1289-
output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine);
1290-
output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine);
1291-
output.push(padding + "tsc @args.txt" + sys.newLine);
1292-
output.push(padding + "tsc --build tsconfig.json" + sys.newLine);
1293-
output.push(sys.newLine);
1294-
1295-
output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine);
1296-
1297-
// We want our descriptions to align at the same column in our output,
1298-
// so we keep track of the longest option usage string.
1299-
marginLength = 0;
1300-
const usageColumn: string[] = []; // Things like "-d, --declaration" go in here.
1301-
const descriptionColumn: string[] = [];
1302-
1303-
const optionsDescriptionMap = createMap<string[]>(); // Map between option.description and list of option.type if it is a kind
1304-
1305-
for (const option of optionsList) {
1306-
// If an option lacks a description,
1307-
// it is not officially supported.
1308-
if (!option.description) {
1309-
continue;
1310-
}
1311-
1312-
let usageText = " ";
1313-
if (option.shortName) {
1314-
usageText += "-" + option.shortName;
1315-
usageText += getParamType(option);
1316-
usageText += ", ";
1317-
}
1318-
1319-
usageText += "--" + option.name;
1320-
usageText += getParamType(option);
1321-
1322-
usageColumn.push(usageText);
1323-
let description: string;
1324-
1325-
if (option.name === "lib") {
1326-
description = getDiagnosticText(option.description);
1327-
const element = (<CommandLineOptionOfListType>option).element;
1328-
const typeMap = <Map<number | string>>element.type;
1329-
optionsDescriptionMap.set(description, arrayFrom(typeMap.keys()).map(key => `'${key}'`));
1330-
}
1331-
else {
1332-
description = getDiagnosticText(option.description);
1333-
}
1334-
1335-
descriptionColumn.push(description);
1336-
1337-
// Set the new margin for the description column if necessary.
1338-
marginLength = Math.max(usageText.length, marginLength);
1339-
}
1340-
1341-
// Special case that can't fit in the loop.
1342-
const usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
1343-
usageColumn.push(usageText);
1344-
descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file));
1345-
marginLength = Math.max(usageText.length, marginLength);
1346-
1347-
// Print out each row, aligning all the descriptions on the same column.
1348-
for (let i = 0; i < usageColumn.length; i++) {
1349-
const usage = usageColumn[i];
1350-
const description = descriptionColumn[i];
1351-
const kindsList = optionsDescriptionMap.get(description);
1352-
output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine);
1353-
1354-
if (kindsList) {
1355-
output.push(makePadding(marginLength + 4));
1356-
for (const kind of kindsList) {
1357-
output.push(kind + " ");
1358-
}
1359-
output.push(sys.newLine);
1360-
}
1361-
}
1362-
1363-
for (const line of output) {
1364-
sys.write(line);
1365-
}
1366-
return;
1367-
1368-
function getParamType(option: CommandLineOption) {
1369-
if (option.paramType !== undefined) {
1370-
return " " + getDiagnosticText(option.paramType);
1371-
}
1372-
return "";
1373-
}
1374-
1375-
function makePadding(paddingLength: number): string {
1376-
return Array(paddingLength + 1).join(" ");
1377-
}
1378-
}
1379-
13801267
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
13811268
/**
13821269
* Reports config file diagnostics
@@ -1801,22 +1688,29 @@ namespace ts {
18011688
references: readonly ProjectReference[] | undefined;
18021689
}
18031690

1691+
/** @internal */
1692+
export interface ConvertToTSConfigHost {
1693+
getCurrentDirectory(): string;
1694+
useCaseSensitiveFileNames: boolean;
1695+
}
1696+
18041697
/**
18051698
* Generate an uncommented, complete tsconfig for use with "--showConfig"
18061699
* @param configParseResult options to be generated into tsconfig.json
18071700
* @param configFileName name of the parsed config file - output paths will be generated relative to this
18081701
* @param host provides current directory and case sensitivity services
18091702
*/
18101703
/** @internal */
1811-
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: { getCurrentDirectory(): string, useCaseSensitiveFileNames: boolean }): TSConfig {
1704+
export function convertToTSConfig(configParseResult: ParsedCommandLine, configFileName: string, host: ConvertToTSConfigHost): TSConfig {
18121705
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
18131706
const files = map(
18141707
filter(
18151708
configParseResult.fileNames,
18161709
(!configParseResult.configFileSpecs || !configParseResult.configFileSpecs.validatedIncludeSpecs) ? _ => true : matchesSpecs(
18171710
configFileName,
18181711
configParseResult.configFileSpecs.validatedIncludeSpecs,
1819-
configParseResult.configFileSpecs.validatedExcludeSpecs
1712+
configParseResult.configFileSpecs.validatedExcludeSpecs,
1713+
host,
18201714
)
18211715
),
18221716
f => getRelativePathFromFile(getNormalizedAbsolutePath(configFileName, host.getCurrentDirectory()), getNormalizedAbsolutePath(f, host.getCurrentDirectory()), getCanonicalFileName)
@@ -1854,11 +1748,11 @@ namespace ts {
18541748
return specs;
18551749
}
18561750

1857-
function matchesSpecs(path: string, includeSpecs: readonly string[] | undefined, excludeSpecs: readonly string[] | undefined): (path: string) => boolean {
1751+
function matchesSpecs(path: string, includeSpecs: readonly string[] | undefined, excludeSpecs: readonly string[] | undefined, host: ConvertToTSConfigHost): (path: string) => boolean {
18581752
if (!includeSpecs) return _ => true;
1859-
const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, sys.useCaseSensitiveFileNames, sys.getCurrentDirectory());
1860-
const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, sys.useCaseSensitiveFileNames);
1861-
const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, sys.useCaseSensitiveFileNames);
1753+
const patterns = getFileMatcherPatterns(path, excludeSpecs, includeSpecs, host.useCaseSensitiveFileNames, host.getCurrentDirectory());
1754+
const excludeRe = patterns.excludePattern && getRegexFromPattern(patterns.excludePattern, host.useCaseSensitiveFileNames);
1755+
const includeRe = patterns.includeFilePattern && getRegexFromPattern(patterns.includeFilePattern, host.useCaseSensitiveFileNames);
18621756
if (includeRe) {
18631757
if (excludeRe) {
18641758
return path => !(includeRe.test(path) && !excludeRe.test(path));

src/compiler/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace ts {
9191
/** Parses config file using System interface */
9292
export function parseConfigFileWithSystem(configFileName: string, optionsToExtend: CompilerOptions, system: System, reportDiagnostic: DiagnosticReporter) {
9393
const host: ParseConfigFileHost = <any>system;
94-
host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(sys, reportDiagnostic, diagnostic);
94+
host.onUnRecoverableConfigFileDiagnostic = diagnostic => reportUnrecoverableDiagnostic(system, reportDiagnostic, diagnostic);
9595
const result = getParsedCommandLineOfConfigFile(configFileName, optionsToExtend, host);
9696
host.onUnRecoverableConfigFileDiagnostic = undefined!; // TODO: GH#18217
9797
return result;

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
"unittests/services/extract/helpers.ts",
4141
"unittests/tsbuild/helpers.ts",
42+
"../tsc/executeCommandLine.ts",
4243
"unittests/tsc/helpers.ts",
4344
"unittests/tscWatch/helpers.ts",
4445
"unittests/tsserver/helpers.ts",

src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,12 @@ namespace ts {
99
projFs = undefined!; // Release the contents
1010
});
1111

12-
function outputs(folder: string) {
13-
return [
14-
`${folder}/index.js`,
15-
`${folder}/index.d.ts`,
16-
`${folder}/tsconfig.tsbuildinfo`
17-
];
18-
}
19-
20-
it("verify that subsequent builds after initial build doesnt build anything", () => {
21-
const fs = projFs.shadow();
22-
const host = fakes.SolutionBuilderHost.create(fs);
23-
createSolutionBuilder(host, ["/src"], { verbose: true }).build();
24-
host.assertDiagnosticMessages(
25-
getExpectedDiagnosticForProjectsInBuild("src/src/folder/tsconfig.json", "src/src/folder2/tsconfig.json", "src/src/tsconfig.json", "src/tests/tsconfig.json", "src/tsconfig.json"),
26-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/folder/tsconfig.json", "src/src/folder/index.js"],
27-
[Diagnostics.Building_project_0, "/src/src/folder/tsconfig.json"],
28-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/src/folder2/tsconfig.json", "src/src/folder2/index.js"],
29-
[Diagnostics.Building_project_0, "/src/src/folder2/tsconfig.json"],
30-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tests/tsconfig.json", "src/tests/index.js"],
31-
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"],
32-
);
33-
verifyOutputsPresent(fs, [
34-
...outputs("/src/src/folder"),
35-
...outputs("/src/src/folder2"),
36-
...outputs("/src/tests"),
37-
]);
38-
host.clearDiagnostics();
39-
createSolutionBuilder(host, ["/src"], { verbose: true }).build();
40-
host.assertDiagnosticMessages(
41-
getExpectedDiagnosticForProjectsInBuild("src/src/folder/tsconfig.json", "src/src/folder2/tsconfig.json", "src/src/tsconfig.json", "src/tests/tsconfig.json", "src/tsconfig.json"),
42-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/src/folder/tsconfig.json", "src/src/folder/index.ts", "src/src/folder/index.js"],
43-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/src/folder2/tsconfig.json", "src/src/folder2/index.ts", "src/src/folder2/index.js"],
44-
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, "src/tests/tsconfig.json", "src/tests/index.ts", "src/tests/index.js"],
45-
);
12+
verifyTscIncrementalEdits({
13+
scenario: "containerOnlyReferenced",
14+
subScenario: "verify that subsequent builds after initial build doesnt build anything",
15+
fs: () => projFs,
16+
commandLineArgs: ["--b", "/src", "--verbose"],
17+
incrementalScenarios: [noChangeRun]
4618
});
4719
});
4820
}

0 commit comments

Comments
 (0)