jekyll-logger-tap 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e72991f7e1e96c3e072ef9628035b6965e6d42770e186a817a8e89ff011745c
4
- data.tar.gz: ae1014594b9ea6b14d5baa8d4e0731b9031246d344441add49f2381669d5dbf2
3
+ metadata.gz: dabd346de26f90f60ea7429e2eb4c53837684c61eff99acd4f835a155b334265
4
+ data.tar.gz: 6ddb6f4c0af62a0e2951139d05903885806738139a2e130d138b8b8b45ff1ec8
5
5
  SHA512:
6
- metadata.gz: 03d38bccab4e6ac090f8b33ead7d1a05cfe723719feccae2cb94e277b82b929156c43e679c9e657c586612da5e7cbc7996b0c013c8386e5d0a3338f8ac2f4deb
7
- data.tar.gz: 279ee232090e7013df2070e00227dca6d1cfbbe5c61e7e6831a533181f09188341809cd56a0a8a98e101110144f5b53dbea8b81bce99a4fcdb13f56c272a5631
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
- ## v0.1.0 - 2023-10-02
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 -'.green,
16
- 'WARN' => 'not ok - Warning:'.yellow,
17
- 'ERROR' => 'not ok - Error:'.red,
18
- 'FATAL' => 'Bail out!'.red,
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
- "#{SEVERITY_FORMAT['DEBUG']} #{line}"
56
+ "#{tap_format(0)} #{line}"
37
57
  end.join
38
58
  else
39
- "#{SEVERITY_FORMAT[severity]} #{msg}"
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-logger-tap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f