Skip to content

Commit e40cbbd

Browse files
committed
Enhance cancellation handling in CheckModel tests
Updated the CheckModel cancellation tests to create temporary TLA+ and CFG files dynamically, improving isolation and reliability. The tests now ensure proper cleanup of temporary files and diagnostic collections after execution. This change enhances the robustness of the test suite by avoiding potential conflicts with existing files and ensuring a clean testing environment. Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
1 parent c0d6401 commit e40cbbd

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tests/suite/commands/checkModelCancel.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as assert from 'assert';
2+
import * as fs from 'fs';
3+
import * as os from 'os';
24
import * as path from 'path';
35
import * as vscode from 'vscode';
46

57
suite('CheckModel cancellation handling', () => {
8+
const fsp = fs.promises;
69
const tla2toolsPath = require.resolve(path.resolve(__dirname, '../../../src/tla2tools'));
710
const checkModelPath = require.resolve(path.resolve(__dirname, '../../../src/commands/checkModel'));
811
const modelPath = require.resolve(path.resolve(__dirname, '../../../src/model/check'));
@@ -71,12 +74,21 @@ suite('CheckModel cancellation handling', () => {
7174
const { doCheckModel, CTX_TLC_CAN_RUN_AGAIN, CTX_TLC_RUNNING } = await import(checkModelPath);
7275
const { SpecFiles } = await import(modelPath);
7376

74-
const specFiles = new SpecFiles('Dummy.tla', 'Dummy.cfg');
75-
const diagnostics = vscode.languages.createDiagnosticCollection('cancel-test');
77+
const tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'check-model-cancel-'));
78+
const tlaFile = path.join(tmpDir, 'Dummy.tla');
79+
const cfgFile = path.join(tmpDir, 'Dummy.cfg');
80+
await fsp.writeFile(tlaFile, '---- MODULE Dummy ----\n====\n');
81+
await fsp.writeFile(cfgFile, 'SPECIFICATION Spec\n');
7682

77-
await doCheckModel(specFiles, true, {} as vscode.ExtensionContext, diagnostics, true);
83+
const specFiles = new SpecFiles(tlaFile, cfgFile);
84+
const diagnostics = vscode.languages.createDiagnosticCollection('cancel-test');
7885

79-
diagnostics.dispose();
86+
try {
87+
await doCheckModel(specFiles, true, {} as vscode.ExtensionContext, diagnostics, true);
88+
} finally {
89+
diagnostics.dispose();
90+
await fsp.rm(tmpDir, { recursive: true, force: true });
91+
}
8092

8193
assert.strictEqual(
8294
contextValues[CTX_TLC_RUNNING],

0 commit comments

Comments
 (0)