wile 0.9.261203
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 +7 -0
- data/.version +1 -0
- data/CREDITS.md +20 -0
- data/README.md +253 -0
- data/bin/wile +102 -0
- data/cache/.bin/pane +99 -0
- data/cache/.bin/panes +54 -0
- data/cache/.config.fish +2 -0
- data/cache/.dictionary +0 -0
- data/cache/.gemignore +16 -0
- data/cache/.gitignore +9 -0
- data/cache/.greeting.erb +1 -0
- data/cache/.irbrc +30 -0
- data/cache/.lexicon +0 -0
- data/cache/.prompt.erb +1 -0
- data/cache/.reek-strict.yml +1 -0
- data/cache/.reek.yml +1 -0
- data/cache/.rubocop-strict.yml +4 -0
- data/cache/.rubocop.yml +4 -0
- data/cache/.ruby-version-floor +1 -0
- data/cache/.ruby-version.erb +1 -0
- data/cache/.solargraph.yml +21 -0
- data/cache/.title.erb +1 -0
- data/cache/.version +1 -0
- data/cache/.wile/example.rb +56 -0
- data/cache/.wileignore +3 -0
- data/cache/CREDITS.md +10 -0
- data/cache/Gemfile +5 -0
- data/cache/Gemfile.lock +1 -0
- data/cache/History.txt +0 -0
- data/cache/README.md.erb +54 -0
- data/cache/TODO.md +3 -0
- data/cache/bin/project.erb +12 -0
- data/cache/cucumber.yml +1 -0
- data/cache/examples/README.md +3 -0
- data/cache/features/help.feature.erb +30 -0
- data/cache/features/step_definitions/command_steps.rb +171 -0
- data/cache/features/support/env.rb +11 -0
- data/cache/features/version.feature.erb +19 -0
- data/cache/git/hooks/pre-commit +93 -0
- data/cache/lib/project.rb.erb +4 -0
- data/cache/man/project.md.erb +24 -0
- data/cache/pkg/README.md +3 -0
- data/cache/test/cons.gz +0 -0
- data/cache/test/tc_comments +216 -0
- data/cache/test/tc_cucumber_slow +67 -0
- data/cache/test/tc_dependency_scrapes +126 -0
- data/cache/test/tc_dictionary +51 -0
- data/cache/test/tc_encoding +53 -0
- data/cache/test/tc_lexicon +34 -0
- data/cache/test/tc_lib_tests +37 -0
- data/cache/test/tc_lints +71 -0
- data/cache/test/tc_readme_rocket_check +128 -0
- data/cache/test/tc_reek +20 -0
- data/cache/test/tc_rubocop +20 -0
- data/cache/test/tc_ruby_syntax +28 -0
- data/cache/test/tc_tags +32 -0
- data/cache/test/tc_tasks_test +31 -0
- data/cache/test/tc_version +97 -0
- data/cache/test/tc_weird_filenames +23 -0
- data/cache/test/test_helper.rb +230 -0
- data/cache/tmp/README.md +8 -0
- data/data/command_version.tsv +281 -0
- data/dependencies.txt +70 -0
- data/lib/wile/autoloads/cache.rb +123 -0
- data/lib/wile/autoloads/code_content.rb +225 -0
- data/lib/wile/autoloads/code_data.rb +153 -0
- data/lib/wile/autoloads/code_data_function.rb +79 -0
- data/lib/wile/autoloads/code_data_valuation.rb +60 -0
- data/lib/wile/autoloads/code_stats.rb +185 -0
- data/lib/wile/autoloads/command_version.rb +119 -0
- data/lib/wile/autoloads/content.rb +196 -0
- data/lib/wile/autoloads/dependencies.rb +170 -0
- data/lib/wile/autoloads/gem_utils.rb +69 -0
- data/lib/wile/autoloads/gemspec.rb +163 -0
- data/lib/wile/autoloads/git.rb +59 -0
- data/lib/wile/autoloads/info.rb +91 -0
- data/lib/wile/autoloads/manpage.rb +44 -0
- data/lib/wile/autoloads/methods.rb +130 -0
- data/lib/wile/autoloads/nvim_files.rb +54 -0
- data/lib/wile/autoloads/options_dictionary.rb +345 -0
- data/lib/wile/autoloads/order_optimizer.rb +185 -0
- data/lib/wile/autoloads/project.rb +60 -0
- data/lib/wile/autoloads/readme.rb +137 -0
- data/lib/wile/autoloads/receivers.rb +101 -0
- data/lib/wile/autoloads/responds.rb +36 -0
- data/lib/wile/autoloads/test.rb +78 -0
- data/lib/wile/autoloads/thread_pool.rb +64 -0
- data/lib/wile/help.rb +41 -0
- data/lib/wile/requires.rb +7 -0
- data/lib/wile/run.rb +108 -0
- data/lib/wile/sysexits.rb +43 -0
- data/lib/wile/tasks/build.rb +46 -0
- data/lib/wile/tasks/bump.rb +61 -0
- data/lib/wile/tasks/compare.rb +139 -0
- data/lib/wile/tasks/content.rb +44 -0
- data/lib/wile/tasks/cp.rb +52 -0
- data/lib/wile/tasks/dependencies.rb +58 -0
- data/lib/wile/tasks/dictionary.rb +59 -0
- data/lib/wile/tasks/gemcheck.rb +142 -0
- data/lib/wile/tasks/gemfile.rb +60 -0
- data/lib/wile/tasks/help.rb +29 -0
- data/lib/wile/tasks/info.rb +77 -0
- data/lib/wile/tasks/install.rb +53 -0
- data/lib/wile/tasks/lexicon.rb +59 -0
- data/lib/wile/tasks/list.rb +97 -0
- data/lib/wile/tasks/methods.rb +154 -0
- data/lib/wile/tasks/mkdir.rb +19 -0
- data/lib/wile/tasks/note.rb +49 -0
- data/lib/wile/tasks/nvim.rb +60 -0
- data/lib/wile/tasks/order.rb +93 -0
- data/lib/wile/tasks/oscheck.rb +49 -0
- data/lib/wile/tasks/publish.rb +67 -0
- data/lib/wile/tasks/receivers.rb +34 -0
- data/lib/wile/tasks/review.rb +157 -0
- data/lib/wile/tasks/ruby.rb +38 -0
- data/lib/wile/tasks/tc.rb +114 -0
- data/lib/wile/tasks/test.rb +57 -0
- data/lib/wile/tasks/todo.rb +55 -0
- data/lib/wile/tasks/update.rb +67 -0
- data/lib/wile/tasks.rb +34 -0
- data/lib/wile/usage.rb +56 -0
- data/lib/wile/usage_error.rb +18 -0
- data/lib/wile/utilities.rb +283 -0
- data/lib/wile/utilities_refinements.rb +41 -0
- data/lib/wile/wile_refinements.rb +137 -0
- data/lib/wile.rb +39 -0
- data/man/wile.1 +1121 -0
- data/man/wile.md +786 -0
- data/pkg/README.md +3 -0
- metadata +399 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
|
|
6
|
+
README = 'README.md'
|
|
7
|
+
ROCKET = /\s*#=>\s*/
|
|
8
|
+
MATCH = /\s*#~>\s*/
|
|
9
|
+
DECLARATION = /\s*#!>\s*/
|
|
10
|
+
BINDING = binding
|
|
11
|
+
|
|
12
|
+
# README.md validations
|
|
13
|
+
class TestReadmeRocketCheck < Test::Unit::TestCase
|
|
14
|
+
def test_readme_rocket_check
|
|
15
|
+
return unless File.exist? README
|
|
16
|
+
|
|
17
|
+
step_thru_readme do |expected, actual, message|
|
|
18
|
+
if expected.is_a?(Regexp)
|
|
19
|
+
assert_match(expected, actual, message)
|
|
20
|
+
else
|
|
21
|
+
assert_equal(expected, actual, message)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
rescue ScriptError, StandardError => e
|
|
25
|
+
flunk e.message.red
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def init
|
|
31
|
+
@lines = File.readlines(README)
|
|
32
|
+
@ruby = false
|
|
33
|
+
@script = String.new
|
|
34
|
+
@line_number = 0
|
|
35
|
+
@line = nil
|
|
36
|
+
@actual = nil
|
|
37
|
+
@expected = nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def step_thru_readme
|
|
41
|
+
init
|
|
42
|
+
step_thru_script do
|
|
43
|
+
yield(@expected, @actual, "#{@line_number}: #{@line}")
|
|
44
|
+
end
|
|
45
|
+
completes_successfully unless @script.empty?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def completes_successfully
|
|
49
|
+
BINDING.eval(@script)
|
|
50
|
+
rescue ScriptError, StandardError => e
|
|
51
|
+
flunk "#{@line_number}: #{e.message}".red
|
|
52
|
+
ensure
|
|
53
|
+
@script.clear
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def ruby_code?
|
|
57
|
+
case @line
|
|
58
|
+
when /^```ruby\b/
|
|
59
|
+
@ruby = true
|
|
60
|
+
return false
|
|
61
|
+
when /^```\s*$/
|
|
62
|
+
completes_successfully unless @script.empty?
|
|
63
|
+
@ruby = false
|
|
64
|
+
end
|
|
65
|
+
@ruby
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def declaration_break?
|
|
69
|
+
if DECLARATION.match? @line
|
|
70
|
+
declaration = @line.split(DECLARATION, 2).last.chomp
|
|
71
|
+
puts "Rocket line number #{@line_number}:".colorize(:yellow)
|
|
72
|
+
puts declaration.colorize(:yellow)
|
|
73
|
+
return true if /^TODO/.match? declaration
|
|
74
|
+
end
|
|
75
|
+
false
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def step_thru_script
|
|
79
|
+
while (@line = @lines.shift)
|
|
80
|
+
@line_number += 1
|
|
81
|
+
next unless ruby_code?
|
|
82
|
+
break if declaration_break?
|
|
83
|
+
next unless script_ready?
|
|
84
|
+
|
|
85
|
+
eval_script
|
|
86
|
+
reset_expected_actual
|
|
87
|
+
yield
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def script_ready?
|
|
92
|
+
@script << @line unless @line.match?(/^\s*#/)
|
|
93
|
+
ROCKET.match?(@line) || MATCH.match?(@line)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def eval_script
|
|
97
|
+
@actual = BINDING.eval(@script)
|
|
98
|
+
rescue ScriptError, StandardError => e
|
|
99
|
+
@actual = e.message.red
|
|
100
|
+
ensure
|
|
101
|
+
@script.clear
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def reset_expected_actual
|
|
105
|
+
reset_expected
|
|
106
|
+
reset_actual
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def reset_expected
|
|
110
|
+
case @line
|
|
111
|
+
when ROCKET
|
|
112
|
+
@expected = @line.split(ROCKET, 2).last.chomp
|
|
113
|
+
when MATCH
|
|
114
|
+
@expected = Regexp.new @line.split(MATCH, 2).last.chomp
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def reset_actual(str = @actual.to_s.uncolorize)
|
|
119
|
+
ins = @actual.inspect
|
|
120
|
+
fallback = @actual.is_a?(String) ? str : ins
|
|
121
|
+
@actual = case @expected
|
|
122
|
+
when Regexp then @expected.match?(str) ? str : fallback
|
|
123
|
+
when str then str
|
|
124
|
+
when ins then ins
|
|
125
|
+
else fallback
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
data/cache/test/tc_reek
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
# wile: require 'reek'
|
|
6
|
+
# wile: os `reek`
|
|
7
|
+
|
|
8
|
+
# Reek Tests
|
|
9
|
+
class TestReek < Test::Unit::TestCase
|
|
10
|
+
REEK_OPTIONS = %w[--no-progress --config .reek.yml].freeze
|
|
11
|
+
|
|
12
|
+
def test_reek
|
|
13
|
+
files = ruby_files.reject { it.start_with?('cache/') }
|
|
14
|
+
flunk 'No files found for reek scan!'.red if files.empty?
|
|
15
|
+
|
|
16
|
+
res = system('reek', *REEK_OPTIONS, *files)
|
|
17
|
+
flunk 'reek command not found!'.red if res.nil?
|
|
18
|
+
flunk 'Smelly code!'.red unless res
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
# wile: require 'rubocop'
|
|
6
|
+
# wile: os `rubocop`
|
|
7
|
+
|
|
8
|
+
# Rubocop Tests
|
|
9
|
+
class TestRuboCop < Test::Unit::TestCase
|
|
10
|
+
RUBOCOP_OPTIONS = %w[--format quiet --config .rubocop.yml].freeze
|
|
11
|
+
|
|
12
|
+
def test_rubocop
|
|
13
|
+
files = ruby_files.reject { it.start_with?('cache/') }
|
|
14
|
+
flunk 'No files found for rubocop scan!'.red if files.empty?
|
|
15
|
+
|
|
16
|
+
res = system('rubocop', *RUBOCOP_OPTIONS, *files)
|
|
17
|
+
flunk 'rubocop command not found!'.red if res.nil?
|
|
18
|
+
flunk 'Busted by Rubocop!'.red unless res
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# wile: os `ruby`
|
|
5
|
+
|
|
6
|
+
require_relative 'test_helper'
|
|
7
|
+
|
|
8
|
+
# Ruby Syntax Tests
|
|
9
|
+
class TestRubySyntax < Test::Unit::TestCase
|
|
10
|
+
def test_ruby_syntax
|
|
11
|
+
files = ruby_files
|
|
12
|
+
flunk 'No files found for ruby syntax check!'.red if files.empty?
|
|
13
|
+
|
|
14
|
+
files.each { check_syntax(it) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def check_syntax(filename)
|
|
20
|
+
res = system('ruby', '-c', filename, out: File::NULL, err: File::NULL)
|
|
21
|
+
flunk 'ruby command not found!'.red if res.nil?
|
|
22
|
+
unless res
|
|
23
|
+
err = IO.popen(['ruby', '-c', filename], err: %i[child out], &:read)
|
|
24
|
+
flunk "# SYNTAX: #{filename}\n#{err}".red
|
|
25
|
+
end
|
|
26
|
+
assert res
|
|
27
|
+
end
|
|
28
|
+
end
|
data/cache/test/tc_tags
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
# wile: require 'ripper-tags'
|
|
6
|
+
# wile: os `ripper-tags`
|
|
7
|
+
|
|
8
|
+
# Tags Test generates and maintains the ctags file using ripper-tags.
|
|
9
|
+
class TestTags < Test::Unit::TestCase
|
|
10
|
+
PATTERNS = %w[lib/**/*.rb bin/* test/tc_* test/test_helper.rb].freeze
|
|
11
|
+
|
|
12
|
+
def test_tags
|
|
13
|
+
before = tags_content
|
|
14
|
+
generate_tags
|
|
15
|
+
after = tags_content
|
|
16
|
+
puts 'Tags changed.'.yellow if before != after
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def tags_content
|
|
22
|
+
File.file?('tags') ? File.read('tags') : nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def generate_tags
|
|
26
|
+
system('ripper-tags', *files)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def files
|
|
30
|
+
Dir.glob(PATTERNS).select { File.file?(it) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
|
|
6
|
+
# Fail-less warnings of missing cucumber task features.
|
|
7
|
+
class TestTasksTest < Test::Unit::TestCase
|
|
8
|
+
def test_tasks_test
|
|
9
|
+
return if quiet?
|
|
10
|
+
|
|
11
|
+
task_files.each do |file|
|
|
12
|
+
feature = expected_feature(file)
|
|
13
|
+
next if File.exist?(feature)
|
|
14
|
+
|
|
15
|
+
puts "Missing: #{feature}".yellow
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def task_files
|
|
22
|
+
Dir.glob('lib/**/tasks/*.rb')
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def expected_feature(file)
|
|
26
|
+
parts = file.split('/')
|
|
27
|
+
project = parts[1]
|
|
28
|
+
task = File.basename(file, '.rb')
|
|
29
|
+
"features/#{project}_#{task}.feature"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
|
|
6
|
+
# Version Tests
|
|
7
|
+
class TestVersion < Test::Unit::TestCase
|
|
8
|
+
class << self
|
|
9
|
+
attr_reader :version, :grep_version
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.startup
|
|
13
|
+
@grep_version = Dir.glob(['lib/*.rb', 'lib/*/version.rb']).lazy
|
|
14
|
+
.filter_map { File.read(it)[/\d+\.\d+\.\d+/] }
|
|
15
|
+
.first
|
|
16
|
+
|
|
17
|
+
if File.exist?('.version')
|
|
18
|
+
@version = File.read('.version').chomp
|
|
19
|
+
else
|
|
20
|
+
msg = 'Consider using `.version` as the authoritative VERSION source.'
|
|
21
|
+
warn msg.yellow
|
|
22
|
+
@version = @grep_version
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def setup
|
|
27
|
+
flunk 'Could not get authoritative VERSION'.red unless version
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_lib_version
|
|
31
|
+
if grep_version
|
|
32
|
+
assert_equal(version, grep_version)
|
|
33
|
+
else
|
|
34
|
+
# A strict prescription:
|
|
35
|
+
# rubocop: disable-next Lint/InterpolationCheck
|
|
36
|
+
expected = 'VERSION = File.read("#{ROOT}/.version").chomp'
|
|
37
|
+
actual = Dir.glob('lib/*.rb').lazy
|
|
38
|
+
.filter_map { File.read(it)[/^\s*VERSION\s*=.*$/] }
|
|
39
|
+
.first&.strip
|
|
40
|
+
assert_equal(expected, actual)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_bin_version
|
|
45
|
+
executable = File.join('bin', File.basename(Dir.pwd))
|
|
46
|
+
return unless File.file?(executable) && File.executable?(executable)
|
|
47
|
+
|
|
48
|
+
out = IO.popen([executable, '--version'], # permit
|
|
49
|
+
err: File::NULL, &:read)&.strip
|
|
50
|
+
assert_equal(version, out)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_gemspec_version
|
|
54
|
+
return unless (gemspec = Dir.glob('*.gemspec').first)
|
|
55
|
+
|
|
56
|
+
assert_equal(version, File.read(gemspec)[/\d+\.\d+\.\d+/])
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_readme_version
|
|
60
|
+
return unless (readme = Dir.glob('README.*').first)
|
|
61
|
+
|
|
62
|
+
content = File.read(readme)
|
|
63
|
+
assert_equal(version, content[/\d+\.\d+\.\d+/])
|
|
64
|
+
ruby_version = RUBY_VERSION.split('.').first(2).join('.')
|
|
65
|
+
assert_equal(ruby_version, content[/Ruby version:.*?(\d+\.\d+)/, 1])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def test_ruby_version
|
|
69
|
+
return unless File.exist?('.ruby-version')
|
|
70
|
+
|
|
71
|
+
content = File.read('.ruby-version').strip
|
|
72
|
+
assert_match(/\A\d+\.\d+\.\d+\z/, content)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_ruby_version_floor
|
|
76
|
+
return unless File.exist?('.ruby-version-floor')
|
|
77
|
+
|
|
78
|
+
floor = File.read('.ruby-version-floor').strip
|
|
79
|
+
assert_match(/\A\d+\.\d+(\.\d+)?\z/, floor)
|
|
80
|
+
active = Gem::Version.new(RUBY_VERSION)
|
|
81
|
+
assert_operator(Gem::Version.new(floor), :<=, active)
|
|
82
|
+
return unless File.exist?('.ruby-version')
|
|
83
|
+
|
|
84
|
+
pinned = Gem::Version.new(File.read('.ruby-version').strip)
|
|
85
|
+
assert_operator(Gem::Version.new(floor), :<=, pinned)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def version
|
|
91
|
+
self.class.version
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def grep_version
|
|
95
|
+
self.class.grep_version
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'find'
|
|
6
|
+
|
|
7
|
+
# Check for non-standard / weird filenames
|
|
8
|
+
class TestWeirdFilenames < Test::Unit::TestCase
|
|
9
|
+
ALLOWED = /\A[a-zA-Z0-9._][a-zA-Z0-9._-]*\z/
|
|
10
|
+
PRUNED = %w[./.git ./tmp ./wiki].freeze
|
|
11
|
+
|
|
12
|
+
def test_weird_filenames
|
|
13
|
+
weird = []
|
|
14
|
+
Find.find('.') do |path|
|
|
15
|
+
Find.prune if PRUNED.include?(path)
|
|
16
|
+
next if path == '.'
|
|
17
|
+
|
|
18
|
+
base = File.basename(path)
|
|
19
|
+
weird << path.scrub unless base.valid_encoding? && base.match?(ALLOWED)
|
|
20
|
+
end
|
|
21
|
+
assert_empty weird, "Weird filenames found:\n#{weird.join("\n").red}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Encoding.default_external = Encoding::UTF_8
|
|
4
|
+
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'colorize'
|
|
7
|
+
require 'prism'
|
|
8
|
+
# wile: require 'reek'
|
|
9
|
+
# wile: require 'rubocop'
|
|
10
|
+
# wile: os `diff,git,reek,rubocop`
|
|
11
|
+
|
|
12
|
+
String.disable_colorization = true unless $stdout.tty? &&
|
|
13
|
+
ENV['NO_COLOR'].to_s.empty? &&
|
|
14
|
+
ENV['TERM'] != 'dumb'
|
|
15
|
+
|
|
16
|
+
# :reek:IrresponsibleModule
|
|
17
|
+
module Test
|
|
18
|
+
# :reek:IrresponsibleModule
|
|
19
|
+
module Unit
|
|
20
|
+
# Shared test case helpers for unit tests.
|
|
21
|
+
# :reek:IrresponsibleModule
|
|
22
|
+
class TestCase
|
|
23
|
+
FAULT_ONLY = ARGV.include?('--progress-style=fault-only')
|
|
24
|
+
|
|
25
|
+
# :reek:UtilityFunction
|
|
26
|
+
def bang_ruby?(filename)
|
|
27
|
+
return false if /\.\w*$/.match?(filename) ||
|
|
28
|
+
File.directory?(filename) ||
|
|
29
|
+
File.empty?(filename) ||
|
|
30
|
+
!File.executable?(filename)
|
|
31
|
+
|
|
32
|
+
/^#!.*\bruby\b/.match?(File.read(filename, 80).lines[0].rstrip)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# :reek:UtilityFunction
|
|
36
|
+
def binary?(filename)
|
|
37
|
+
File.open(filename, 'rb') { |io| io.read(8192)&.include?("\x00") }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# :reek:UtilityFunction
|
|
41
|
+
def diff_output(source_file, target_file)
|
|
42
|
+
opt = String.disable_colorization ? '' : '--color=always'
|
|
43
|
+
`diff #{opt} #{source_file} #{target_file}`.strip
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# :reek:UtilityFunction
|
|
47
|
+
def quiet? = FAULT_ONLY
|
|
48
|
+
|
|
49
|
+
# :reek:UtilityFunction
|
|
50
|
+
def ruby?(filename)
|
|
51
|
+
/\.rb$/.match?(filename) || bang_ruby?(filename)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def ruby_files
|
|
55
|
+
`git ls-files`.lines.map(&:chomp)
|
|
56
|
+
.select { File.file?(it) }
|
|
57
|
+
.select { ruby?(it) }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Shared helpers for unit tests in Wile projects. Verifies that every
|
|
64
|
+
# method on a target class has a corresponding test method (method-level
|
|
65
|
+
# coverage audit) and provides no-fail wrappers for running linters on files.
|
|
66
|
+
#
|
|
67
|
+
# Suggested template usage:
|
|
68
|
+
#
|
|
69
|
+
# class TestMyClass < Test::Unit::TestCase
|
|
70
|
+
# include TestModule
|
|
71
|
+
#
|
|
72
|
+
# def test_coverage = coverage(MyClass)
|
|
73
|
+
#
|
|
74
|
+
# # And unit test methods...
|
|
75
|
+
#
|
|
76
|
+
# def test_rubocop_and_reek
|
|
77
|
+
# file = 'lib/my_class.rb'
|
|
78
|
+
# rubocop(file) && # but redundant by tc_rubocop
|
|
79
|
+
# reek(file) && # but redundant by tc_reek
|
|
80
|
+
# rubocop(__FILE__) # self rubocop-ing
|
|
81
|
+
# end
|
|
82
|
+
# end
|
|
83
|
+
|
|
84
|
+
module MissingCalls
|
|
85
|
+
def missing_calls = (@missing_calls ||= [])
|
|
86
|
+
|
|
87
|
+
# rubocop:disable-next Style/MissingRespondToMissing
|
|
88
|
+
def method_missing(*args)
|
|
89
|
+
missing_calls.push(args)
|
|
90
|
+
self
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# :reek:IrresponsibleModule
|
|
95
|
+
module MockUp
|
|
96
|
+
# :reek:TooManyStatements
|
|
97
|
+
def self.create(mod, symbol)
|
|
98
|
+
klass = Class.new do
|
|
99
|
+
include MissingCalls
|
|
100
|
+
|
|
101
|
+
def initialize(*) = nil
|
|
102
|
+
def inspect = self.class.to_s
|
|
103
|
+
end
|
|
104
|
+
klass.extend MissingCalls
|
|
105
|
+
mod.const_set(symbol, klass)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Test and warnings common to test files
|
|
110
|
+
module TestModule
|
|
111
|
+
# Checks for context.test_method for each klass.method
|
|
112
|
+
class Coverage
|
|
113
|
+
# Allow color changes.
|
|
114
|
+
# rubocop:disable-next Style/MutableConstant
|
|
115
|
+
COLOR = {
|
|
116
|
+
public: :yellow,
|
|
117
|
+
protected: :yellow,
|
|
118
|
+
private: :yellow,
|
|
119
|
+
refinement: :yellow
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
def initialize(klass, context)
|
|
123
|
+
@klass = klass
|
|
124
|
+
@context = context
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# :reek:ControlParameter
|
|
128
|
+
def test_all(klass_methods)
|
|
129
|
+
test_class_methods if klass_methods
|
|
130
|
+
test_public_methods
|
|
131
|
+
test_protected_methods
|
|
132
|
+
test_private_methods
|
|
133
|
+
test_refinements
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_class_methods
|
|
137
|
+
@klass.methods(false).sort.each do |method|
|
|
138
|
+
test_method method, :public, 'class_'
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_public_methods
|
|
143
|
+
@klass.public_instance_methods(false).sort.each do |method|
|
|
144
|
+
test_method method, :public
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_protected_methods
|
|
149
|
+
@klass.protected_instance_methods(false).sort.each do |method|
|
|
150
|
+
test_method method, :protected
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_private_methods
|
|
155
|
+
@klass.private_instance_methods(false).sort.each do |method|
|
|
156
|
+
test_method method, :private
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_refinements
|
|
161
|
+
@klass.refinements.each do |refinement|
|
|
162
|
+
test_refinement refinement, refinement.target.to_s.downcase
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
private
|
|
167
|
+
|
|
168
|
+
RENAME = lambda do |method|
|
|
169
|
+
"test_#{method}"
|
|
170
|
+
.sub(/\[\]=$/, 'brackets_set')
|
|
171
|
+
.sub(/\[\]$/, 'brackets')
|
|
172
|
+
.sub(/<<$/, 'shovel')
|
|
173
|
+
.sub(/<=>$/, 'spaceship')
|
|
174
|
+
.sub(/==$/, 'equals')
|
|
175
|
+
.sub(/=$/, '_set')
|
|
176
|
+
.sub(/!$/, '_bang')
|
|
177
|
+
.sub(/\?$/, '_predicate')
|
|
178
|
+
end
|
|
179
|
+
private_constant :RENAME
|
|
180
|
+
|
|
181
|
+
# Check if context has a test for the method.
|
|
182
|
+
# :reek:ManualDispatch
|
|
183
|
+
def test_method(method, type, mod = '')
|
|
184
|
+
return if method.start_with? 'test_'
|
|
185
|
+
|
|
186
|
+
name = RENAME["#{mod}#{method}"]
|
|
187
|
+
return if name.end_with?('?_set') || covered?(name, mod, method)
|
|
188
|
+
|
|
189
|
+
puts "Missing #{@context.class}##{name}".colorize COLOR[type]
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def covered?(name, mod, method)
|
|
193
|
+
return true if test_exists?(name)
|
|
194
|
+
|
|
195
|
+
method.end_with?('?') &&
|
|
196
|
+
test_exists?("test_#{mod}#{method}".sub(/\?$/, '_wut'))
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# :reek:ManualDispatch
|
|
200
|
+
def test_exists?(name)
|
|
201
|
+
return true if @context.respond_to?(name.to_sym)
|
|
202
|
+
|
|
203
|
+
@context.methods.any? { it.to_s.start_with?("#{name}_") }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_refinement(refinement, target)
|
|
207
|
+
refinement.public_instance_methods(false).each do |method|
|
|
208
|
+
test_method "#{target}_#{method}", :refinement
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# No fail warnings
|
|
214
|
+
# :reek:BooleanParameter
|
|
215
|
+
def coverage(klass, klass_methods: true)
|
|
216
|
+
Coverage.new(klass, self).test_all(klass_methods)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# No fail system runs
|
|
220
|
+
|
|
221
|
+
def reek(file)
|
|
222
|
+
puts "Reek #{file}".blue
|
|
223
|
+
system('reek', file)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def rubocop(file)
|
|
227
|
+
puts "Rubocop #{file}".blue
|
|
228
|
+
system('rubocop', file)
|
|
229
|
+
end
|
|
230
|
+
end
|
data/cache/tmp/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Temporary Files
|
|
2
|
+
|
|
3
|
+
Temporary working files -- such as `tmp/.dictionary` and `tmp/.lexicon`
|
|
4
|
+
generated by `wile test`, `wile dictionary`, and `wile lexicon` -- are placed
|
|
5
|
+
here.
|
|
6
|
+
|
|
7
|
+
Other files in this directory are ignored via `.gitignore`. This `README.md` is
|
|
8
|
+
tracked so that `./tmp/` exists in the repository.
|