lib/raap/cli.rb in raap-0.4.0 vs lib/raap/cli.rb in raap-0.5.0

- old
+ new

@@ -10,11 +10,10 @@ :timeout, :size_from, :size_to, :size_by, :allow_private, - :skips, keyword_init: true ) # Should skip methods has side effects DEFAULT_SKIP = Set.new @@ -43,11 +42,10 @@ libraries: [], timeout: 3, size_from: 0, size_to: 99, size_by: 1, - skips: [], allow_private: false, ) @argv = argv @skip = DEFAULT_SKIP.dup @results = [] @@ -62,11 +60,11 @@ @option.libraries << lib end o.on('--require lib', 'require ruby library') do |lib| @option.requires << lib end - o.on('--log-level level', "default: warn") do |arg| + o.on('--log-level level', "default: info") do |arg| RaaP.logger.level = arg end o.on('--timeout sec', Float, "default: #{@option.timeout}") do |arg| @option.timeout = arg end @@ -80,13 +78,10 @@ @option.size_by = arg end o.on('--allow-private', "default: #{@option.allow_private}") do @option.allow_private = true end - o.on('--skip tag', "skip case (e.g. `Foo#meth`)") do |tag| - @option.skips << tag - end end.parse!(@argv) @option.dirs.each do |dir| RaaP::RBS.loader.add(path: Pathname(dir)) end @@ -94,14 +89,10 @@ RaaP::RBS.loader.add(library: lib, version: nil) end @option.requires.each do |lib| require lib end - @option.skips.each do |skip| - @skip << skip - end - @skip.freeze self end def run @@ -109,11 +100,24 @@ puts "Interrupted by SIGINT" report exit 1 end - @argv.map do |tag| + # Search skip tag + @argv.each do |tag| + if tag.start_with?('!') && (tag.include?('#') || tag.include?('.')) + t = tag[1..] or raise + t = "::#{t}" unless t.start_with?('::') + t or raise + @skip << t + end + end + @skip.freeze + + @argv.each do |tag| + next if tag.start_with?('!') + case when tag.include?('#') run_by(kind: :instance, tag:) when tag.include?('.') run_by(kind: :singleton, tag:) @@ -202,11 +206,15 @@ end def run_by_type_name_with_search(tag:) first, _last = tag.split('::') RBS.env.class_decls.each do |name, _entry| - if ['', '::'].any? { |pre| name.to_s.match?(/\A#{pre}#{first}\b/) } + if ['', '::'].any? { |pre| name.to_s.start_with?("#{pre}#{first}") } + if @skip.include?(name.to_s) + RaaP.logger.info("Skip #{name}") + next + end run_by_type_name(tag: name.to_s) end end end @@ -218,12 +226,15 @@ type_name = type.name.absolute! type_args = type.args definition = RBS.builder.build_singleton(type_name) type_params_decl = definition.type_params_decl - definition.methods.filter_map do |method_name, method| - next if @skip.include?("#{type_name.absolute!}.#{method_name}") + definition.methods.each do |method_name, method| + if @skip.include?("#{type_name.absolute!}.#{method_name}") + RaaP.logger.info("Skip #{"#{type_name.absolute!}.#{method_name}"}") + next + end next unless method.accessibility == :public next if method.defined_in != type_name RaaP.logger.info("# #{type_name}.#{method_name}") @results << { @@ -234,12 +245,15 @@ } end definition = RBS.builder.build_instance(type_name) type_params_decl = definition.type_params_decl - definition.methods.filter_map do |method_name, method| - next if @skip.include?("#{type_name.absolute!}##{method_name}") + definition.methods.each do |method_name, method| + if @skip.include?("#{type_name.absolute!}##{method_name}") + RaaP.logger.info("Skip #{"#{type_name.absolute!}.#{method_name}"}") + next + end next unless method.accessibility == :public next if method.defined_in != type_name RaaP.logger.info("# #{type_name}##{method_name}") @results << { @@ -256,13 +270,15 @@ if receiver_type.type.instance_of?(::RBS::Types::ClassSingleton) prefix = 'self.' else prefix = '' end - type_params_decl.each_with_index do |_, i| + + # type_args delegate to self_type + type_params_decl.each_with_index do |param, i| if rtype.instance_of?(::RBS::Types::ClassInstance) - rtype.args[i] = type_args[i] || ::RBS::Types::Bases::Any.new(location: nil) + rtype.args[i] = type_args[i] || param.upper_bound || ::RBS::Types::Bases::Any.new(location: nil) end end RaaP.logger.info("## def #{prefix}#{method_name}: #{method_type}") status = 0 reason = nil @@ -277,21 +293,21 @@ instance_type: ::RBS::Types::ClassInstance.new(name: rtype.name, args: type_args, location: nil), class_type: ::RBS::Types::ClassSingleton.new(name: rtype.name, location: nil), ), size_step: @option.size_from.step(to: @option.size_to, by: @option.size_by), timeout: @option.timeout, - allow_private: true, + allow_private: @option.allow_private, ) start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) stats = prop.run do |called| case called in Result::Success => s print '.' RaaP.logger.debug { "Success: #{s.called_str}" } in Result::Failure => f puts 'F' if (e = f.exception) - RaaP.logger.debug { "Failure: [#{e.class}] #{e.message}" } + RaaP.logger.info { "Failure: [#{e.class}] #{e.message}" } RaaP.logger.debug { e.backtrace.join("\n") } end RaaP.logger.debug { PP.pp(f.symbolic_call, ''.dup) } reason = StringIO.new reason.puts "Failed in case of `#{f.called_str}`"