logue 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.glarkrc +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/logue/frame.rb +28 -0
- data/lib/logue/line.rb +22 -0
- data/lib/logue/location.rb +25 -0
- data/lib/logue/location_format.rb +47 -0
- data/lib/logue/logger.rb +26 -45
- data/lib/logue/version.rb +6 -0
- data/lib/logue.rb +0 -4
- data/logue.gemspec +38 -0
- metadata +81 -38
- data/lib/logue/format.rb +0 -38
- data/lib/logue/writer.rb +0 -24
- data/test/logue/colors_test.rb +0 -12
- data/test/logue/format_test.rb +0 -59
- data/test/logue/log_test.rb +0 -88
- data/test/logue/loggable_test.rb +0 -72
- data/test/logue/logger_test.rb +0 -30
- data/test/logue/pathutil_test.rb +0 -73
- data/test/logue/testlog/log_stack_test.rb +0 -97
- data/test/logue/testlog/log_test.rb +0 -167
- data/test/logue/testlog/loggable_test.rb +0 -30
- data/test/logue/writer_test.rb +0 -57
data/test/logue/colors_test.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'logue/colors'
|
5
|
-
require 'test/unit'
|
6
|
-
|
7
|
-
class ColorsTest < Test::Unit::TestCase
|
8
|
-
def test_valid_colors
|
9
|
-
result = Colors.valid_colors
|
10
|
-
assert_equal [ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :default ], result.keys
|
11
|
-
end
|
12
|
-
end
|
data/test/logue/format_test.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/format'
|
6
|
-
|
7
|
-
class Logue::FormatTestCase < Test::Unit::TestCase
|
8
|
-
# use as:
|
9
|
-
# msg "path", path, "lineno", lineno, "cls", cls, "func", func
|
10
|
-
def message(*fields)
|
11
|
-
fields.each_slice(2).collect do |field, value|
|
12
|
-
"#{field}: #{value}"
|
13
|
-
end.join "; "
|
14
|
-
end
|
15
|
-
|
16
|
-
def assert_instance_variable expected, obj, name
|
17
|
-
val = obj.instance_eval name
|
18
|
-
assert_equal expected, val, "name: #{name}; expected: #{expected}; result: #{val}"
|
19
|
-
val
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_default_values
|
23
|
-
fmt = Logue::Format.new
|
24
|
-
assert_instance_variable Logue::FormatWidths::DEFAULT_FILENAME, fmt, "@file_width"
|
25
|
-
assert_instance_variable Logue::FormatWidths::DEFAULT_LINENUM, fmt, "@line_width"
|
26
|
-
assert_instance_variable Logue::FormatWidths::DEFAULT_FUNCTION, fmt, "@method_width"
|
27
|
-
assert_instance_variable true, fmt, "@trim"
|
28
|
-
end
|
29
|
-
|
30
|
-
def assert_format expected, path, lineno, cls, func
|
31
|
-
msg = message "path", path, "lineno", lineno, "cls", cls, "func", func
|
32
|
-
fmt = Logue::Format.new
|
33
|
-
fmt.format path, lineno, cls, func
|
34
|
-
result = fmt.format path, lineno, cls, func
|
35
|
-
assert_equal expected, result, msg
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_write
|
39
|
-
path = "/a/long/path/to/the/directory/abc.t"
|
40
|
-
lineno = 1
|
41
|
-
func = "block (2 levels) in one"
|
42
|
-
cls = nil
|
43
|
-
expected = "[.../the/directory/abc.t : 1] {block (2 levels) in }"
|
44
|
-
assert_format expected, path, lineno, cls, func
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_copy
|
48
|
-
fmt = Logue::Format.new line_width: 77
|
49
|
-
val = fmt.instance_eval "@line_width"
|
50
|
-
assert_equal 77, val
|
51
|
-
|
52
|
-
copy = fmt.copy method_width: 123
|
53
|
-
val = copy.instance_eval "@line_width"
|
54
|
-
assert_equal 77, val
|
55
|
-
|
56
|
-
val = copy.instance_eval "@method_width"
|
57
|
-
assert_equal 123, val
|
58
|
-
end
|
59
|
-
end
|
data/test/logue/log_test.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/log'
|
6
|
-
|
7
|
-
class Logue::LogTest < Test::Unit::TestCase
|
8
|
-
def assert_accessor_methods rdmeth, *values
|
9
|
-
wrmeth = (rdmeth.to_s + "=").to_sym
|
10
|
-
logger = Logue::Log.logger
|
11
|
-
values.each do |value|
|
12
|
-
Logue::Log.send wrmeth, value
|
13
|
-
|
14
|
-
assert_equal value, logger.send(rdmeth)
|
15
|
-
assert_equal value, Logue::Log.send(rdmeth)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def assert_read_method rdmeth, *values
|
20
|
-
values.each do |value|
|
21
|
-
Logue::Log.send rdmeth, *value
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_delegator_verbose
|
26
|
-
assert_accessor_methods :verbose, false, true
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_delegator_level
|
30
|
-
assert_accessor_methods :level, Logue::Log::Severity::FATAL, Logue::Log::Severity::INFO
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_delegator_quiet
|
34
|
-
assert_accessor_methods :quiet, true, false
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_delegator_format
|
38
|
-
# no logger.format method yet:
|
39
|
-
return if true
|
40
|
-
assert_accessor_methods :format, "abc", "def"
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_delegator_output
|
44
|
-
assert_accessor_methods :output, "abc", "def"
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_delegator_colorize_line
|
48
|
-
assert_accessor_methods :colorize_line, false, true
|
49
|
-
end
|
50
|
-
|
51
|
-
def assert_outfile_equals value
|
52
|
-
# is called, but converted from value to File.new(value)
|
53
|
-
Logue::Log.outfile = value
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_delegator_outfile
|
57
|
-
assert_outfile_equals "/tmp/logue_test_abc"
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_ignore_file
|
61
|
-
assert_read_method :ignore_file, true, false
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_ignore_method
|
65
|
-
assert_read_method :ignore_method, true, false
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_ignore_class
|
69
|
-
assert_read_method :ignore_class, true, false
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_log_file
|
73
|
-
assert_read_method :log_file, true, false
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_log_method
|
77
|
-
assert_read_method :log_method, true, false
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_log_class
|
81
|
-
assert_read_method :log_class, true, false
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_set_color
|
85
|
-
lvl = Logue::Log::Severity::FATAL
|
86
|
-
assert_read_method :set_color, [ lvl, :red ], [ lvl, :none ]
|
87
|
-
end
|
88
|
-
end
|
data/test/logue/loggable_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/loggable'
|
6
|
-
|
7
|
-
class LoggableTest < Test::Unit::TestCase
|
8
|
-
def test_respond_to_colors
|
9
|
-
obj = Object.new
|
10
|
-
obj.extend Logue::Loggable
|
11
|
-
|
12
|
-
# from rainbow/color:
|
13
|
-
|
14
|
-
colors = [
|
15
|
-
:black,
|
16
|
-
:red,
|
17
|
-
:green,
|
18
|
-
:yellow,
|
19
|
-
:blue,
|
20
|
-
:magenta,
|
21
|
-
:cyan,
|
22
|
-
:white,
|
23
|
-
:default
|
24
|
-
]
|
25
|
-
|
26
|
-
colors.each do |color|
|
27
|
-
assert_respond_to obj, color, "color: #{color}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# poor man's mock
|
32
|
-
class TestLogDelegate
|
33
|
-
class << self
|
34
|
-
attr_accessor :invoked
|
35
|
-
|
36
|
-
def method_missing meth, *args, &blk
|
37
|
-
@invoked = { name: meth, args: args }
|
38
|
-
end
|
39
|
-
|
40
|
-
def respond_to? meth, include_all = false
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_delegation
|
47
|
-
obj = Object.new
|
48
|
-
obj.extend Logue::Loggable
|
49
|
-
|
50
|
-
def obj.delegate_log_class
|
51
|
-
TestLogDelegate
|
52
|
-
end
|
53
|
-
|
54
|
-
delegate_methods = Array.new.tap do |ary|
|
55
|
-
ary << :log
|
56
|
-
ary << :debug
|
57
|
-
ary << :info
|
58
|
-
ary << :warn
|
59
|
-
ary << :error
|
60
|
-
ary << :fatal
|
61
|
-
ary << :stack
|
62
|
-
ary << :write
|
63
|
-
end
|
64
|
-
|
65
|
-
delegate_methods.each do |dmeth|
|
66
|
-
TestLogDelegate.invoked = nil
|
67
|
-
obj.send dmeth, "abc"
|
68
|
-
invoked = TestLogDelegate.invoked
|
69
|
-
assert_equal dmeth, invoked[:name], "method: #{dmeth}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/test/logue/logger_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/logger'
|
6
|
-
|
7
|
-
class LoggerTest < Test::Unit::TestCase
|
8
|
-
def test_default
|
9
|
-
logger = Logue::Logger.new
|
10
|
-
|
11
|
-
assert_equal Logue::Log::Severity::FATAL, $LOGGING_LEVEL
|
12
|
-
assert_equal Logue::Log::Severity::FATAL, logger.level
|
13
|
-
|
14
|
-
assert_equal false, logger.quiet
|
15
|
-
assert_equal $stdout, logger.output
|
16
|
-
assert_equal false, logger.colorize_line
|
17
|
-
|
18
|
-
assert_equal Hash.new, logger.ignored_files
|
19
|
-
assert_equal Hash.new, logger.ignored_methods
|
20
|
-
assert_equal Hash.new, logger.ignored_classes
|
21
|
-
assert_equal true, logger.trim
|
22
|
-
|
23
|
-
assert_equal false, logger.verbose
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_respond_to
|
27
|
-
logger = Logue::Logger.new
|
28
|
-
assert_equal true, logger.respond_to?(:blue)
|
29
|
-
end
|
30
|
-
end
|
data/test/logue/pathutil_test.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/pathutil'
|
6
|
-
|
7
|
-
class Logue::PathUtilTestCase < Test::Unit::TestCase
|
8
|
-
# trim_left
|
9
|
-
|
10
|
-
def run_trim_left_test expected, length, str = "something"
|
11
|
-
trimmed = Logue::PathUtil.trim_left str, length
|
12
|
-
assert_equal expected, trimmed
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_trim_left_short_positive_number
|
16
|
-
run_trim_left_test "some", 4
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_trim_left_long
|
20
|
-
run_trim_left_test "something", 10
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_trim_left_short_negative_number
|
24
|
-
run_trim_left_test "some", -4
|
25
|
-
end
|
26
|
-
|
27
|
-
# trim_right
|
28
|
-
|
29
|
-
def assert_trim_right expected, length, str
|
30
|
-
trimmed = Logue::PathUtil.trim_right str, length
|
31
|
-
assert_equal expected, trimmed, "length: #{length}"
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_trim_right_path_excess
|
35
|
-
assert_trim_right "ab/cd/ef.t", 11, "ab/cd/ef.t"
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_trim_right_path_at_length
|
39
|
-
assert_trim_right "ab/cd/ef.t", 10, "ab/cd/ef.t"
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_trim_right_path_one_less
|
43
|
-
assert_trim_right ".../ef.t", 9, "ab/cd/ef.t"
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_trim_right_path_two_less
|
47
|
-
assert_trim_right ".../ef.t", 8, "ab/cd/ef.t"
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_trim_right_path_three_less
|
51
|
-
assert_trim_right "ef.t", 7, "ab/cd/ef.t"
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_trim_right_path_four_less
|
55
|
-
assert_trim_right "ef.t", 6, "ab/cd/ef.t"
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_trim_right_path_five_less
|
59
|
-
assert_trim_right "ef.t", 5, "ab/cd/ef.t"
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_trim_right_path_six_less
|
63
|
-
assert_trim_right "ef.t", 4, "ab/cd/ef.t"
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_trim_right_path_seven_less
|
67
|
-
assert_trim_right "ef.t", 3, "ab/cd/ef.t"
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_trim_right_path_eight_less
|
71
|
-
assert_trim_right "ef.t", 2, "ab/cd/ef.t"
|
72
|
-
end
|
73
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'stringio'
|
7
|
-
require 'logue'
|
8
|
-
|
9
|
-
include Logue
|
10
|
-
|
11
|
-
class LogAbyss
|
12
|
-
include Loggable
|
13
|
-
|
14
|
-
def squeal
|
15
|
-
log "hello from the abyss"
|
16
|
-
stack "turtles all the way down"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class LogDepths
|
21
|
-
include Loggable
|
22
|
-
|
23
|
-
def speak
|
24
|
-
log "hello from the depths"
|
25
|
-
la = LogAbyss.new
|
26
|
-
la.squeal
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class LogInner
|
31
|
-
include Loggable
|
32
|
-
|
33
|
-
def screech
|
34
|
-
ldi = LogDepths.new
|
35
|
-
log "hello from the innerds"
|
36
|
-
ldi.speak
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class LogStackTestCase < Test::Unit::TestCase
|
41
|
-
include Loggable
|
42
|
-
|
43
|
-
def test_stack
|
44
|
-
Log.set_widths(-15, 4, -40)
|
45
|
-
|
46
|
-
log = Proc.new {
|
47
|
-
li = LogInner.new
|
48
|
-
li.screech
|
49
|
-
}
|
50
|
-
|
51
|
-
expected_output = [
|
52
|
-
"[log_stack_test.rb: 35] {LogInner#screech } hello from the innerds",
|
53
|
-
"[log_stack_test.rb: 24] {LogDepths#speak } hello from the depths",
|
54
|
-
"[log_stack_test.rb: 15] {LogAbyss#squeal } hello from the abyss",
|
55
|
-
"[log_stack_test.rb: 16] {LogAbyss#squeal } turtles all the way down",
|
56
|
-
"[log_stack_test.rb: 26] {speak } ",
|
57
|
-
"[log_stack_test.rb: 36] {screech } ",
|
58
|
-
]
|
59
|
-
|
60
|
-
do_run_test @verbose_setup, log, *expected_output
|
61
|
-
end
|
62
|
-
|
63
|
-
# the ctor is down here so the lines above are less likely to change.
|
64
|
-
def initialize test, name = nil
|
65
|
-
@nonverbose_setup = Proc.new {
|
66
|
-
Log.verbose = false
|
67
|
-
Log.output = StringIO.new
|
68
|
-
}
|
69
|
-
|
70
|
-
@verbose_setup = Proc.new {
|
71
|
-
Log.verbose = true
|
72
|
-
Log.output = StringIO.new
|
73
|
-
}
|
74
|
-
|
75
|
-
super test
|
76
|
-
end
|
77
|
-
|
78
|
-
def do_run_test setup, log, *expected
|
79
|
-
io = setup.call
|
80
|
-
|
81
|
-
log.call
|
82
|
-
|
83
|
-
assert_not_nil io
|
84
|
-
str = io.string
|
85
|
-
assert_not_nil str
|
86
|
-
|
87
|
-
lines = str.split "\n"
|
88
|
-
|
89
|
-
(0 ... expected.size).each do |idx|
|
90
|
-
if expected[idx]
|
91
|
-
assert_equal expected[idx], lines[idx], "index: #{idx}"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
Log.output = io
|
96
|
-
end
|
97
|
-
end
|
@@ -1,167 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'pathname'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'stringio'
|
7
|
-
require 'logue/loggable'
|
8
|
-
require 'logue/testlog/logtestee'
|
9
|
-
require 'logue/format'
|
10
|
-
|
11
|
-
include Logue
|
12
|
-
|
13
|
-
class LogTestCase < Test::Unit::TestCase
|
14
|
-
include Loggable
|
15
|
-
|
16
|
-
def run_log_testee_test(methname, expected, &blk)
|
17
|
-
Log.verbose = true
|
18
|
-
io = StringIO.new
|
19
|
-
Log.output = io
|
20
|
-
Log.set_default_widths
|
21
|
-
|
22
|
-
blk.call if blk
|
23
|
-
|
24
|
-
lt = LogTestee.new
|
25
|
-
lt.send methname
|
26
|
-
|
27
|
-
str = io.string
|
28
|
-
|
29
|
-
lines = str.split "\n"
|
30
|
-
|
31
|
-
(0 ... expected.size).each do |idx|
|
32
|
-
if expected[idx]
|
33
|
-
assert_equal expected[idx], lines[idx], "index: #{idx}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
Log.set_default_widths
|
38
|
-
end
|
39
|
-
|
40
|
-
def run_format_test(expected, &blk)
|
41
|
-
Log.verbose = true
|
42
|
-
io = StringIO.new
|
43
|
-
Log.output = io
|
44
|
-
Log.set_default_widths
|
45
|
-
|
46
|
-
blk.call
|
47
|
-
|
48
|
-
lt = LogTestee.new
|
49
|
-
lt.format_test
|
50
|
-
|
51
|
-
assert_equal expected.join(''), io.string
|
52
|
-
|
53
|
-
Log.set_default_widths
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_no_output
|
57
|
-
run_log_testee_test(:log_all, Array.new) do
|
58
|
-
Log.verbose = false
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def msg lnum, methname, msg
|
63
|
-
sprintf("[ .../testlog/logtestee.rb : %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_output_arg
|
67
|
-
methname = "log_all"
|
68
|
-
|
69
|
-
expected = Array.new
|
70
|
-
(1 .. 6).each do |lnum|
|
71
|
-
msg = "hello, world?"
|
72
|
-
if lnum == 4 || lnum == 5
|
73
|
-
msg = "EXPECTED OUTPUT TO STDERR: hello, world."
|
74
|
-
end
|
75
|
-
expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
|
76
|
-
end
|
77
|
-
|
78
|
-
run_log_testee_test(:log_all, expected)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_output_block_at_level
|
82
|
-
Log.level = Log::DEBUG
|
83
|
-
|
84
|
-
methname = "log_block"
|
85
|
-
|
86
|
-
msg = "block party"
|
87
|
-
|
88
|
-
expected = Array.new
|
89
|
-
expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 26, methname[0 .. 19], msg)
|
90
|
-
|
91
|
-
run_log_testee_test(:log_block, expected)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_output_block_below_level
|
95
|
-
expected = Array.new
|
96
|
-
|
97
|
-
run_log_testee_test(:log_block, expected) do
|
98
|
-
Log.level = Log::INFO
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_colors_foreground
|
103
|
-
methname = "log_foregrounds"
|
104
|
-
expected = Array.new
|
105
|
-
expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 30, methname[0 .. 19], "\e[37mwhite wedding\e[0m")
|
106
|
-
expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 31, methname[0 .. 19], "\e[34mblue iris\e[0m")
|
107
|
-
|
108
|
-
run_log_testee_test(:log_foregrounds, expected)
|
109
|
-
end
|
110
|
-
|
111
|
-
def xxxtest_colors_background
|
112
|
-
expected = Array.new
|
113
|
-
expected << "[.../test/logue/log_test.rb: 109] {LogTestCase#test_col} \e[46mred\e[0m"
|
114
|
-
|
115
|
-
run_log_testee_test(:log_foregrounds, expected) do
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_format_default
|
120
|
-
expected = Array.new
|
121
|
-
expected << "[.../testlog/logtestee.rb : 10] {format_test } tamrof\n"
|
122
|
-
|
123
|
-
run_format_test expected do
|
124
|
-
Log.set_default_widths
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_format_flush_filename_left
|
129
|
-
expected = Array.new
|
130
|
-
expected << "[.../test/logue/testlog/logtestee.rb: 10] {format_test } tamrof\n"
|
131
|
-
|
132
|
-
run_format_test expected do
|
133
|
-
Log.set_widths(-35, Logue::FormatWidths::DEFAULT_LINENUM, Logue::FormatWidths::DEFAULT_FUNCTION)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_format_flush_linenum_left
|
138
|
-
expected = Array.new
|
139
|
-
expected << "[.../testlog/logtestee.rb :10 ] {format_test } tamrof\n"
|
140
|
-
|
141
|
-
run_format_test expected do
|
142
|
-
Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, -10, Logue::FormatWidths::DEFAULT_FUNCTION)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_format_flush_function_right
|
147
|
-
expected = Array.new
|
148
|
-
expected << "[.../testlog/logtestee.rb : 10] { format_test} tamrof\n"
|
149
|
-
|
150
|
-
run_format_test expected do
|
151
|
-
Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, Logue::FormatWidths::DEFAULT_LINENUM, 35)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_format_pad_linenum_zeros
|
156
|
-
expected = Array.new
|
157
|
-
expected << "[.../testlog/logtestee.rb :00000010] {format_test } tamrof\n"
|
158
|
-
|
159
|
-
run_format_test expected do
|
160
|
-
Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, "08", Logue::FormatWidths::DEFAULT_FUNCTION)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_respond_to_color
|
165
|
-
assert Log.respond_to? :blue
|
166
|
-
end
|
167
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'stringio'
|
6
|
-
require 'logue/log'
|
7
|
-
require 'logue/loggable'
|
8
|
-
require 'logue/testlog/lgbl_testee'
|
9
|
-
|
10
|
-
class LoggableTestCase < Test::Unit::TestCase
|
11
|
-
include Logue::Loggable
|
12
|
-
|
13
|
-
def test_instance_colors
|
14
|
-
Logue::Log.verbose = true
|
15
|
-
io = StringIO.new
|
16
|
-
Logue::Log.output = io
|
17
|
-
|
18
|
-
expected = Array.new
|
19
|
-
expected << "[.../lgbl_testee.rb : 10] {LgblTestee#crystal } hello!\n"
|
20
|
-
expected << "[.../lgbl_testee.rb : 11] {LgblTestee#crystal } [34mazul ... [0m\n"
|
21
|
-
expected << "[.../lgbl_testee.rb : 12] {LgblTestee#crystal } [31mrojo?[0m\n"
|
22
|
-
|
23
|
-
te = LgblTestee.new
|
24
|
-
te.crystal
|
25
|
-
|
26
|
-
# puts io.string
|
27
|
-
|
28
|
-
assert_equal expected.join(''), io.string
|
29
|
-
end
|
30
|
-
end
|
data/test/logue/writer_test.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
# -*- ruby -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'logue/writer'
|
6
|
-
require 'logue/format'
|
7
|
-
require 'stringio'
|
8
|
-
|
9
|
-
class FakeLocation
|
10
|
-
attr_reader :absolute_path
|
11
|
-
attr_reader :lineno
|
12
|
-
attr_reader :label
|
13
|
-
# attr_reader :base_label
|
14
|
-
|
15
|
-
def initialize args
|
16
|
-
@absolute_path = args[:absolute_path]
|
17
|
-
@lineno = args[:lineno]
|
18
|
-
@label = args[:label]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class WriterTest < Test::Unit::TestCase
|
23
|
-
def test_write_one
|
24
|
-
fake_stack = Array.new.tap do |ary|
|
25
|
-
ary << FakeLocation.new(absolute_path: "/a/long/path/to/the/directory/abc.t", label: "block (2 levels) in one", lineno: 1)
|
26
|
-
ary << FakeLocation.new(absolute_path: "/another/path/def.t", label: "two", lineno: 11)
|
27
|
-
ary << FakeLocation.new(absolute_path: "/a/whole/nother/path/ghi.t", label: "three", lineno: 101)
|
28
|
-
end
|
29
|
-
|
30
|
-
fmt = Logue::Format.new
|
31
|
-
|
32
|
-
# content is matched in format_test
|
33
|
-
|
34
|
-
out, err = capture_io do
|
35
|
-
wr = Logue::Writer.new
|
36
|
-
wr.write fmt, fake_stack, 1
|
37
|
-
end
|
38
|
-
refute_empty out
|
39
|
-
assert_empty err
|
40
|
-
end
|
41
|
-
|
42
|
-
def capture_io
|
43
|
-
begin
|
44
|
-
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
45
|
-
|
46
|
-
orig_stdout, orig_stderr = $stdout, $stderr
|
47
|
-
$stdout, $stderr = captured_stdout, captured_stderr
|
48
|
-
|
49
|
-
yield
|
50
|
-
|
51
|
-
return captured_stdout.string, captured_stderr.string
|
52
|
-
ensure
|
53
|
-
$stdout = orig_stdout
|
54
|
-
$stderr = orig_stderr
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|