jekyll-logger-tap 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/jekyll/log_adapters/tap.rb +65 -6
- data/lib/jekyll-logger-tap.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dabd346de26f90f60ea7429e2eb4c53837684c61eff99acd4f835a155b334265
|
4
|
+
data.tar.gz: 6ddb6f4c0af62a0e2951139d05903885806738139a2e130d138b8b8b45ff1ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce49f25cebdcefd82619a8aeb0cdd733b83ad4350f92f889cb54e5238cd95de477ca47257ea630b94a27bc22d71d974c1737082208802c15c71486f6fd953cc2
|
7
|
+
data.tar.gz: 7b534424d49e17ef4711c9764d73a748975759c4e43c89a5d0f722ac8040a2d89106e480b82a31e46569fe104055f204b19af7290b3c32ffbe8ff6281c82e668
|
data/CHANGELOG.md
CHANGED
@@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
##
|
8
|
+
## [0.2.0] - 2023-10-02
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Color is removed when the output is piped
|
13
|
+
- Add TAP version header
|
14
|
+
- Print test plan at the end
|
15
|
+
|
16
|
+
## [0.1.0] - 2023-10-02
|
9
17
|
|
10
18
|
### Added
|
11
19
|
|
@@ -10,15 +10,30 @@ module Jekyll
|
|
10
10
|
class Logger < Jekyll::Stevenson
|
11
11
|
# TAP doesn't have that many levels, so we differentiate errors
|
12
12
|
# from warnings by color and prefix.
|
13
|
+
#
|
14
|
+
# @see Logger::Severity
|
13
15
|
SEVERITY_FORMAT = {
|
14
16
|
'DEBUG' => '#',
|
15
|
-
'INFO' => 'ok -'
|
16
|
-
'WARN' => 'not ok - Warning:'
|
17
|
-
'ERROR' => 'not ok - Error:'
|
18
|
-
'FATAL' => 'Bail out!'
|
17
|
+
'INFO' => 'ok -',
|
18
|
+
'WARN' => 'not ok - Warning:',
|
19
|
+
'ERROR' => 'not ok - Error:',
|
20
|
+
'FATAL' => 'Bail out!',
|
19
21
|
'ANY' => ''
|
20
22
|
}
|
21
23
|
|
24
|
+
SEVERITY_COLOR = {
|
25
|
+
'DEBUG' => [],
|
26
|
+
'INFO' => %i[green],
|
27
|
+
'WARN' => %i[yellow],
|
28
|
+
'ERROR' => %i[red],
|
29
|
+
'FATAL' => %i[red bold],
|
30
|
+
'ANY' => []
|
31
|
+
}
|
32
|
+
|
33
|
+
COUNT_TESTS = (1..3)
|
34
|
+
|
35
|
+
attr_reader :test_counter
|
36
|
+
|
22
37
|
# Replace the formatter with a proc
|
23
38
|
#
|
24
39
|
# Multi-line messages are assumed to be debug level, like the
|
@@ -26,6 +41,11 @@ module Jekyll
|
|
26
41
|
def initialize
|
27
42
|
super
|
28
43
|
|
44
|
+
logdevice(1).puts('TAP version 14')
|
45
|
+
|
46
|
+
# Initialize counter
|
47
|
+
@test_counter = 0
|
48
|
+
# At this point, severity is an Integer
|
29
49
|
@formatter = proc do |severity, _, _, msg|
|
30
50
|
msg = msg.to_s.strip_ansi.strip
|
31
51
|
|
@@ -33,13 +53,52 @@ module Jekyll
|
|
33
53
|
|
34
54
|
if msg.lines.size > 1
|
35
55
|
msg.lines.map do |line|
|
36
|
-
"#{
|
56
|
+
"#{tap_format(0)} #{line}"
|
37
57
|
end.join
|
38
58
|
else
|
39
|
-
"#{
|
59
|
+
"#{tap_format(severity)} #{msg}"
|
40
60
|
end
|
41
61
|
end
|
42
62
|
end
|
63
|
+
|
64
|
+
def close
|
65
|
+
logdevice(0).puts("1..#{@test_counter}")
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
# Don't convert severity level to string
|
71
|
+
#
|
72
|
+
# @see Logger#format_severity
|
73
|
+
# @return [Integer]
|
74
|
+
def format_severity(severity)
|
75
|
+
severity
|
76
|
+
end
|
77
|
+
|
78
|
+
# Test if logdevice is a TTY
|
79
|
+
#
|
80
|
+
# @param :severity [Integer]
|
81
|
+
def tty?(severity)
|
82
|
+
!!logdevice(severity)&.isatty
|
83
|
+
end
|
84
|
+
|
85
|
+
# At this point, severity is an Integer. Skips colorizing if it
|
86
|
+
# detects we're piping output.
|
87
|
+
#
|
88
|
+
# @param :severity [Integer]
|
89
|
+
# @return [String]
|
90
|
+
def tap_format(severity)
|
91
|
+
@test_counter += 1 if COUNT_TESTS.include? severity
|
92
|
+
tap_formatted = SEVERITY_FORMAT.values[severity]
|
93
|
+
|
94
|
+
return tap_formatted unless tty?(severity)
|
95
|
+
|
96
|
+
colors = SEVERITY_COLOR.values[severity]
|
97
|
+
|
98
|
+
colors.reduce(tap_formatted) do |aggregated, color|
|
99
|
+
aggregated.public_send(color)
|
100
|
+
end
|
101
|
+
end
|
43
102
|
end
|
44
103
|
end
|
45
104
|
end
|
data/lib/jekyll-logger-tap.rb
CHANGED
@@ -3,3 +3,13 @@
|
|
3
3
|
require_relative 'jekyll/log_adapters/tap'
|
4
4
|
|
5
5
|
Jekyll.logger = Jekyll::LogAdapters::Tap::Logger.new
|
6
|
+
|
7
|
+
module JekyllCommandDecorator
|
8
|
+
def process_with_graceful_fail(cmd, options, *klass)
|
9
|
+
super
|
10
|
+
ensure
|
11
|
+
Jekyll.logger.instance_variable_get(:@writer).close
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Jekyll::Command.singleton_class.prepend JekyllCommandDecorator
|