Skip to content

Commit

Permalink
Support customTool tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Nov 25, 2021
1 parent 76c1fce commit ae378d7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/test/dart_debug/debug/dart_cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fsPath, getRandomInt } from "../../../shared/utils/fs";
import { resolvedPromise } from "../../../shared/utils/promises";
import { DartDebugClient } from "../../dart_debug_client";
import { createDebugClient, ensureFrameCategories, ensureMapEntry, ensureNoVariable, ensureVariable, ensureVariableWithIndex, getVariablesTree, isExternalPackage, isLocalPackage, isSdkFrame, isUserCode, spawnDartProcessPaused, startDebugger, waitAllThrowIfTerminates } from "../../debug_helpers";
import { activate, breakpointFor, closeAllOpenFiles, currentDoc, currentEditor, defer, delay, emptyFile, ensureArrayContainsArray, ensureHasRunWithArgsStarting, extApi, getAttachConfiguration, getDefinition, getLaunchConfiguration, getPackages, getResolvedDebugConfiguration, helloWorldBrokenFile, helloWorldDeferredEntryFile, helloWorldDeferredScriptFile, helloWorldExampleSubFolder, helloWorldExampleSubFolderMainFile, helloWorldFolder, helloWorldGettersFile, helloWorldGoodbyeFile, helloWorldHttpFile, helloWorldInspectionFile as helloWorldInspectFile, helloWorldLocalPackageFile, helloWorldLongRunningFile, helloWorldMainFile, helloWorldPartEntryFile, helloWorldPartFile, helloWorldStack60File, helloWorldThrowInExternalPackageFile, helloWorldThrowInLocalPackageFile, helloWorldThrowInSdkFile, myPackageFolder, openFile, positionOf, prepareHasRunFile, sb, setConfigForTest, setTestContent, uriFor, waitForResult, watchPromise, writeBrokenDartCodeIntoFileForTest } from "../../helpers";
import { activate, breakpointFor, closeAllOpenFiles, currentDoc, currentEditor, customScriptExt, defer, delay, emptyFile, ensureArrayContainsArray, ensureHasRunWithArgsStarting, extApi, getAttachConfiguration, getDefinition, getLaunchConfiguration, getPackages, getResolvedDebugConfiguration, helloWorldBrokenFile, helloWorldDeferredEntryFile, helloWorldDeferredScriptFile, helloWorldExampleSubFolder, helloWorldExampleSubFolderMainFile, helloWorldFolder, helloWorldGettersFile, helloWorldGoodbyeFile, helloWorldHttpFile, helloWorldInspectionFile as helloWorldInspectFile, helloWorldLocalPackageFile, helloWorldLongRunningFile, helloWorldMainFile, helloWorldPartEntryFile, helloWorldPartFile, helloWorldStack60File, helloWorldThrowInExternalPackageFile, helloWorldThrowInLocalPackageFile, helloWorldThrowInSdkFile, myPackageFolder, openFile, positionOf, prepareHasRunFile, sb, setConfigForTest, setTestContent, uriFor, waitForResult, watchPromise, writeBrokenDartCodeIntoFileForTest } from "../../helpers";


describe("dart cli debugger", () => {
Expand Down Expand Up @@ -1252,7 +1252,7 @@ insp=<inspected variable>
const hasRunFile = prepareHasRunFile(root, "dart");

const config = await startDebugger(dc, helloWorldMainFile, {
customTool: path.join(root, "scripts/custom_dart.sh"),
customTool: path.join(root, `scripts/custom_dart.${customScriptExt}`),
customToolReplacesArgs: 0,
});
await waitAllThrowIfTerminates(dc,
Expand Down
4 changes: 2 additions & 2 deletions src/test/dart_debug/debug/dart_test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LspTestOutlineInfo, LspTestOutlineVisitor } from "../../../shared/utils
import * as testUtils from "../../../shared/utils/test";
import { DartDebugClient } from "../../dart_debug_client";
import { createDebugClient, startDebugger, waitAllThrowIfTerminates } from "../../debug_helpers";
import { activate, captureDebugSessionCustomEvents, checkTreeNodeResults, clearTestTree, delay, ensureArrayContainsArray, ensureHasRunWithArgsStarting, extApi, getCodeLens, getExpectedResults, getPackages, getResolvedDebugConfiguration, helloWorldFolder, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestShortFile, helloWorldTestTreeFile, logger, makeTestTextTree, openFile as openFileBasic, positionOf, prepareHasRunFile, setConfigForTest, waitForResult } from "../../helpers";
import { activate, captureDebugSessionCustomEvents, checkTreeNodeResults, clearTestTree, customScriptExt, delay, ensureArrayContainsArray, ensureHasRunWithArgsStarting, extApi, getCodeLens, getExpectedResults, getPackages, getResolvedDebugConfiguration, helloWorldFolder, helloWorldTestBrokenFile, helloWorldTestDupeNameFile, helloWorldTestMainFile, helloWorldTestShortFile, helloWorldTestTreeFile, logger, makeTestTextTree, openFile as openFileBasic, positionOf, prepareHasRunFile, setConfigForTest, waitForResult } from "../../helpers";

describe("dart test debugger", () => {
// We have tests that require external packages.
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("dart test debugger", () => {
const hasRunFile = prepareHasRunFile(root, "dart_test");

const config = await startDebugger(dc, helloWorldTestMainFile, {
customTool: path.join(root, "scripts/custom_test.sh"),
customTool: path.join(root, `scripts/custom_test.${customScriptExt}`),
// Replace "run --no-spawn-devtools test:test"
customToolReplacesArgs: 3,
noDebug: true,
Expand Down
9 changes: 7 additions & 2 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tmpdir } from "os";
import * as path from "path";
import * as sinon from "sinon";
import * as vs from "vscode";
import { dartCodeExtensionIdentifier } from "../shared/constants";
import { dartCodeExtensionIdentifier, isWin } from "../shared/constants";
import { DartLaunchArgs } from "../shared/debug/interfaces";
import { LogCategory, TestStatus } from "../shared/enums";
import { IAmDisposable, Logger } from "../shared/interfaces";
Expand All @@ -27,6 +27,7 @@ export const fakeCancellationToken: vs.CancellationToken = {
isCancellationRequested: false,
onCancellationRequested: () => ({ dispose: () => undefined }),
};
export const customScriptExt = isWin ? "bat" : "sh";

if (!ext) {
logger.error("Quitting with error because extension failed to load.");
Expand Down Expand Up @@ -1022,7 +1023,11 @@ export function ensureHasRunWithArgsStarting(root: string, name: string, expecte
? name
: path.join(root, `scripts/has_run/${name}`);
assert.ok(fs.existsSync(hasRunFile));
const contents = fs.readFileSync(hasRunFile).toString();
const contents = fs.readFileSync(hasRunFile).toString()
// On Windows we get all the quotes from the args, but they're not
// important for the test so strip them so we can use the same
// expectation across platforms.
.replace(/"/g, "");
assert.ok(contents.trim().startsWith(expectedArgs.trim()), `Contents:\n${contents}\nExpected start:\n${expectedArgs}`);
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/test_projects/hello_world/scripts/custom_dart.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if not exist "%~dp0\has_run" mkdir "%~dp0\has_run"
echo %* > "%~dp0\has_run\dart"
dart %*
3 changes: 3 additions & 0 deletions src/test/test_projects/hello_world/scripts/custom_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if not exist "%~dp0\has_run" mkdir "%~dp0\has_run"
echo %* > "%~dp0\has_run\dart_test"
dart run test:test %*
3 changes: 3 additions & 0 deletions src/test/test_projects/web/hello_world/scripts/custom_web.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if not exist "%~dp0\has_run" mkdir "%~dp0\has_run"
echo %* > "%~dp0\has_run\web"
dart pub global run webdev daemon %*
4 changes: 2 additions & 2 deletions src/test/web_debug/debug/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DebuggerType, VmService } from "../../../shared/enums";
import { fsPath } from "../../../shared/utils/fs";
import { DartDebugClient } from "../../dart_debug_client";
import { createDebugClient, ensureVariable, startDebugger, waitAllThrowIfTerminates } from "../../debug_helpers";
import { activate, closeAllOpenFiles, defer, delay, ensureHasRunWithArgsStarting, extApi, getLaunchConfiguration, getPackages, logger, openFile, positionOf, prepareHasRunFile, sb, setConfigForTest, waitForResult, watchPromise, webBrokenIndexFile, webBrokenMainFile, webHelloWorldExampleSubFolder, webHelloWorldExampleSubFolderIndexFile, webHelloWorldFolder, webHelloWorldIndexFile, webHelloWorldMainFile, webProjectContainerFolder } from "../../helpers";
import { activate, closeAllOpenFiles, customScriptExt, defer, delay, ensureHasRunWithArgsStarting, extApi, getLaunchConfiguration, getPackages, logger, openFile, positionOf, prepareHasRunFile, sb, setConfigForTest, waitForResult, watchPromise, webBrokenIndexFile, webBrokenMainFile, webHelloWorldExampleSubFolder, webHelloWorldExampleSubFolderIndexFile, webHelloWorldFolder, webHelloWorldIndexFile, webHelloWorldMainFile, webProjectContainerFolder } from "../../helpers";

describe("web debugger", () => {
before("get packages (0)", () => getPackages(webHelloWorldIndexFile));
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("web debugger", () => {
const hasRunFile = prepareHasRunFile(root, "web");

const config = await startDebugger(dc, webHelloWorldIndexFile, {
customTool: path.join(root, "scripts/custom_web.sh"),
customTool: path.join(root, `scripts/custom_web.${customScriptExt}`),
// (dart) pub global run webdev daemon
customToolReplacesArgs: 5,
toolArgs: "--",
Expand Down

0 comments on commit ae378d7

Please sign in to comment.