logue 1.0.5 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
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
@@ -0,0 +1,72 @@
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
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,73 @@
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
@@ -49,12 +49,12 @@ class LogStackTestCase < Test::Unit::TestCase
49
49
  }
50
50
 
51
51
  expected_output = [
52
- "[ ...: 35] {LogInner#screech } hello from the innerds",
53
- "[ ...: 24] {LogDepths#speak } hello from the depths",
54
- "[ ...: 15] {LogAbyss#squeal } hello from the abyss",
55
- "[ ...: 16] {LogAbyss#squeal } turtles all the way down",
56
- "[ ...: 26] {speak } ",
57
- "[ ...: 36] {screech } ",
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
58
  ]
59
59
 
60
60
  do_run_test @verbose_setup, log, *expected_output
@@ -6,6 +6,7 @@ require 'test/unit'
6
6
  require 'stringio'
7
7
  require 'logue/loggable'
8
8
  require 'logue/testlog/logtestee'
9
+ require 'logue/format'
9
10
 
10
11
  include Logue
11
12
 
@@ -59,7 +60,7 @@ class LogTestCase < Test::Unit::TestCase
59
60
  end
60
61
 
61
62
  def msg lnum, methname, msg
62
- sprintf("[ ...testlog/logtestee.rb: %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
63
+ sprintf("[ .../testlog/logtestee.rb : %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
63
64
  end
64
65
 
65
66
  def test_output_arg
@@ -71,7 +72,7 @@ class LogTestCase < Test::Unit::TestCase
71
72
  if lnum == 4 || lnum == 5
72
73
  msg = "EXPECTED OUTPUT TO STDERR: hello, world."
73
74
  end
74
- expected << sprintf("[ ...testlog/logtestee.rb: %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
75
+ expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 16 + lnum, methname[0 .. 19], msg)
75
76
  end
76
77
 
77
78
  run_log_testee_test(:log_all, expected)
@@ -85,7 +86,7 @@ class LogTestCase < Test::Unit::TestCase
85
86
  msg = "block party"
86
87
 
87
88
  expected = Array.new
88
- expected << sprintf("[ ...testlog/logtestee.rb: %2d] {%-20s} %s", 26, methname[0 .. 19], msg)
89
+ expected << sprintf("[.../testlog/logtestee.rb : %2d] {%-20s} %s", 26, methname[0 .. 19], msg)
89
90
 
90
91
  run_log_testee_test(:log_block, expected)
91
92
  end
@@ -101,15 +102,15 @@ class LogTestCase < Test::Unit::TestCase
101
102
  def test_colors_foreground
102
103
  methname = "log_foregrounds"
103
104
  expected = Array.new
104
- expected << sprintf("[ ...testlog/logtestee.rb: %2d] {%-20s} %s", 30, methname[0 .. 19], "\e[37mwhite wedding\e[0m")
105
- expected << sprintf("[ ...testlog/logtestee.rb: %2d] {%-20s} %s", 31, methname[0 .. 19], "\e[34mblue iris\e[0m")
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")
106
107
 
107
108
  run_log_testee_test(:log_foregrounds, expected)
108
109
  end
109
110
 
110
111
  def xxxtest_colors_background
111
112
  expected = Array.new
112
- expected << "[ ...test/logue/log_test.rb: 109] {LogTestCase#test_col} \e[46mred\e[0m"
113
+ expected << "[.../test/logue/log_test.rb: 109] {LogTestCase#test_col} \e[46mred\e[0m"
113
114
 
114
115
  run_log_testee_test(:log_foregrounds, expected) do
115
116
  end
@@ -117,7 +118,7 @@ class LogTestCase < Test::Unit::TestCase
117
118
 
118
119
  def test_format_default
119
120
  expected = Array.new
120
- expected << "[ ...testlog/logtestee.rb: 10] {format_test } tamrof\n"
121
+ expected << "[.../testlog/logtestee.rb : 10] {format_test } tamrof\n"
121
122
 
122
123
  run_format_test expected do
123
124
  Log.set_default_widths
@@ -126,37 +127,37 @@ class LogTestCase < Test::Unit::TestCase
126
127
 
127
128
  def test_format_flush_filename_left
128
129
  expected = Array.new
129
- expected << "[ ...test/logue/testlog/logtestee.rb: 10] {format_test } tamrof\n"
130
+ expected << "[.../test/logue/testlog/logtestee.rb: 10] {format_test } tamrof\n"
130
131
 
131
132
  run_format_test expected do
132
- Log.set_widths(-35, Log::DEFAULT_LINENUM_WIDTH, Log::DEFAULT_FUNCTION_WIDTH)
133
+ Log.set_widths(-35, Logue::FormatWidths::DEFAULT_LINENUM, Logue::FormatWidths::DEFAULT_FUNCTION)
133
134
  end
134
135
  end
135
136
 
136
137
  def test_format_flush_linenum_left
137
138
  expected = Array.new
138
- expected << "[ ...testlog/logtestee.rb:10 ] {format_test } tamrof\n"
139
+ expected << "[.../testlog/logtestee.rb :10 ] {format_test } tamrof\n"
139
140
 
140
141
  run_format_test expected do
141
- Log.set_widths(Log::DEFAULT_FILENAME_WIDTH, -10, Log::DEFAULT_FUNCTION_WIDTH)
142
+ Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, -10, Logue::FormatWidths::DEFAULT_FUNCTION)
142
143
  end
143
144
  end
144
145
 
145
146
  def test_format_flush_function_right
146
147
  expected = Array.new
147
- expected << "[ ...testlog/logtestee.rb: 10] { format_test} tamrof\n"
148
+ expected << "[.../testlog/logtestee.rb : 10] { format_test} tamrof\n"
148
149
 
149
150
  run_format_test expected do
150
- Log.set_widths(Log::DEFAULT_FILENAME_WIDTH, Log::DEFAULT_LINENUM_WIDTH, 35)
151
+ Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, Logue::FormatWidths::DEFAULT_LINENUM, 35)
151
152
  end
152
153
  end
153
154
 
154
155
  def test_format_pad_linenum_zeros
155
156
  expected = Array.new
156
- expected << "[ ...testlog/logtestee.rb:00000010] {format_test } tamrof\n"
157
+ expected << "[.../testlog/logtestee.rb :00000010] {format_test } tamrof\n"
157
158
 
158
159
  run_format_test expected do
159
- Log.set_widths(Log::DEFAULT_FILENAME_WIDTH, "08", Log::DEFAULT_FUNCTION_WIDTH)
160
+ Log.set_widths(Logue::FormatWidths::DEFAULT_FILENAME, "08", Logue::FormatWidths::DEFAULT_FUNCTION)
160
161
  end
161
162
  end
162
163
 
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- require 'pathname'
5
4
  require 'test/unit'
6
5
  require 'stringio'
7
6
  require 'logue/log'
@@ -17,9 +16,9 @@ class LoggableTestCase < Test::Unit::TestCase
17
16
  Logue::Log.output = io
18
17
 
19
18
  expected = Array.new
20
- expected << "[...testlog/lgbl_testee.rb: 10] {LgblTestee#crystal } hello!\n"
21
- expected << "[...testlog/lgbl_testee.rb: 11] {LgblTestee#crystal } azul ... \n"
22
- expected << "[...testlog/lgbl_testee.rb: 12] {LgblTestee#crystal } rojo?\n"
19
+ expected << "[.../lgbl_testee.rb : 10] {LgblTestee#crystal } hello!\n"
20
+ expected << "[.../lgbl_testee.rb : 11] {LgblTestee#crystal } azul ... \n"
21
+ expected << "[.../lgbl_testee.rb : 12] {LgblTestee#crystal } rojo?\n"
23
22
 
24
23
  te = LgblTestee.new
25
24
  te.crystal
@@ -0,0 +1,57 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logue
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -31,7 +31,7 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
33
  description: A module that adds logging/trace functionality.
34
- email: jeugenepace@gmail.com
34
+ email: jpace317@gmail.com
35
35
  executables: []
36
36
  extensions: []
37
37
  extra_rdoc_files:
@@ -44,12 +44,20 @@ files:
44
44
  - lib/logue/log.rb
45
45
  - lib/logue/loggable.rb
46
46
  - lib/logue/logger.rb
47
+ - lib/logue/pathutil.rb
47
48
  - lib/logue/severity.rb
49
+ - lib/logue/writer.rb
50
+ - test/logue/colors_test.rb
48
51
  - test/logue/format_test.rb
52
+ - test/logue/log_test.rb
53
+ - test/logue/loggable_test.rb
54
+ - test/logue/logger_test.rb
55
+ - test/logue/pathutil_test.rb
49
56
  - test/logue/testlog/log_stack_test.rb
50
57
  - test/logue/testlog/log_test.rb
51
58
  - test/logue/testlog/loggable_test.rb
52
- homepage: http://jeugenepace.github.com/logue
59
+ - test/logue/writer_test.rb
60
+ homepage: http://jpace.github.com/logue
53
61
  licenses:
54
62
  - MIT
55
63
  metadata: {}
@@ -69,12 +77,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
77
  version: '0'
70
78
  requirements: []
71
79
  rubyforge_project:
72
- rubygems_version: 2.5.1
80
+ rubygems_version: 2.6.3
73
81
  signing_key:
74
82
  specification_version: 4
75
83
  summary: A minimalist logging module.
76
84
  test_files:
85
+ - test/logue/colors_test.rb
77
86
  - test/logue/format_test.rb
87
+ - test/logue/log_test.rb
88
+ - test/logue/loggable_test.rb
89
+ - test/logue/logger_test.rb
90
+ - test/logue/pathutil_test.rb
78
91
  - test/logue/testlog/log_stack_test.rb
79
92
  - test/logue/testlog/log_test.rb
80
93
  - test/logue/testlog/loggable_test.rb
94
+ - test/logue/writer_test.rb