Skip to content

Commit

Permalink
Creates an empty .expected file when running test output compare
Browse files Browse the repository at this point in the history
If the expected file does not already exists. This helps with test
creation and allows users to create tests more quickly.
  • Loading branch information
aeisenberg committed Nov 9, 2020
1 parent 245496c commit b163669
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [UNRELEASED]

- Editors opened by navigating from the results view are no longer opened in _preview mode_. Now they are opened as a persistent editor. [#630](https://github.com/github/vscode-codeql/pull/630)
- 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. [#669](https://github.com/github/vscode-codeql/pull/669)

## 1.3.6 - 4 November 2020

Expand All @@ -14,6 +15,7 @@
## 1.3.5 - 27 October 2020

- Fix a bug where archived source folders for databases were not showing any contents.
- Fix URI encoding for databases that were created with special characters in their paths.

## 1.3.4 - 22 October 2020

Expand Down
21 changes: 18 additions & 3 deletions extensions/ql-vscode/src/test-ui.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import { Uri, TextDocumentShowOptions, commands, window } from 'vscode';
import {
TestHub,
TestController,
TestAdapter,
TestRunStartedEvent,
TestRunFinishedEvent,
TestEvent,
TestSuiteEvent
} from 'vscode-test-adapter-api';

import { showAndLogWarningMessage } from './helpers';
import { TestTreeNode } from './test-tree-node';
import { DisposableObject } from './vscode-utils/disposable-object';
import { UIService } from './vscode-utils/ui-service';
import { TestHub, TestController, TestAdapter, TestRunStartedEvent, TestRunFinishedEvent, TestEvent, TestSuiteEvent } from 'vscode-test-adapter-api';
import { QLTestAdapter, getExpectedFile, getActualFile } from './test-adapter';
import { logger } from './logging';

Expand Down Expand Up @@ -78,12 +88,17 @@ export class TestUIService extends UIService implements TestController {
preserveFocus: true,
preview: true
};

if (!await fs.pathExists(expectedPath)) {
showAndLogWarningMessage(`'${path.basename(expectedPath)}' does not exist. Creating an empty file.`);
await fs.createFile(expectedPath);
}

if (await fs.pathExists(actualPath)) {
const actualUri = Uri.file(actualPath);
await commands.executeCommand<void>('vscode.diff', expectedUri, actualUri,
`Expected vs. Actual for ${path.basename(testId)}`, options);
}
else {
} else {
await window.showTextDocument(expectedUri, options);
}
}
Expand Down

0 comments on commit b163669

Please sign in to comment.