Skip to content

Commit d6b59d7

Browse files
committed
Creates an empty .expected file when running test output compare
If the expected file does not already exists. This helps with test creation and allows users to create tests more quickly.
1 parent 9ddfd58 commit d6b59d7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

extensions/ql-vscode/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fix a bug where archived source folders for databases were not showing any contents.
88
- Fix URI encoding for databases that were created with special characters in their paths.
9+
- When comparing the results of a failed QL test run and the `.expected` file does not exist, an empty `.expected` file is created and compared against the `.actual` file.
910

1011
## 1.3.4 - 22 October 2020
1112

extensions/ql-vscode/src/test-ui.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import { Uri, TextDocumentShowOptions, commands, window } from 'vscode';
4+
import {
5+
TestHub,
6+
TestController,
7+
TestAdapter,
8+
TestRunStartedEvent,
9+
TestRunFinishedEvent,
10+
TestEvent,
11+
TestSuiteEvent
12+
} from 'vscode-test-adapter-api';
13+
14+
import { showAndLogWarningMessage } from './helpers';
415
import { TestTreeNode } from './test-tree-node';
516
import { DisposableObject } from './vscode-utils/disposable-object';
617
import { UIService } from './vscode-utils/ui-service';
7-
import { TestHub, TestController, TestAdapter, TestRunStartedEvent, TestRunFinishedEvent, TestEvent, TestSuiteEvent } from 'vscode-test-adapter-api';
818
import { QLTestAdapter, getExpectedFile, getActualFile } from './test-adapter';
919
import { logger } from './logging';
1020

@@ -78,12 +88,17 @@ export class TestUIService extends UIService implements TestController {
7888
preserveFocus: true,
7989
preview: true
8090
};
91+
92+
if (!await fs.pathExists(expectedPath)) {
93+
showAndLogWarningMessage(`'${path.basename(expectedPath)}' does not exist. Creating an empty file.`);
94+
await fs.createFile(expectedPath);
95+
}
96+
8197
if (await fs.pathExists(actualPath)) {
8298
const actualUri = Uri.file(actualPath);
8399
await commands.executeCommand<void>('vscode.diff', expectedUri, actualUri,
84100
`Expected vs. Actual for ${path.basename(testId)}`, options);
85-
}
86-
else {
101+
} else {
87102
await window.showTextDocument(expectedUri, options);
88103
}
89104
}

0 commit comments

Comments
 (0)