Skip to content

Commit 7613bf1

Browse files
committed
Fix filename variable substitution to strip any extension
When using ${modelName} or ${specName} in TLC custom options, the variables now correctly resolve to the base filename without extension, regardless of whether the file has a .cfg or .tla extension. Previously, path.basename(file, '.ext') would only strip the specified extension, causing ${modelName}.dot to expand to "Model.tla.dot" when the config was embedded in a .tla file instead of the expected "Model.dot". Now using path.parse(file).name which properly strips any extension. Fixes Github issue #483 #483 [Bug] Signed-off-by: Markus Alexander Kuppe <github.com@lemmster.de>
1 parent 8a3409b commit 7613bf1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/tla2tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ export function extractFingerprintFromTrace(traceFilePath: string): number | und
484484
export async function buildTlcOptions(tlaFilePath: string, cfgFilePath: string, customOptions: string[]): Promise<string[]> {
485485
const custOpts = customOptions.map((opt) => {
486486
return opt
487-
.replace(VAR_TLC_SPEC_NAME, path.basename(tlaFilePath, '.tla'))
488-
.replace(VAR_TLC_MODEL_NAME, path.basename(cfgFilePath, '.cfg'));
487+
.replace(VAR_TLC_SPEC_NAME, path.parse(tlaFilePath).name)
488+
.replace(VAR_TLC_MODEL_NAME, path.parse(cfgFilePath).name);
489489
});
490490
const opts = [path.basename(tlaFilePath), '-tool', '-modelcheck'];
491491
addValueOrDefault('-config', cfgFilePath, custOpts, opts);

tests/suite/tla2tools.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,34 @@ suite('TLA+ Tools Test Suite', () => {
103103
assert.strictEqual(result[dumpIdx + 2], 'bar.dot');
104104
});
105105

106+
test('Strips .tla extension from modelName when CONFIG is embedded (regression for #483)', async () => {
107+
const result = await buildTlcOptions(
108+
'/path/to/HourClock.tla',
109+
'/path/to/HourClock.tla',
110+
['-dump', 'dot,colorize,actionlabels', '${modelName}.dot']
111+
);
112+
assert.strictEqual(result[0], 'HourClock.tla');
113+
assert.ok(result.includes('-dump'));
114+
const dumpIdx = result.indexOf('-dump');
115+
assert.strictEqual(result[dumpIdx + 1], 'dot,colorize,actionlabels');
116+
assert.strictEqual(result[dumpIdx + 2], 'HourClock.dot',
117+
'modelName should expand to HourClock.dot, not HourClock.tla.dot');
118+
});
119+
120+
test('Strips .tla extension from specName when CONFIG is embedded', async () => {
121+
const result = await buildTlcOptions(
122+
'/path/to/HourClock.tla',
123+
'/path/to/HourClock.tla',
124+
['-dump', 'dot', '${specName}.dot']
125+
);
126+
assert.strictEqual(result[0], 'HourClock.tla');
127+
assert.ok(result.includes('-dump'));
128+
const dumpIdx = result.indexOf('-dump');
129+
assert.strictEqual(result[dumpIdx + 1], 'dot');
130+
assert.strictEqual(result[dumpIdx + 2], 'HourClock.dot',
131+
'specName should expand to HourClock.dot, not HourClock.tla.dot');
132+
});
133+
106134
test('Provides default classpath and GC in Java options', async () => {
107135
assert.deepEqual(
108136
buildJavaOptions(

0 commit comments

Comments
 (0)