From b5b84f1cb01e9c063feba7a1b3acdfb41feca898 Mon Sep 17 00:00:00 2001 From: blindfs Date: Sat, 28 Dec 2024 19:37:42 +0800 Subject: [PATCH] chore: more readable output of utils.nu test_format --- run_test.nu | 2 +- utils.nu | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/run_test.nu b/run_test.nu index 1dc66a7..fb002fb 100755 --- a/run_test.nu +++ b/run_test.nu @@ -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_' diff --git a/utils.nu b/utils.nu index 6ee6749..bd262c9 100644 --- a/utils.nu +++ b/utils.nu @@ -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 @@ -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) @@ -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." + } }