From c086fc17733206ca0fbe55ac5843949e7503f6f2 Mon Sep 17 00:00:00 2001 From: bluepython508 Date: Sat, 2 Dec 2023 19:25:19 +0000 Subject: [PATCH] Test result improvements: color --- lib/mix_tasks.ex | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/mix_tasks.ex b/lib/mix_tasks.ex index 6d7d90f..efe53d7 100644 --- a/lib/mix_tasks.ex +++ b/lib/mix_tasks.ex @@ -128,32 +128,24 @@ defmodule Mix.Tasks.Aoc do |> Enum.map(fn {test, input, p1e, p2e} -> parsed = mod.parse(input) p1 = mod.part1(parsed) - - if p1e do - if stringify(p1) != p1e do - IO.puts("Failed at #{test}.1: expected #{p1e}, got:") - dbg(p1) - else - IO.puts("Test #{test}.1 succeeded") - end - else - IO.puts("Test #{test}.1") - dbg(p1) - end - p2 = mod.part2(parsed) - if p2e do - if stringify(p2) != p2e do - IO.puts("Failed at #{test}.2: expected #{p2e}, got:") - dbg(p2) + result = fn (part, got, expected) -> + if expected do + if stringify(got) != expected do + IO.puts(IO.ANSI.format [:red, "Test #{test}.#{part} failed: expected #{expected}"]) + dbg(got) + else + IO.puts(IO.ANSI.format [:green, "Test #{test}.#{part} succeeded"]) + end else - IO.puts("Test #{test}.2 succeeded") + IO.puts("Test #{test}.#{part}:") + dbg(got) end - else - IO.puts("Test #{test}.2") - dbg(p2) end + + result.(1, p1, p1e) + result.(2, p2, p2e) end) end