utils 0.33.1 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50ec7fbc2ce6a3e39c4a2ef629e37232bf60ddf491bf3adfcc1ec29d18358f2f
4
- data.tar.gz: e5a8b2edef42e1e00a91a88e46078696ec216c0a25032ff6ac17d030e9e75495
3
+ metadata.gz: 7555fc93b044b6664d90d4e459d730a2f0027ba4a266af8577ac972163a91710
4
+ data.tar.gz: 5c22e9f713f59a2e2cedf64eb0e44746bd86ebd5aa40ea38a88f11524ce53ff7
5
5
  SHA512:
6
- metadata.gz: 3f4648b04e39732a399a49c581aec427178ac17ae6ca3d48e84a76bed45301f61f108848ec08bcdcedb650613406de569173333e0aa8f49711062775f8ee0b70
7
- data.tar.gz: bca088a6c8cd4226358a70563eff3f5febd7c80057bb277fa97404a0ef3992e2e9be1d8ec63d24093e8de1a85eb0ad1bf4f2607f38f07ecca2be8501fbcf10a7
6
+ metadata.gz: 307f459fab4c993a09590af3b2b4de2a8e1ec263a40085685a95721374c36da8107a0d9a1bdb3ab15c9b8707b46a1ab45bbb1909d6046958a14cbf31c7489214
7
+ data.tar.gz: 520ca2fa9e534f9341a565c424ab2ba1d7549e72586500cdf2bd41a1c993d4ecbfbd84d8f86b038a0171158bd5a93be268201ce5b35037d8e031bf5c6eaf6bdb
data/bin/probe CHANGED
@@ -5,6 +5,10 @@ require 'tins/xt'
5
5
  require 'tins/lines_file'
6
6
  include Tins::GO
7
7
  require 'utils'
8
+ begin
9
+ require 'utils/line_formatter'
10
+ rescue LoadError
11
+ end
8
12
  include Utils
9
13
  require 'drb'
10
14
 
data/lib/utils/irb.rb CHANGED
@@ -336,31 +336,17 @@ module Utils
336
336
  STDERR.puts "Loaded '#{f}'."
337
337
  end
338
338
  end
339
- Find.find('.') do |f|
340
- File.directory?(f) and next
341
- md5_f = Utils::MD5.md5(f)
342
- if f.end_with?(file) and !loaded[md5_f]
343
- Kernel.load f
344
- loaded[md5_f] = true
345
- STDERR.puts "Loaded '#{f}'."
346
- end
347
- end
348
339
  end
349
340
  end
350
341
  nil
351
342
  end
352
343
 
353
- def irb_edit(*files)
354
- $editor.full?(:edit, *files)
355
- end
356
-
357
- def edit
358
- $editor.full?(:edit, self)
359
- end
360
-
361
- # List contents of directory
362
- def ls(*args)
363
- puts `ls #{args.map { |x| "'#{x}'" } * ' '}`
344
+ def ed(*files)
345
+ if files.empty?
346
+ $editor.full?(:edit, self)
347
+ else
348
+ $editor.full?(:edit, *files)
349
+ end
364
350
  end
365
351
 
366
352
  if defined?(ActiveRecord::Base)
@@ -9,164 +9,164 @@ rescue LoadError => e
9
9
  else
10
10
  module Utils
11
11
  class LineFormatter
12
- ::RSpec::Core::Formatters.register self, :start, :close,
13
- :example_passed, :example_pending, :example_failed, :dump_summary
14
-
15
- def initialize(output)
16
- @output = output
17
- @output.sync = true
18
- filename = 'errors.lst'
19
- @errors_lst = File.new(filename, 'w')
20
- @errors_lst.sync = true
21
- end
22
-
23
- attr_reader :output
24
-
25
- def start(_ignore)
26
- output.puts "Storing error list in #{@errors_lst.path.inspect}: "
27
- output.puts ?- * Tins::Terminal.columns
28
- end
29
-
30
- def close(_ignore)
31
- @errors_lst.close
32
- end
33
-
34
- def dump_summary(summary)
35
- line = summary_line(summary)
36
- @errors_lst.puts ?= * 80, line
37
- output.puts ?= * Tins::Terminal.columns, line
38
- end
39
-
40
- def example_passed(example)
41
- output.puts format_line(example)
42
- end
43
-
44
- def example_pending(example)
45
- output.puts format_line(example)
46
- end
47
-
48
- def example_failed(example)
49
- dump_failure_to_error_file(example)
50
- output.puts format_line(example)
51
- dump_failure(example)
52
- end
53
-
54
- private
55
-
56
- def summary_line(summary)
57
- failure_percentage = 100 * summary.failure_count.to_f / summary.example_count
58
- failure_percentage.nan? and failure_percentage = 0.0
59
- pending_percentage = 100 * summary.pending_count.to_f / summary.example_count
60
- pending_percentage.nan? and pending_percentage = 0.0
61
- "%u of %u (%.2f %%) failed, %u pending (%.2f %%) in %.3f seconds" % [
62
- summary.failure_count,
63
- summary.example_count,
64
- failure_percentage,
65
- summary.pending_count,
66
- pending_percentage,
67
- summary.duration,
68
- ]
69
- end
70
-
71
- def dump_failure(example)
72
- output.puts(
73
- description(example, full: true),
74
- dump_failure_for_example(example)
75
- )
76
- end
77
-
78
- def read_failed_line(example)
79
- ''.strip
80
- end
81
-
82
- def dump_failure_for_example(example)
83
- result = ''
84
- exception = execution_result(example).exception
85
- exception_class_name = exception.class.name
86
- result << "Failure/Error: #{read_failed_line(example)}\n"
87
- result << "#{exception_class_name}:\n" unless exception_class_name =~ /RSpec/
88
- if m = exception.message
89
- m.to_s.split("\n").each { |line| result << " #{line}\n" }
90
- end
91
- result
92
- end
93
-
94
- def format_backtrace(example, folding: false, limit: nil)
95
- backtrace = execution_result(example).exception.backtrace
96
- backtrace.nil? and return ''
97
- if limit
98
- backtrace = backtrace[0, limit]
99
- end
100
- result = []
101
- folding and result << '{{{'
102
- for line in backtrace
103
- result << RSpec::Core::Metadata::relative_path(line)
104
- end
105
- folding and result << '}}}'
106
- result * ?\n
107
- end
108
-
109
- def dump_failure_to_error_file(example)
110
- @errors_lst.flock File::LOCK_EX
111
- @errors_lst.puts "%s\n%3.3fs %s\n%s\n%s" % [
112
- location(example), run_time(example), description(example, full: true),
113
- dump_failure_for_example(example), format_backtrace(example, folding: true)
114
- ]
115
- ensure
116
- @errors_lst.flock File::LOCK_UN
117
- end
118
-
119
- def execution_result(example)
120
- example.example.metadata[:execution_result]
121
- end
122
-
123
- def description(example, full: ENV['VERBOSE'].to_i == 1)
124
- if full
125
- example.example.full_description
126
- else
127
- example.example.description
128
- end
129
- end
130
-
131
- def run_time(example)
132
- execution_result(example).run_time
133
- end
134
-
135
- def format_line(example)
136
- args = [ location(example), run_time(example), description(example) ]
137
- uncolored = "%s # S %3.3fs %s" % args
138
- uncolored = uncolored[0, Tins::Terminal.columns]
139
- case execution_result(example).status
140
- when :passed
141
- success_color(uncolored)
142
- when :failed
143
- failure_color(uncolored)
144
- when :pending
145
- pending_color(uncolored)
146
- else
147
- uncolored % args
148
- end
149
- end
150
-
151
- def success_color(text)
152
- Term::ANSIColor.green(text)
153
- end
154
-
155
- def failure_color(text)
156
- Term::ANSIColor.red(text)
157
- end
158
-
159
- def pending_color(text)
160
- Term::ANSIColor.yellow(text)
161
- end
162
-
163
- def location(example)
164
- location = example.example.metadata[:location]
165
- unless location.include?(?/)
166
- location = example.example.metadata[:example_group][:location]
167
- end
168
- RSpec::Core::Metadata::relative_path(location)
169
- end
12
+ ::RSpec::Core::Formatters.register self, :start, :close,
13
+ :example_passed, :example_pending, :example_failed, :dump_summary
14
+
15
+ def initialize(output)
16
+ @output = output
17
+ @output.sync = true
18
+ filename = 'errors.lst'
19
+ @errors_lst = File.new(filename, 'w')
20
+ @errors_lst.sync = true
21
+ end
22
+
23
+ attr_reader :output
24
+
25
+ def start(_ignore)
26
+ output.puts "Storing error list in #{@errors_lst.path.inspect}: "
27
+ output.puts ?- * Tins::Terminal.columns
28
+ end
29
+
30
+ def close(_ignore)
31
+ @errors_lst.close
32
+ end
33
+
34
+ def dump_summary(summary)
35
+ line = summary_line(summary)
36
+ @errors_lst.puts ?= * 80, line
37
+ output.puts ?= * Tins::Terminal.columns, line
38
+ end
39
+
40
+ def example_passed(example)
41
+ output.puts format_line(example)
42
+ end
43
+
44
+ def example_pending(example)
45
+ output.puts format_line(example)
46
+ end
47
+
48
+ def example_failed(example)
49
+ dump_failure_to_error_file(example)
50
+ output.puts format_line(example)
51
+ dump_failure(example)
52
+ end
53
+
54
+ private
55
+
56
+ def summary_line(summary)
57
+ failure_percentage = 100 * summary.failure_count.to_f / summary.example_count
58
+ failure_percentage.nan? and failure_percentage = 0.0
59
+ pending_percentage = 100 * summary.pending_count.to_f / summary.example_count
60
+ pending_percentage.nan? and pending_percentage = 0.0
61
+ "%u of %u (%.2f %%) failed, %u pending (%.2f %%) in %.3f seconds" % [
62
+ summary.failure_count,
63
+ summary.example_count,
64
+ failure_percentage,
65
+ summary.pending_count,
66
+ pending_percentage,
67
+ summary.duration,
68
+ ]
69
+ end
70
+
71
+ def dump_failure(example)
72
+ output.puts(
73
+ description(example, full: true),
74
+ dump_failure_for_example(example)
75
+ )
76
+ end
77
+
78
+ def read_failed_line(example)
79
+ ''.strip
80
+ end
81
+
82
+ def dump_failure_for_example(example)
83
+ result = ''
84
+ exception = execution_result(example).exception
85
+ exception_class_name = exception.class.name
86
+ result << "Failure/Error: #{read_failed_line(example)}\n"
87
+ result << "#{exception_class_name}:\n" unless exception_class_name =~ /RSpec/
88
+ if m = exception.message
89
+ m.to_s.split("\n").each { |line| result << " #{line}\n" }
90
+ end
91
+ result
92
+ end
93
+
94
+ def format_backtrace(example, folding: false, limit: nil)
95
+ backtrace = execution_result(example).exception.backtrace
96
+ backtrace.nil? and return ''
97
+ if limit
98
+ backtrace = backtrace[0, limit]
99
+ end
100
+ result = []
101
+ folding and result << '{{{'
102
+ for line in backtrace
103
+ result << RSpec::Core::Metadata::relative_path(line)
104
+ end
105
+ folding and result << '}}}'
106
+ result * ?\n
107
+ end
108
+
109
+ def dump_failure_to_error_file(example)
110
+ @errors_lst.flock File::LOCK_EX
111
+ @errors_lst.puts "%s\n%3.3fs %s\n%s\n%s" % [
112
+ location(example), run_time(example), description(example, full: true),
113
+ dump_failure_for_example(example), format_backtrace(example, folding: true)
114
+ ]
115
+ ensure
116
+ @errors_lst.flock File::LOCK_UN
117
+ end
118
+
119
+ def execution_result(example)
120
+ example.example.metadata[:execution_result]
121
+ end
122
+
123
+ def description(example, full: ENV['VERBOSE'].to_i == 1)
124
+ if full
125
+ example.example.full_description
126
+ else
127
+ example.example.description
128
+ end
129
+ end
130
+
131
+ def run_time(example)
132
+ execution_result(example).run_time
133
+ end
134
+
135
+ def format_line(example)
136
+ args = [ location(example), run_time(example), description(example) ]
137
+ uncolored = "%s # S %3.3fs %s" % args
138
+ uncolored = uncolored[0, Tins::Terminal.columns]
139
+ case execution_result(example).status
140
+ when :passed
141
+ success_color(uncolored)
142
+ when :failed
143
+ failure_color(uncolored)
144
+ when :pending
145
+ pending_color(uncolored)
146
+ else
147
+ uncolored % args
148
+ end
149
+ end
150
+
151
+ def success_color(text)
152
+ Term::ANSIColor.green(text)
153
+ end
154
+
155
+ def failure_color(text)
156
+ Term::ANSIColor.red(text)
157
+ end
158
+
159
+ def pending_color(text)
160
+ Term::ANSIColor.yellow(text)
161
+ end
162
+
163
+ def location(example)
164
+ location = example.example.metadata[:location]
165
+ unless location.include?(?/)
166
+ location = example.example.metadata[:example_group][:location]
167
+ end
168
+ RSpec::Core::Metadata::relative_path(location)
169
+ end
170
170
  end
171
171
  end
172
172
  end
data/lib/utils/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Utils
2
2
  # Utils version
3
- VERSION = '0.33.1'
3
+ VERSION = '0.34.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/utils.rb CHANGED
@@ -10,10 +10,6 @@ module Utils
10
10
  require 'utils/probe_server'
11
11
  require 'utils/ssh_tunnel_specification'
12
12
  require 'utils/line_blamer'
13
- begin
14
- require 'utils/line_formatter'
15
- rescue LoadError
16
- end
17
13
 
18
14
  require 'utils/xt/source_location_extension'
19
15
  class ::Object
data/utils.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: utils 0.33.1 ruby lib
2
+ # stub: utils 0.34.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "utils".freeze
6
- s.version = "0.33.1"
6
+ s.version = "0.34.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2022-12-17"
11
+ s.date = "2023-01-05"
12
12
  s.description = "This ruby gem provides some useful command line utilities".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ascii7".freeze, "blameline".freeze, "check-yaml".freeze, "classify".freeze, "create_cstags".freeze, "create_tags".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "fix-brew".freeze, "git-empty".freeze, "git-versions".freeze, "irb_connect".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "number_files".freeze, "on_change".freeze, "path".freeze, "probe".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.1
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-17 00:00:00.000000000 Z
11
+ date: 2023-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar