Skip to content

Commit

Permalink
make test more informative, add print on skip
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 12, 2024
1 parent 40e8357 commit 88501b4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions vlib/v/util/diff/diff_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,22 @@ fn test_compare_files() {
assert res.contains("-\tversion: '0.0.0'"), res
assert res.contains("+\tversion: '0.1.0'"), res
assert res.contains("+\tlicense: 'MIT'"), res
}

// Test coloring
if !os.execute('diff --color=always').output.contains('--color=always') {
fn test_coloring() {
color_flag := '--color=always'
if os.execute('diff ${color_flag}').output.contains(color_flag) {
// If the flag is unknown, it will be reprinted in the output.
assert res.contains("[31m-\tversion: '0.0.0'[m"), res
assert res.contains("[32m+\tversion: '0.1.0'[m"), res
eprintln('> skipping test, since `diff` does not support `${color_flag}`')
return
}
f1 := 'abc\n'
f2 := 'abcd\n'
p1 := os.join_path(tdir, '${@FN}_f1.txt')
p2 := os.join_path(tdir, '${@FN}_f2.txt')
os.write_file(p1, f1)!
os.write_file(p2, f2)!
res := diff.color_compare_files('diff', p1, p2)
assert res.contains('-abc'), res
assert res.contains('+abcd'), res
}

0 comments on commit 88501b4

Please sign in to comment.