Skip to content

Commit a8deca2

Browse files
authored
Fix issue with ACON::Style::Athena#error_style (#240)
1 parent 48a8d0c commit a8deca2

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/components/console/spec/style/athena_style_spec.cr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ struct AthenaStyleTest < ASPEC::TestCase
2121
string.should match(Regex.new(File.read(normalized_path))), file: file, line: line
2222
end
2323

24+
def test_error_style : Nil
25+
error_output = ACON::Output::IO.new io = IO::Memory.new
26+
output = ACON::Output::ConsoleOutput.new
27+
output.stderr = error_output
28+
29+
style = ACON::Style::Athena.new ACON::Input::Hash.new({} of String => String), output
30+
style.error_style.puts "foo"
31+
32+
io.to_s.should eq "foo\n"
33+
end
34+
35+
def test_error_style_non_console_output : Nil
36+
output = ACON::Output::IO.new io = IO::Memory.new
37+
38+
style = ACON::Style::Athena.new ACON::Input::Hash.new({} of String => String), output
39+
style.error_style.puts "foo"
40+
41+
io.to_s.should eq "foo\n"
42+
end
43+
2444
@[DataProvider("output_provider")]
2545
def test_outputs(command_proc : ACON::Commands::Generic::Proc, file_path : String) : Nil
2646
command = ACON::Commands::Generic.new "foo", &command_proc

src/components/console/src/style/output.cr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,12 @@ abstract class Athena::Console::Style::Output
5353
def verbosity=(verbosity : ACON::Output::Verbosity) : Nil
5454
@output.verbosity = verbosity
5555
end
56+
57+
protected def error_output : ACON::Output::Interface
58+
unless (output = @output).is_a? ACON::Output::ConsoleOutputInterface
59+
return @output
60+
end
61+
62+
output.error_output
63+
end
5664
end

0 commit comments

Comments
 (0)