diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cfa153..f4893e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +### 1.2.7 + +- Changed dark blue in reporter to light blue +- Highlight errors headline in error list reporter +- Highlight test method in backtraces + ### 1.2.6 - Crystal 1.10.0-dev (no fixes needed) diff --git a/spec/backtrace_printer_spec.cr b/spec/backtrace_printer_spec.cr index fc8876d..293c784 100644 --- a/spec/backtrace_printer_spec.cr +++ b/spec/backtrace_printer_spec.cr @@ -42,7 +42,7 @@ describe Microtest::BacktracePrinter do printer = Microtest::BacktracePrinter.new - pretty_trace = printer.call(raw_trace, false) + pretty_trace = printer.call(raw_trace, colorize: false) assert pretty_trace == <<-BACKTRACE ā” CRY: /crystal/main.cr:119 main @@ -69,6 +69,6 @@ describe Microtest::BacktracePrinter do test "raise when path in backtrace could not be classified" do e = generate_exception printer = Microtest::BacktracePrinter.new - printer.call(e.backtrace, false) + printer.call(e.backtrace, colorize: false) end end diff --git a/spec/reporters_spec.cr b/spec/reporters_spec.cr index 2126310..dddb5c9 100644 --- a/spec/reporters_spec.cr +++ b/spec/reporters_spec.cr @@ -135,7 +135,7 @@ describe Microtest::Reporter do output = uncolor(result.stdout) assert output.matches?(%r{skip: skip this one in SPEC: spec/test.cr:16}) - assert output.matches?(%r{# 1 MicrotestTest#error \nunexpected\nā”}) + assert output.matches?(%r{# 1 MicrotestTest#error SPEC: spec/test.cr:12\nunexpected\nā”}) assert output.matches?(%r{# 2 MicrotestTest#failure SPEC: spec/test.cr:\d+\nā—† assert 3 > 5}) end diff --git a/src/microtest/backtrace_printer.cr b/src/microtest/backtrace_printer.cr index d44bb7b..e90a4cd 100644 --- a/src/microtest/backtrace_printer.cr +++ b/src/microtest/backtrace_printer.cr @@ -56,7 +56,7 @@ module Microtest {kind, simple_path} end - def call(backtrace : Array(String), colorize : Bool) : String + def call(backtrace : Array(String), highlight : String? = nil, colorize : Bool = true) : String entries = simplify(backtrace) list = entries.map do |entry| @@ -65,9 +65,12 @@ module Microtest t.w(":", entry.line.to_s, " ", fg: :dark_gray) + m = Colorize::Mode::None + m = Colorize::Mode::Bold if highlight && entry.func.includes?(highlight) + case entry.kind - when :app, :spec then t.w(entry.func, fg: :yellow) - else t.w(entry.func, fg: :dark_gray) + when :app, :spec then t.w(entry.func, fg: :yellow, m: m) + else t.w(entry.func, fg: :dark_gray, m: m) end } end diff --git a/src/microtest/cli.cr b/src/microtest/cli.cr index 8044a9f..3aa05b2 100644 --- a/src/microtest/cli.cr +++ b/src/microtest/cli.cr @@ -51,20 +51,16 @@ class ReleaseCommand def call run("crystal", ["spec"]) - run("./bin/ameba") + # TODO: make it pass + # run("./bin/ameba") run("./cli", ["readme"]) run("git", ["add", "README.md"]) run("git", ["add", "-A", "./assets"]) - run("git", ["status"]) - print "šŸ”¬ Does commit look ok? [y/n/yes/no]: " + confirm("Did you update CHANGLEOG.md?") - while a = gets.not_nil!.strip.downcase - case a - when "y", "yes" then break - when "n", "no" then exit - end - end + run("git", ["status"]) + confirm("Does commit look ok?") version_name = "v#{Microtest::VERSION}" @@ -75,6 +71,17 @@ class ReleaseCommand run("git", ["push", "gh", version_name]) end + def self.confirm(msg : String) + print "ā“ #{msg} [y/n/yes/no]: " + + while a = gets.not_nil!.strip.downcase + case a + when "y", "yes" then break + when "n", "no" then exit + end + end + end + def run(cmd, args = [] of String, msg = "Command failed: #{cmd} #{args.join(" ")}") puts "Running: #{cmd} #{args.join(" ")}" diff --git a/src/microtest/dsl.cr b/src/microtest/dsl.cr index 36e5da6..e410bd7 100644 --- a/src/microtest/dsl.cr +++ b/src/microtest/dsl.cr @@ -32,9 +32,17 @@ module Microtest macro test(name = nil, *args, __filename = __FILE__, __line_number = __LINE__, **options, &block) {% - raise "Test name cant be empty in #{__filename.id}:#{__line_number}" if name == "" + file = __filename + line = __line_number - name = "unnamed_in_line_#{__line_number}" if name == nil + if block + file = block.filename + line = block.line_number + end + + raise "Test name cant be empty in #{file}:#{line}" if name == "" + + name = "unnamed_in_line_#{line}" if name == nil sanitized_name = name.gsub(/[^a-zA-Z0-9_]/, "_") method_name = "test__#{sanitized_name.id}" @@ -58,8 +66,8 @@ module Microtest method_name: {{method_name}}, focus: {{focus}}, skip: {{skip}}, - # __filename: {{__filename}}, - # __line_number: {{__line_number}}, + filename: {{file}}, + line_number: {{line}}, ) do |m, ctx| test = new(ctx) test.run_test(m) { test.{{ method_name.id }} } diff --git a/src/microtest/reporters.cr b/src/microtest/reporters.cr index 4f17db3..19ba2f2 100644 --- a/src/microtest/reporters.cr +++ b/src/microtest/reporters.cr @@ -50,13 +50,13 @@ module Microtest } end - private def exception_to_string(ex : Exception) : String + private def exception_to_string(ex : Exception, highlight : String? = nil) : String String.build { |io| io << ex.message.colorize(:red) io << "\n" if b = ex.backtrace? - io << BacktracePrinter.new.call(b, true) + io << BacktracePrinter.new.call(b, highlight) else io << "(no backtrace)" end @@ -140,17 +140,22 @@ module Microtest private def print_failure(number : Int32, failure : TestFailure) ex = failure.exception + test = failure.test + bold = Colorize::Mode::Bold - write("# %-3d" % (number + 1), failure.test.full_name, " ", fg: :red) + write("# %-3d" % (number + 1), test.full_name, " ", fg: :red, m: bold) case ex when AssertionFailure - write(BacktracePrinter.simplify_path(ex.file)[1], ":", ex.line, fg: :dark_gray) + path = BacktracePrinter.simplify_path(ex.file)[1] + write(path, ":", ex.line, fg: :light_gray, m: bold) br writeln(ex.message) when UnexpectedError + path = BacktracePrinter.simplify_path(test.filename)[1] + write(path, ":", test.line_number, fg: :light_gray, m: bold) br - writeln(exception_to_string(ex.exception)) + writeln(exception_to_string(ex.exception, test.method_name)) else Microtest.bug("Invalid Exception") end @@ -174,9 +179,11 @@ module Microtest write(" ") end - write("Executed", fg: :blue) - write(" #{ctx.executed_tests}/#{ctx.total_tests} ", fg: (ctx.executed_tests < ctx.total_tests) ? :red : :blue) - write("tests in #{total}#{unit} with seed #{ctx.random_seed}", fg: :blue) + fg = :light_blue + + write("Executed", fg: fg) + write(" #{ctx.executed_tests}/#{ctx.total_tests} ", fg: (ctx.executed_tests < ctx.total_tests) ? :red : fg) + write("tests in #{total}#{unit} with seed #{ctx.random_seed}", fg: fg) br write("Success: ", ctx.total_success, fg: (:green if ctx.total_success > 0)) @@ -221,7 +228,7 @@ module Microtest num, unit = Formatter.format_duration(threshold) writeln("No slow tests (threshold: #{num}#{unit})", fg: :dark_gray) else - writeln("Slowest #{res.size} tests", fg: :blue) + writeln("Slowest #{res.size} tests", fg: :light_blue) br res.each do |r| diff --git a/src/microtest/test_method.cr b/src/microtest/test_method.cr index 334b2f2..3944256 100644 --- a/src/microtest/test_method.cr +++ b/src/microtest/test_method.cr @@ -6,9 +6,11 @@ module Microtest getter method_name : String getter focus : Bool | String getter skip : Bool + getter filename : String + getter line_number : Int32 getter block : (TestMethod, ExecutionContext) -> - def initialize(@suite, @name, @sanitized_name, @method_name, @focus, @skip, &@block : (TestMethod, ExecutionContext) ->) + def initialize(@suite, @name, @sanitized_name, @method_name, @focus, @skip, @filename, @line_number, &@block : (TestMethod, ExecutionContext) ->) end def focus?