Skip to content

Commit e8605d8

Browse files
committed
Add an option to overwrite tests output with the current results.
Add `--overwrite-tests` flag that will result in overwriting the testfiles using the currently produced output.
1 parent 3324100 commit e8605d8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

bin/syntaxdev.js

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ testCli.addArgument([ '--no-color' ], {
4343
default: false
4444
});
4545

46+
testCli.addArgument([ '--overwrite-tests' ], {
47+
help: "Overwrite output for tests with the current output",
48+
action: 'storeTrue',
49+
default: false
50+
});
51+
4652
testCli.addArgument([ '--syntax' ], {
4753
help: 'Syntax file in YAML format, ex: "--syntax FooLang.YAML-tmLanguage"',
4854
required: true
@@ -120,6 +126,7 @@ function main() {
120126
options.syntax,
121127
{
122128
no_color: options.no_color,
129+
overwrite_tests: options.overwrite_tests,
123130
add_syntaxes: _.chain(options.add_syntax).flatten().
124131
uniq().sort().value()
125132
}

index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,25 @@ function testFile(file, grammar, options) {
299299
var result = tokenize(source);
300300

301301
if (test != result) {
302+
var extra = '';
303+
if (options.overwrite_tests) {
304+
extra = ', testfile updated';
305+
var buf = [source, '\n\n\n', result];
306+
fs.writeFileSync(file, buf.join('\n').trim() + '\n');
307+
}
308+
302309
if (test) {
303310
return {
304311
file: file,
305312
status: 'fail',
306-
error: 'Output different from expected',
313+
error: 'Output different from expected' + extra,
307314
body: getDiff(test, result)
308315
}
309316
} else {
310317
return {
311318
file: file,
312319
status: 'fail',
313-
error: 'No expected output set',
320+
error: 'No expected output set' + extra,
314321
body: result
315322
}
316323
}

0 commit comments

Comments
 (0)