dictionary help indexing tool/coverage tooling

This commit is contained in:
mgcaret 2020-01-06 12:31:19 -08:00
parent 2f0281a5d9
commit e59f1ce197
2 changed files with 78 additions and 0 deletions

28
utils/covrep.rb Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/ruby
require 'yaml'
index_file = ARGV.shift || usage
File.readable?(index_file) || abort("#{index_file} not found!")
index = YAML.load(File.read(index_file))
covered = []
uncovered = []
index.each_pair do |name, props|
if props["tests"] && props["tests"] > 0
covered << name
else
uncovered << name
end
end
cov_percent = covered.count * 100 / (covered.count+uncovered.count)
puts "Total words: #{covered.count+uncovered.count}"
puts "Covered words: #{covered.count}"
puts "Uncovered words: #{uncovered.count}"
uncovered.each_slice(5) do |sl|
puts "\t#{sl.join(' ')}"
end
puts "Coverage: #{cov_percent}%"

50
utils/index.rb Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/ruby
require 'yaml'
def usage
puts <<EOF
Usage: #{$0} dictionary-source-file coverage-file
reads dictionary-source-file and produces YAML output
with all visible words and their help text, flags, etc.
if coverage-file is specified, merge coverage data
EOF
exit 1
end
dict = ARGV.shift || usage
File.readable?(dict) || abort("#{dict} not found!")
cov = ARGV.shift
coverage = {}
if File.readable?(cov)
coverage = YAML.load(File.read(cov))
end
input = File.read(dict)
output = Hash.new()
help = []
input.lines.each do |line|
case line
when /^\s*;\s+H:\s*(.+)/
help << $1
when /^\s*dword(q?)\s+(.+)/
_label, nameq, flags = $2.split(',')
name = nameq[1..-2].downcase # remove quotes
name.tr!("'", '"') if $1 == 'q'
output[name] ||= {}
output[name].merge!({"help" => help}) unless help.empty?
if flags
fl = flags.split('|')
output[name].merge!({"flags" => fl}) unless fl.empty?
end
output[name].merge!({"tests" => coverage[name]}) if coverage[name]
when /^\s*eword/
help = []
end
end
puts output.to_yaml