2019-05-29 22:19:22 +00:00
|
|
|
|
Encoding.default_external = Encoding::UTF_8
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
require "minitest/autorun"
|
|
|
|
|
require "inspec/ui"
|
|
|
|
|
require "inspec/base_cli"
|
2019-06-07 23:33:56 +00:00
|
|
|
|
require "inspec/errors"
|
2019-06-11 22:24:35 +00:00
|
|
|
|
require "stringio"
|
2018-12-12 16:44:16 +00:00
|
|
|
|
|
|
|
|
|
# https://gist.github.com/chrisopedia/8754917
|
|
|
|
|
# http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#256-colors
|
|
|
|
|
ANSI_CODES = {
|
|
|
|
|
reset: "\e[0m",
|
|
|
|
|
bold: "\e[1m",
|
|
|
|
|
color: {
|
2019-06-11 22:24:35 +00:00
|
|
|
|
red: "\e[38;5;9m", # 256-color light red
|
2018-12-12 16:44:16 +00:00
|
|
|
|
green: "\e[38;5;41m", # 256-color light green
|
|
|
|
|
yellow: "\e[33m",
|
|
|
|
|
cyan: "\e[36m",
|
|
|
|
|
white: "\e[37m",
|
|
|
|
|
grey: "\e[38;5;247m", # 256-color medium grey
|
|
|
|
|
},
|
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
|
|
GLYPHS = {
|
2019-06-11 22:24:35 +00:00
|
|
|
|
bullet: "•", # BULLET, Unicode: U+2022, UTF-8: E2 80 A2
|
|
|
|
|
check: "✔", # HEAVY CHECK MARK, Unicode: U+2714, UTF-8: E2 9C 94
|
|
|
|
|
swirl: "↺", # ANTICLOCKWISE OPEN CIRCLE ARROW, Unicode U+21BA, UTF-8: E2 86 BA
|
|
|
|
|
script_x: "×", # MULTIPLICATION SIGN, Unicode: U+00D7, UTF-8: C3 97
|
|
|
|
|
question: "?", # normal ASCII question mark
|
|
|
|
|
em_dash: "─", # BOX DRAWINGS LIGHT HORIZONTAL Unicode: U+2500, UTF-8: E2 94 80
|
|
|
|
|
heavy_dash: "≖", # RING IN EQUAL TO, Unicode: U+2256, UTF-8: E2 89 96
|
|
|
|
|
vertical_dash: "│", # │ BOX DRAWINGS LIGHT VERTICAL, Unicode: U+2502, UTF-8: E2 94 82
|
|
|
|
|
table_corner: "⨀", # N-ARY CIRCLED DOT OPERATOR, Unicode: U+2A00, UTF-8: E2 A8 80
|
2018-12-12 16:44:16 +00:00
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# Low-Level Formatting
|
|
|
|
|
#=============================================================================#
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "Inspec::UI low-level Formatting" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
let(:fixture_io) { StringIO.new }
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:output) { fixture_io.string }
|
|
|
|
|
let(:ui) { Inspec::UI.new(io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "plain" do
|
|
|
|
|
it "uses no ANSI markers" do
|
|
|
|
|
ui.plain("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include("test")
|
|
|
|
|
_(output).wont_include('\e[')
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is enabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: true, io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "bold" do
|
|
|
|
|
it "uses ANSI bold markers" do
|
|
|
|
|
ui.bold("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(ANSI_CODES[:bold] + "test" + ANSI_CODES[:reset])
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "colors" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
%i{red green cyan yellow white grey}.each do |color|
|
2019-05-31 21:59:06 +00:00
|
|
|
|
it("uses the color code for " + color.to_s) do
|
2019-06-11 22:24:35 +00:00
|
|
|
|
ui.send(color, "test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(ANSI_CODES[:color][color] + "test" + ANSI_CODES[:reset])
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is disabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: false, io: fixture_io) }
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "bold" do
|
|
|
|
|
it "uses no ANSI codes" do
|
|
|
|
|
ui.bold("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[')
|
|
|
|
|
_(output).must_equal("test")
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "colors" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
%i{red green yellow white grey}.each do |color|
|
2019-05-31 21:59:06 +00:00
|
|
|
|
it("uses no ANSI codes for " + color.to_s) do
|
2019-06-11 22:24:35 +00:00
|
|
|
|
ui.send(color, "test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[')
|
|
|
|
|
_(output).must_equal("test")
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# High-Level Formatting
|
|
|
|
|
#=============================================================================#
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "Inspec::UI High-Level Formatting" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
let(:fixture_io) { StringIO.new }
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:output) { fixture_io.string }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is enabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: true, io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "emphasis" do
|
|
|
|
|
it "uses ANSI escapes" do
|
|
|
|
|
result = ui.emphasis("test")
|
2018-11-16 20:32:24 +00:00
|
|
|
|
# Emphasis does not print by default
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(result).must_equal(ANSI_CODES[:color][:cyan] + "test" + ANSI_CODES[:reset])
|
|
|
|
|
_(output).must_equal ""
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "headline" do
|
|
|
|
|
it "formats the headline when short" do
|
|
|
|
|
ui.headline("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_match(/^\n/) # Start with one newlines
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ""
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 36 + " "
|
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:white] + "test" + ANSI_CODES[:reset]
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 36 + " "
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n\n$/) # End with two newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
it "formats the headline when longer" do
|
|
|
|
|
ui.headline("Testing is Such a Pleasure!")
|
|
|
|
|
expected = ""
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 24 + " "
|
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:white] + "Testing is Such a Pleasure!" + ANSI_CODES[:reset]
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 24 + " "
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "error" do
|
|
|
|
|
it "formats the message" do
|
|
|
|
|
ui.error("Everything has gone terribly wrong")
|
|
|
|
|
expected = ""
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:red]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += "ERROR:"
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:reset]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += " "
|
|
|
|
|
expected += "Everything has gone terribly wrong"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n$/) # End with a newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "warning" do
|
|
|
|
|
it "formats the message" do
|
|
|
|
|
ui.warning("Maybe we can still pull through this")
|
|
|
|
|
expected = ""
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:yellow]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += "WARNING:"
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:reset]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += " "
|
|
|
|
|
expected += "Maybe we can still pull through this"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n$/) # End with a newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is disabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: false, io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "emphasis" do
|
|
|
|
|
it "does not use ANSI escapes" do
|
|
|
|
|
result = ui.emphasis("test")
|
2018-11-16 20:32:24 +00:00
|
|
|
|
# Emphasis does not print by default
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(result).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(result).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
|
|
|
|
_(result).must_equal("test")
|
|
|
|
|
_(output).must_equal ""
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "headline" do
|
|
|
|
|
it "formats the headline when short" do
|
|
|
|
|
ui.headline("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ""
|
|
|
|
|
expected += " " + "-" * 36 + " "
|
|
|
|
|
expected += "test"
|
|
|
|
|
expected += " " + "-" * 36 + " "
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "error" do
|
|
|
|
|
it "formats the message without color" do
|
|
|
|
|
ui.error("Everything has gone terribly wrong")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ""
|
|
|
|
|
expected += "ERROR:"
|
|
|
|
|
expected += " "
|
|
|
|
|
expected += "Everything has gone terribly wrong"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n$/) # End with a newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "warning" do
|
|
|
|
|
it "formats the message" do
|
|
|
|
|
ui.warning("Maybe we can still pull through this")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ""
|
|
|
|
|
expected += "WARNING:"
|
|
|
|
|
expected += " "
|
|
|
|
|
expected += "Maybe we can still pull through this"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n$/) # End with a newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# Tables and Lists
|
|
|
|
|
#=============================================================================#
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "Inspec::UI Tables and Lists" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
let(:fixture_io) { StringIO.new }
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:output) { fixture_io.string }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is enabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: true, io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("line") do
|
|
|
|
|
it "draws a line" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
ui.line
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ANSI_CODES[:bold] + GLYPHS[:heavy_dash] * 80 + ANSI_CODES[:reset] + "\n"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("list_item") do
|
|
|
|
|
it "makes a bullet point" do
|
|
|
|
|
ui.list_item("test")
|
|
|
|
|
expected = " "
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:white]
|
|
|
|
|
expected += GLYPHS[:bullet]
|
|
|
|
|
expected += ANSI_CODES[:reset]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += " " + "test" + "\n"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("tables") do
|
|
|
|
|
it "makes a table" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
ui.table do |t|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
t.header = %w{Fruit Tartness Succulence}
|
|
|
|
|
t << ["Dragonfruit", "Very Low", "High"]
|
|
|
|
|
t << ["The Exquisite Lime, Scurvy's Bane", "High", "Medium"]
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
lines = output.split("\n")
|
|
|
|
|
|
|
|
|
|
# First, third, and last lines should be horizontal dividors
|
|
|
|
|
[0, 2, -1].each do |idx|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(lines[idx]).must_include(GLYPHS[:em_dash] * 3)
|
|
|
|
|
_(lines[idx]).wont_include(" ")
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Second, fourth, and fifth lines should have custom vertical dividors
|
|
|
|
|
[1, 3, 4].each do |idx|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(lines[idx]).must_match(/^#{GLYPHS[:vertical_dash]}/) # Start with a vertical line
|
|
|
|
|
_(lines[idx]).must_match(/#{GLYPHS[:vertical_dash]}$/) # End with a vertical line
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Second (header) line should have bold and white on each header label
|
2019-06-11 22:24:35 +00:00
|
|
|
|
lines[1].split(GLYPHS[:vertical_dash]).map(&:strip).reject { |e| e == "" }.each do |header_label|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(header_label).must_include ANSI_CODES[:bold] + ANSI_CODES[:color][:white]
|
|
|
|
|
_(header_label).must_include ANSI_CODES[:reset]
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "when color is disabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:ui) { Inspec::UI.new(color: false, io: fixture_io) }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("line") do
|
|
|
|
|
it "draws a line without ANSI codes or special glyphs" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
ui.line
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = "-" * 80 + "\n"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("list_item") do
|
|
|
|
|
it "makes a bullet point without ANSI codes or special glyphs" do
|
|
|
|
|
ui.list_item("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = " " + "*" + " " + "test" + "\n"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe("tables") do
|
|
|
|
|
it "makes a table ANSI codes or special glyphs" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
ui.table do |t|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
t.header = %w{Fruit Tartness Succulence}
|
|
|
|
|
t << ["Dragonfruit", "Very Low", "High"]
|
|
|
|
|
t << ["The Exquisite Lime, Scurvy's Bane", "High", "Medium"]
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).wont_include('\e[') # No ANSI escapes
|
|
|
|
|
_(output).wont_match(/[^[:ascii:]]/) # No non-ASCII chars (such as UTF-8 glyphs)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
|
|
|
|
|
lines = output.split("\n")
|
|
|
|
|
|
|
|
|
|
# First, third, and last lines should be horizontal dividors
|
|
|
|
|
[0, 2, -1].each do |idx|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(lines[idx]).must_match(/^\+/) # Start with a corner
|
|
|
|
|
_(lines[idx]).must_match(/\+$/) # End with a corner
|
|
|
|
|
_(lines[idx]).must_match(/\-\+\-/) # Have internal corners
|
|
|
|
|
_(lines[idx]).wont_include(" ")
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Second, fourth, and fifth lines should have stock vertical dividors
|
|
|
|
|
[1, 3, 4].each do |idx|
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(lines[idx]).must_match(/^\|/) # Start with a vertical line
|
|
|
|
|
_(lines[idx]).must_match(/\|$/) # End with a vertical line
|
|
|
|
|
_(lines[idx]).must_match(/\s\|\s/) # Have vertical line
|
|
|
|
|
_(lines[idx]).wont_include("+")
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# CLI Integration
|
|
|
|
|
#=============================================================================#
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "Inspec::UI CLI integration" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
let(:fixture_io) { StringIO.new }
|
2018-12-12 16:44:16 +00:00
|
|
|
|
let(:output) { fixture_io.string }
|
|
|
|
|
let(:cli) { Inspec::BaseCLI.new }
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "ui method" do
|
|
|
|
|
it "should respond to ui" do
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(cli).must_respond_to(:ui)
|
|
|
|
|
_(cli).must_respond_to(:'ui=')
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "backwards compatibility" do
|
|
|
|
|
it "should support plain_text" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
cli.ui = Inspec::UI.new(io: fixture_io)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
cli.plain_text("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal "test\n"
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
it "should support mark_text" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
# mark_text applies cyan and DOES NOT PRINT
|
|
|
|
|
cli.ui = Inspec::UI.new(io: fixture_io)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
result = cli.mark_text("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(result).must_equal ANSI_CODES[:color][:cyan] + "test" + ANSI_CODES[:reset]
|
|
|
|
|
_(output).must_equal ""
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
it "should support headline" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
cli.ui = Inspec::UI.new(io: fixture_io)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
cli.headline("test")
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_match(/^\n/) # Start with one newlines
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected = ""
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 36 + " "
|
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:white] + "test" + ANSI_CODES[:reset]
|
|
|
|
|
expected += " " + GLYPHS[:em_dash] * 36 + " "
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_include(expected)
|
|
|
|
|
_(output).must_match(/\n\n$/) # End with two newline
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
|
it "should support li" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
cli.ui = Inspec::UI.new(io: fixture_io)
|
2019-06-11 22:24:35 +00:00
|
|
|
|
cli.li("test")
|
|
|
|
|
expected = " "
|
2018-12-12 16:44:16 +00:00
|
|
|
|
expected += ANSI_CODES[:bold] + ANSI_CODES[:color][:white]
|
|
|
|
|
expected += GLYPHS[:bullet]
|
|
|
|
|
expected += ANSI_CODES[:reset]
|
2019-06-11 22:24:35 +00:00
|
|
|
|
expected += " " + "test" + "\n"
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(output).must_equal(expected)
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# Interactivity
|
|
|
|
|
#=============================================================================#
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "interactivity" do
|
|
|
|
|
describe "when interactivity is disabled" do
|
|
|
|
|
describe "interactive check" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
it "should be false" do
|
|
|
|
|
ui = Inspec::UI.new(interactive: false)
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(ui.interactive?).must_equal false
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "prompt" do
|
|
|
|
|
it "should throw an exception if interactivity is disabled" do
|
2018-12-12 16:44:16 +00:00
|
|
|
|
ui = Inspec::UI.new(interactive: false)
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(->() { ui.prompt }).must_raise Inspec::UserInteractionRequired
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# Exit Codes
|
|
|
|
|
#=============================================================================#
|
|
|
|
|
# These are tested in functional tests
|
2019-06-11 22:24:35 +00:00
|
|
|
|
describe "Inspec UI Exit Codes" do
|
2019-07-09 00:20:30 +00:00
|
|
|
|
%i{
|
|
|
|
|
EXIT_NORMAL
|
|
|
|
|
EXIT_USAGE_ERROR
|
|
|
|
|
EXIT_PLUGIN_ERROR
|
|
|
|
|
EXIT_SKIPPED_TESTS
|
|
|
|
|
EXIT_FAILED_TESTS
|
|
|
|
|
}.each do |const_name|
|
2018-12-12 16:44:16 +00:00
|
|
|
|
it "should define #{const_name}" do
|
2019-09-30 22:31:55 +00:00
|
|
|
|
_(Inspec::UI.const_defined?(const_name)).must_equal true
|
2018-12-12 16:44:16 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-04-24 00:21:31 +00:00
|
|
|
|
end
|