Skip to content

Commit

Permalink
chore: more readable output of utils.nu test_format
Browse files Browse the repository at this point in the history
  • Loading branch information
blindFS committed Dec 28, 2024
1 parent 723d694 commit b5b84f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion run_test.nu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $env.TOPIARY_CONFIG_FILE = (pwd | path join languages.ncl)
$env.TOPIARY_LANGUAGE_DIR = (pwd | path join languages)

for f in $files {
print $"Testing: (ansi green_bold)($f)(ansi reset)"
print $"(ansi green)Testing: (ansi yellow)($f)(ansi reset)"
cp $f $temp_file
topiary format $temp_file
let expected_file = $f | str replace --regex '/input_' '/expected_'
Expand Down
16 changes: 14 additions & 2 deletions utils.nu
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def print_progress [
let done = ''
let empty = ''
let count = [1 (($ratio * $length) | into int)] | math max
print -n (str_repeat $done $count) (str_repeat $empty ($length - $count)) ($ratio * 100 | into string --decimals 0) %
(
print -n
(str_repeat $done $count)
(str_repeat $empty ($length - $count))
($ratio * 100 | into string --decimals 0) %
)
}

# Test the topiary formatter with all nu files within a directory
Expand All @@ -38,6 +43,7 @@ export def test_format [
let files = glob $'($path | str trim -r -c '/')/**/*.nu'
let target = "./test.nu"
let len = $files | length
$env.format_detected_error = false
for i in 1..$len {
let file = $files | get ($i - 1)
print_progress ($i / $len)
Expand All @@ -49,11 +55,17 @@ export def test_format [
let err_after = run_ide_check $target
assert ($err_before == $err_after)
} catch {
print $file
$env.format_detected_error = true
print $"(ansi red)Error detected: (ansi yellow)($file)(ansi reset)"
if $break {
rm $target
break
}
}
rm $target
}
if not $env.format_detected_error {
print ''
print $"(ansi green)All nu scripts successfully passed the check, but style issues are still possible."
}
}

0 comments on commit b5b84f1

Please sign in to comment.