From 75e590b9455d532505602c22a38660cf765f94e3 Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Fri, 20 Nov 2026 17:37:05 -0500 Subject: [PATCH 1/2] Modernize packaging and run on current Ruby Replace the .index/.gemspec/Assembly/MANIFEST/var packaging with a plain tapout.gemspec and Rakefile, and Travis with GitHub Actions on Ruby 2.7 to 4.0. Tapout::VERSION is now a constant; Tapout.metadata and lib/tapout.yml are gone. Stop using the abbrev library, which left Ruby's default gems in 3.4: reporter names are matched by unique prefix directly. Stop appending to string literals, so Tapout works with frozen string literals. Correct the README's reporter name (progress, not progressbar), a typo in its pause example, and its links. Co-Authored-By: Claude Fable 5.2 --- .gemspec | 307 ----------- .github/workflows/ci.yml | 35 ++ .index | 70 --- .travis.yml | 10 - Assembly | 26 - HISTORY.md | 18 + MANIFEST | 41 -- README.md | 23 +- Rakefile | 22 + demo/01_reporters/applique/cli.rb | 2 +- demo/02_adapters/perl_adapter.md | 2 +- lib/tapout.rb | 1 + lib/tapout.yml | 1 - lib/tapout/adapters/perl.rb | 2 +- lib/tapout/parsers/abstract.rb | 2 +- lib/tapout/parsers/yaml.rb | 4 +- lib/tapout/reporters/abstract.rb | 18 +- lib/tapout/reporters/progress_reporter.rb | 4 +- lib/tapout/version.rb | 19 +- tapout.gemspec | 40 ++ var/authors | 2 - var/copyrights | 2 - var/created | 1 - var/description | 1 - var/name | 1 - var/organizations | 2 - var/repositories | 2 - var/requirements | 6 - var/resources | 9 - var/summary | 1 - var/title | 1 - var/version | 1 - work/minitest.rb | 632 ---------------------- 33 files changed, 150 insertions(+), 1158 deletions(-) delete mode 100644 .gemspec create mode 100644 .github/workflows/ci.yml delete mode 100644 .index delete mode 100644 .travis.yml delete mode 100644 Assembly delete mode 100644 MANIFEST create mode 100644 Rakefile delete mode 120000 lib/tapout.yml create mode 100644 tapout.gemspec delete mode 100644 var/authors delete mode 100644 var/copyrights delete mode 100644 var/created delete mode 100644 var/description delete mode 100644 var/name delete mode 100644 var/organizations delete mode 100644 var/repositories delete mode 100644 var/requirements delete mode 100644 var/resources delete mode 100644 var/summary delete mode 100644 var/title delete mode 100644 var/version delete mode 100644 work/minitest.rb diff --git a/.gemspec b/.gemspec deleted file mode 100644 index ea0db60..0000000 --- a/.gemspec +++ /dev/null @@ -1,307 +0,0 @@ -# encoding: utf-8 - -require 'yaml' -require 'pathname' - -module Indexer - - # Convert index data into a gemspec. - # - # Notes: - # * Assumes all executables are in bin/. - # * Does not yet handle default_executable setting. - # * Does not yet handle platform setting. - # * Does not yet handle required_ruby_version. - # * Support for rdoc entries is weak. - # - class GemspecExporter - - # File globs to include in package --unless a manifest file exists. - FILES = ".index .yardopts alt bin data demo ext features lib man spec test try* [A-Z]*.*" unless defined?(FILES) - - # File globs to omit from FILES. - OMIT = "Config.rb" unless defined?(OMIT) - - # Standard file patterns. - PATTERNS = { - :root => '{.index,Gemfile}', - :bin => 'bin/*', - :lib => 'lib/{**/}*', #.rb', - :ext => 'ext/{**/}extconf.rb', - :doc => '*.{txt,rdoc,md,markdown,tt,textile}', - :test => '{test,spec}/{**/}*.rb' - } unless defined?(PATTERNS) - - # For which revision of indexer spec is this converter intended? - REVISION = 2013 unless defined?(REVISION) - - # - def self.gemspec - new.to_gemspec - end - - # - attr :metadata - - # - def initialize(metadata=nil) - @root_check = false - - if metadata - root_dir = metadata.delete(:root) - if root_dir - @root = root_dir - @root_check = true - end - metadata = nil if metadata.empty? - end - - @metadata = metadata || YAML.load_file(root + '.index') - - if @metadata['revision'].to_i != REVISION - warn "This gemspec exporter was not designed for this revision of index metadata." - end - end - - # - def has_root? - root ? true : false - end - - # - def root - return @root if @root || @root_check - @root_check = true - @root = find_root - end - - # - def manifest - return nil unless root - @manifest ||= Dir.glob(root + 'manifest{,.txt}', File::FNM_CASEFOLD).first - end - - # - def scm - return nil unless root - @scm ||= %w{git hg}.find{ |m| (root + ".#{m}").directory? }.to_sym - end - - # - def files - return [] unless root - @files ||= \ - if manifest - File.readlines(manifest). - map{ |line| line.strip }. - reject{ |line| line.empty? || line[0,1] == '#' } - else - list = [] - Dir.chdir(root) do - FILES.split(/\s+/).each do |pattern| - list.concat(glob(pattern)) - end - OMIT.split(/\s+/).each do |pattern| - list = list - glob(pattern) - end - end - list - end.select{ |path| File.file?(path) }.uniq - end - - # - def glob_files(pattern) - return [] unless root - Dir.chdir(root) do - Dir.glob(pattern).select do |path| - File.file?(path) && files.include?(path) - end - end - end - - def patterns - PATTERNS - end - - def executables - @executables ||= \ - glob_files(patterns[:bin]).map do |path| - File.basename(path) - end - end - - def extensions - @extensions ||= \ - glob_files(patterns[:ext]).map do |path| - File.basename(path) - end - end - - def name - metadata['name'] || metadata['title'].downcase.gsub(/\W+/,'_') - end - - def homepage - page = ( - metadata['resources'].find{ |r| r['type'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^home/i } || - metadata['resources'].find{ |r| r['name'] =~ /^web/i } - ) - page ? page['uri'] : false - end - - def licenses - metadata['copyrights'].map{ |c| c['license'] }.compact - end - - def require_paths - paths = metadata['paths'] || {} - paths['load'] || ['lib'] - end - - # - # Convert to gemnspec. - # - def to_gemspec - if has_root? - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - else - Gem::Specification.new do |gemspec| - to_gemspec_data(gemspec) - to_gemspec_paths(gemspec) - end - end - end - - # - # Convert pure data settings. - # - def to_gemspec_data(gemspec) - gemspec.name = name - gemspec.version = metadata['version'] - gemspec.summary = metadata['summary'] - gemspec.description = metadata['description'] - - metadata['authors'].each do |author| - gemspec.authors << author['name'] - - if author.has_key?('email') - if gemspec.email - gemspec.email << author['email'] - else - gemspec.email = [author['email']] - end - end - end - - gemspec.licenses = licenses - - requirements = metadata['requirements'] || [] - requirements.each do |req| - next if req['optional'] - next if req['external'] - - name = req['name'] - groups = req['groups'] || [] - - version = gemify_version(req['version']) - - if groups.empty? or groups.include?('runtime') - # populate runtime dependencies - if gemspec.respond_to?(:add_runtime_dependency) - gemspec.add_runtime_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - else - # populate development dependencies - if gemspec.respond_to?(:add_development_dependency) - gemspec.add_development_dependency(name,*version) - else - gemspec.add_dependency(name,*version) - end - end - end - - # convert external dependencies into gemspec requirements - requirements.each do |req| - next unless req['external'] - gemspec.requirements << ("%s-%s" % req.values_at('name', 'version')) - end - - gemspec.homepage = homepage - gemspec.require_paths = require_paths - gemspec.post_install_message = metadata['install_message'] - end - - # - # Set gemspec settings that require a root directory path. - # - def to_gemspec_paths(gemspec) - gemspec.files = files - gemspec.extensions = extensions - gemspec.executables = executables - - if Gem::VERSION < '1.7.' - gemspec.default_executable = gemspec.executables.first - end - - gemspec.test_files = glob_files(patterns[:test]) - - unless gemspec.files.include?('.document') - gemspec.extra_rdoc_files = glob_files(patterns[:doc]) - end - end - - # - # Return a copy of this file. This is used to generate a local - # .gemspec file that can automatically read the index file. - # - def self.source_code - File.read(__FILE__) - end - - private - - def find_root - root_files = patterns[:root] - if Dir.glob(root_files).first - Pathname.new(Dir.pwd) - elsif Dir.glob("../#{root_files}").first - Pathname.new(Dir.pwd).parent - else - #raise "Can't find root of project containing `#{root_files}'." - warn "Can't find root of project containing `#{root_files}'." - nil - end - end - - def glob(pattern) - if File.directory?(pattern) - Dir.glob(File.join(pattern, '**', '*')) - else - Dir.glob(pattern) - end - end - - def gemify_version(version) - case version - when /^(.*?)\+$/ - ">= #{$1}" - when /^(.*?)\-$/ - "< #{$1}" - when /^(.*?)\~$/ - "~> #{$1}" - else - version - end - end - - end - -end - -Indexer::GemspecExporter.gemspec \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bdecda9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Monthly, to catch breakage from new Ruby or dependency releases + # when nothing has been pushed. + schedule: + - cron: '0 6 1 * *' + +permissions: + contents: read + +jobs: + test: + name: Ruby ${{ matrix.ruby }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4', '4.0'] + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Demos + run: bundle exec qed -Ilib demo/ + - name: Demos with frozen string literals + if: matrix.ruby == '4.0' + run: bundle exec qed -Ilib demo/ + env: + RUBYOPT: --enable=frozen-string-literal diff --git a/.index b/.index deleted file mode 100644 index f340a1b..0000000 --- a/.index +++ /dev/null @@ -1,70 +0,0 @@ ---- -revision: 2013 -type: ruby -sources: -- var -authors: -- name: Thomas Sawyer - email: transfire@gmail.com -organizations: -- name: Rubyworks -requirements: -- name: ansi -- name: json -- groups: - - build - development: true - name: ergo -- groups: - - test - development: true - name: qed -- groups: - - test - development: true - name: ae -conflicts: [] -alternatives: [] -resources: -- type: home - uri: http://rubyworks.github.com/tapout - label: Homepage -- type: wiki - uri: http://github.com/rubyworks/tapout/wiki - label: User Guide -- type: docs - uri: http://rubydoc.info/gems/tapout/frames - label: Documentation -- type: code - uri: http://github.com/rubyworks/tapout - label: Source Code -- type: bugs - uri: http://github.com/rubyworks/tapout/issues - label: Issue Tracker -- type: mail - uri: http://groups.google.com/rubyworks-mailinglist - label: Mailing List -- type: chat - uri: irc://chat.us.freenode.net#rubyworks - label: IRC Channel -repositories: -- name: upstream - scm: git - uri: git://github.com/rubyworks/tapout.git -categories: [] -copyrights: -- holder: Thomas Sawyer - year: '2010' - license: BSD-2-Clause -customs: [] -paths: - lib: - - lib -name: tapout -title: TAPOUT -summary: Progressive TAP Harness -created: '2010-12-23' -description: Tapout is a TAP consumer that can take any TAP, TAP-Y or TAP-J stream - and output it in a variety of useful formats. -version: 0.4.5 -date: '2013-11-20' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d76d6ff..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -language: ruby -script: "bundle exec qed" -rvm: - - 1.8.7 - - 1.9.3 - - 2.0.0 - - rbx - - jruby - diff --git a/Assembly b/Assembly deleted file mode 100644 index 460d8b3..0000000 --- a/Assembly +++ /dev/null @@ -1,26 +0,0 @@ ---- -github: - gh_pages: web - -gem: - active: true - -dnote: - title: Source Notes - labels: ~ - output: log/notes.html - -locat: - output: log/locat.html - active: false - -email: - mailto: - - ruby-talk@ruby-lang.org - - rubyworks-mailinglist@googlegroups.com - -vclog: - output: - - log/history.html - - log/changes.html - diff --git a/HISTORY.md b/HISTORY.md index d08dfa9..270432d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,23 @@ # RELEASE HISTORY +## Unreleased + +Tapout runs on current Ruby again. It needs Ruby 2.7 or newer. + +Changes: + +* Work with Bundler on Ruby 3.4 and newer, where the `abbrev` library is + no longer part of Ruby. Reporter names are matched without it: a name + can still be shortened to any unique beginning, as in `tapout pro`. +* Work with frozen string literals. +* Replace the old packaging (`.index`, `.gemspec`, `Assembly`, `MANIFEST`, + `var/`) with a plain `tapout.gemspec`, and Travis with GitHub Actions, + testing Ruby 2.7 to 4.0. +* `Tapout::VERSION` is a constant in `tapout/version.rb`. `Tapout.metadata` + and the lookup of other project metadata as constants are gone. +* Correct the README, which named a `progressbar` reporter; it is + `progress`. + ## 0.4.5 / 2013-11-20 Added some convenience methods for test runners using tapout. diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 2268117..0000000 --- a/MANIFEST +++ /dev/null @@ -1,41 +0,0 @@ -#!mast .index .yardopts bin demo lib man spec test *.md *.txt -.index -.yardopts -bin/tapout -demo/01_reporters/applique/cli.rb -demo/01_reporters/fixtures/tapy.yml -demo/01_reporters/reporters.md -demo/02_adapters/perl_adapter.md -demo/09_issues/applique/env.rb -demo/09_issues/default_reporter.md -demo/applique/ae.rb -demo/applique/env.rb -lib/tapout/adapters/perl.rb -lib/tapout/cli.rb -lib/tapout/config.rb -lib/tapout/core_ext.rb -lib/tapout/parsers/abstract.rb -lib/tapout/parsers/json.rb -lib/tapout/parsers/perl.rb -lib/tapout/parsers/yaml.rb -lib/tapout/parsers.rb -lib/tapout/reporters/abstract.rb -lib/tapout/reporters/breakdown_reporter.rb -lib/tapout/reporters/dot_reporter.rb -lib/tapout/reporters/html_reporter.rb -lib/tapout/reporters/markdown_reporter.rb -lib/tapout/reporters/outline_reporter.rb -lib/tapout/reporters/pretty_reporter.rb -lib/tapout/reporters/progress_reporter.rb -lib/tapout/reporters/runtime_reporter.rb -lib/tapout/reporters/tap_reporter.rb -lib/tapout/reporters/turn_reporter.rb -lib/tapout/reporters.rb -lib/tapout/utility.rb -lib/tapout/version.rb -lib/tapout.rb -lib/tapout.yml -COPYING.md -README.md -TAP-YJ.md -HISTORY.md diff --git a/README.md b/README.md index c322262..b24a7cc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # TAPOUT -[Website](http://rubyworks.github.com/tapout) | -[User Guide](http://github.com/rubyworks/tapout/wiki) | -[Report Issue](http://github.com/rubyworks/tapout/issues) | -[Development](http://github.com/rubyworks/tapout) +[Website](https://rubyworks.github.io/tapout) | +[User Guide](https://github.com/rubyworks/tapout/wiki) | +[Report Issue](https://github.com/rubyworks/tapout/issues) | +[Development](https://github.com/rubyworks/tapout) -[![Build Status](https://secure.travis-ci.org/rubyworks/tapout.png)](http://travis-ci.org/rubyworks/tapout) -[![Gem Version](https://badge.fury.io/rb/tapout.png)](http://badge.fury.io/rb/tapout)     -[![Flattr Me](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund) +[![CI](https://github.com/rubyworks/tapout/actions/workflows/ci.yml/badge.svg)](https://github.com/rubyworks/tapout/actions/workflows/ci.yml) +[![Gem Version](https://badge.fury.io/rb/tapout.svg)](https://rubygems.org/gems/tapout) ## About @@ -26,7 +25,7 @@ limitations. To learn about the TAP-Y/J specification, see the [TAP-Y/J Specification](https://github.com/rubyworks/tapout/wiki/TAP-Y-J-Specification) document. -For information about TAP, see http://testanything.org/ +For information about TAP, see https://testanything.org/ ## Usage @@ -49,14 +48,14 @@ TAPOUT supports a variety of output formats. The default is the common dot-progress format (simply called `dot`). Other formats are selectable via the `tapout` command's first argument. - $ rubytest -y -Ilib test/foo.rb | tapout progressbar + $ rubytest -y -Ilib test/foo.rb | tapout progress TAPOUT is smart enough to match the closest matching format name. So, for example, the above could be written as: $ rubytest -y -Ilib test/foo.rb | tapout pro -And tapout will know to use the `progressbar` format. +And tapout will know to use the `progress` format. To see a list of supported formats use the list subcommand: @@ -66,7 +65,7 @@ If your test framework does not support TAP-Y/J, but does support traditional TAP, TAPOUT will automatically recognize the difference by TAP's `1..N` header and automatically translate it. - $ rubytest -ftap -Ilib test/foo.rb | tapout progressbar + $ rubytest -ftap -Ilib test/foo.rb | tapout progress ## Bypassing @@ -85,7 +84,7 @@ A good example of this is debugging with Pry using `binding.pry`. def test_something STDOUT.puts 16.chr # tells tapout to pause processing binding.pry - STDOUT.puts 23.char # tells tapout to start again + STDOUT.puts 23.chr # tells tapout to start again assert something end diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..abc2187 --- /dev/null +++ b/Rakefile @@ -0,0 +1,22 @@ +require 'rake/clean' +CLOBBER.include 'pkg' + +require 'bundler/gem_helper' + +# Bundler tags releases as v1.2.3, but Tapout's tags have always been +# plain version numbers, so keep it that way. +class Bundler::GemHelper + def version_tag + version.to_s + end +end + +Bundler::GemHelper.install_tasks + +desc 'run demos' +task 'demo' do + sh 'qed -Ilib demo/' +end + +task 'test' => 'demo' +task 'default' => 'demo' diff --git a/demo/01_reporters/applique/cli.rb b/demo/01_reporters/applique/cli.rb index 0ffe30a..a97e37d 100644 --- a/demo/01_reporters/applique/cli.rb +++ b/demo/01_reporters/applique/cli.rb @@ -6,7 +6,7 @@ When '(((\w+))) reporter should run without error' do |format| $stdin = StringIO.new(@tapy) - $stdout = StringIO.new(out = '') + $stdout = StringIO.new(out = String.new) Tapout.cli(format) end diff --git a/demo/02_adapters/perl_adapter.md b/demo/02_adapters/perl_adapter.md index ddf9eee..86d1531 100644 --- a/demo/02_adapters/perl_adapter.md +++ b/demo/02_adapters/perl_adapter.md @@ -36,7 +36,7 @@ Or pipe the converted stream directly to another stream. adapter = Tapout::PerlAdapter.new(stream) - output = "" + output = String.new tapy = adapter | output diff --git a/lib/tapout.rb b/lib/tapout.rb index ca97ef0..b154d51 100644 --- a/lib/tapout.rb +++ b/lib/tapout.rb @@ -1,6 +1,7 @@ module Tapout end +require 'tapout/version' require 'tapout/config' require 'tapout/cli' require 'tapout/parsers' diff --git a/lib/tapout.yml b/lib/tapout.yml deleted file mode 120000 index f018114..0000000 --- a/lib/tapout.yml +++ /dev/null @@ -1 +0,0 @@ -../.index \ No newline at end of file diff --git a/lib/tapout/adapters/perl.rb b/lib/tapout/adapters/perl.rb index b3e4be2..d7ea9ab 100644 --- a/lib/tapout/adapters/perl.rb +++ b/lib/tapout/adapters/perl.rb @@ -29,7 +29,7 @@ def reset # Convert input stream to TAP-Y string. def to_s - self | "" + self | String.new end # Route stream to an array of entires. diff --git a/lib/tapout/parsers/abstract.rb b/lib/tapout/parsers/abstract.rb index 1c002d4..5721f88 100644 --- a/lib/tapout/parsers/abstract.rb +++ b/lib/tapout/parsers/abstract.rb @@ -18,7 +18,7 @@ def passthru(doc=nil) return line if RESUME_DOCUMENT === line $stdout << line end - return '' + return String.new end end diff --git a/lib/tapout/parsers/yaml.rb b/lib/tapout/parsers/yaml.rb index a880fd9..7f79e08 100644 --- a/lib/tapout/parsers/yaml.rb +++ b/lib/tapout/parsers/yaml.rb @@ -32,7 +32,7 @@ def initialize(options={}) def consume(input=nil) @input = input if input - entry = '' + entry = String.new while line = @input.gets case line when PAUSE_DOCUMENT @@ -88,7 +88,7 @@ def passthru(doc=nil) return line if @resume === line $stdout << line end - return '' + return String.new end end diff --git a/lib/tapout/reporters/abstract.rb b/lib/tapout/reporters/abstract.rb index e29f43f..a480cf2 100644 --- a/lib/tapout/reporters/abstract.rb +++ b/lib/tapout/reporters/abstract.rb @@ -1,5 +1,4 @@ require 'ansi' -require 'abbrev' module Tapout @@ -19,13 +18,11 @@ def self.index # Returns a reporter class given it's name or a unique abbreviation of it. # If `name` is `nil` then the default dot reporter is returned. def self.factory(name) - list = index.keys.abbrev - rptr = index[list[name || DEAFULT_REPORTER]] + rptr = lookup(name || DEAFULT_REPORTER) unless rptr begin require "tapout-#{name}" - list = index.keys.abbrev - rptr = index[list[name || DEAFULT_REPORTER]] + rptr = lookup(name || DEAFULT_REPORTER) rescue LoadError end raise ArgumentError, "Unrecognized reporter -- #{name.inspect}" unless rptr @@ -33,6 +30,15 @@ def self.factory(name) rptr end + # Returns the reporter class with the given name, or the one whose name + # it is the start of, if there is only one such. + def self.lookup(name) + name = name.to_s + return index[name] if index.key?(name) + keys = index.keys.select { |key| key.start_with?(name) } + keys.size == 1 ? index[keys.first] : nil + end + ## # The Abstract class serves as a base class for all reporters. Reporters # must sublcass Abstract in order to be added the the Reporters Index. @@ -495,7 +501,7 @@ def captured_stderr(test) # def captured_output(test) - str = "" + str = String.new str += captured_stdout(test){ |c| "\nSTDOUT\n#{c.tabto(4)}\n" }.to_s str += captured_stderr(test){ |c| "\nSTDERR\n#{c.tabto(4)}\n" }.to_s str diff --git a/lib/tapout/reporters/progress_reporter.rb b/lib/tapout/reporters/progress_reporter.rb index ab6629e..0d4e221 100644 --- a/lib/tapout/reporters/progress_reporter.rb +++ b/lib/tapout/reporters/progress_reporter.rb @@ -175,7 +175,7 @@ def post_report(suite) #puts("\n%i tests, %i assertions, %i failures, %i errors\n\n" % tally) - tally_line = "-----\n" + tally_line = +"-----\n" tally_line << "%-#{width}s " % "TOTAL" tally_line << "%10s %10s %10s %10s" % tally @@ -201,7 +201,7 @@ def post_report(suite) private def paint_line(testrun, width) - line = '' + line = String.new line << "%-#{width}s " % [testrun.name] line << "%10s %10s %10s %10s" % testrun.counts line << " " * 8 diff --git a/lib/tapout/version.rb b/lib/tapout/version.rb index 340e030..6a80542 100644 --- a/lib/tapout/version.rb +++ b/lib/tapout/version.rb @@ -1,20 +1,7 @@ module Tapout + # The version of Tapout. + VERSION = '0.4.5' + # The current revision of the TAP-Y/J format. REVISION = "4" - - # Project metadata. - # - # @return [Hash] metadata from .ruby file - def self.metadata - @metadata ||= ( - require 'yaml' - YAML.load_file(File.join(File.dirname(__FILE__), '/../tapout.yml')) - ) - end - - # Any missing constant will be looked for in - # project metadata. - def self.const_missing(name) - metadata[name.to_s.downcase] || super(name) - end end diff --git a/tapout.gemspec b/tapout.gemspec new file mode 100644 index 0000000..245babc --- /dev/null +++ b/tapout.gemspec @@ -0,0 +1,40 @@ +require_relative 'lib/tapout/version' + +Gem::Specification.new do |s| + s.name = 'tapout' + s.version = Tapout::VERSION + s.summary = 'Progressive TAP Harness' + s.description = 'Tapout is a TAP consumer that can take any TAP, TAP-Y or TAP-J stream ' \ + 'and output it in a variety of useful formats.' + + s.authors = ['Trans'] + s.email = ['transfire@gmail.com'] + s.homepage = 'https://rubyworks.github.io/tapout' + s.license = 'BSD-2-Clause' + + s.metadata = { + 'homepage_uri' => s.homepage, + 'source_code_uri' => 'https://github.com/rubyworks/tapout', + 'bug_tracker_uri' => 'https://github.com/rubyworks/tapout/issues', + 'changelog_uri' => 'https://github.com/rubyworks/tapout/blob/master/HISTORY.md', + 'documentation_uri' => 'https://rubydoc.info/gems/tapout' + } + + s.required_ruby_version = '>= 2.7' + + s.files = Dir[ + 'lib/**/*.rb', 'bin/*', 'demo/**/*', + '.yardopts', 'README.md', 'HISTORY.md', 'COPYING.md', 'TAP-YJ.md' + ] + s.bindir = 'bin' + s.executables = ['tapout'] + s.require_paths = ['lib'] + s.extra_rdoc_files = ['COPYING.md', 'HISTORY.md', 'README.md', 'TAP-YJ.md'] + + s.add_dependency 'ansi', '>= 1.5' + s.add_dependency 'json' + + s.add_development_dependency 'rake', '>= 13' + s.add_development_dependency 'qed', '>= 2.9' + s.add_development_dependency 'ae', '>= 1.8' +end diff --git a/var/authors b/var/authors deleted file mode 100644 index ba213a0..0000000 --- a/var/authors +++ /dev/null @@ -1,2 +0,0 @@ ---- -- Thomas Sawyer diff --git a/var/copyrights b/var/copyrights deleted file mode 100644 index f3c6d17..0000000 --- a/var/copyrights +++ /dev/null @@ -1,2 +0,0 @@ ---- -- Copyright (c) 2010 Thomas Sawyer (BSD-2-Clause) diff --git a/var/created b/var/created deleted file mode 100644 index 213c2a4..0000000 --- a/var/created +++ /dev/null @@ -1 +0,0 @@ -2010-12-23 \ No newline at end of file diff --git a/var/description b/var/description deleted file mode 100644 index 4ca288e..0000000 --- a/var/description +++ /dev/null @@ -1 +0,0 @@ -Tapout is a TAP consumer that can take any TAP, TAP-Y or TAP-J stream and output it in a variety of useful formats. \ No newline at end of file diff --git a/var/name b/var/name deleted file mode 100644 index e32d731..0000000 --- a/var/name +++ /dev/null @@ -1 +0,0 @@ -tapout \ No newline at end of file diff --git a/var/organizations b/var/organizations deleted file mode 100644 index a2119fd..0000000 --- a/var/organizations +++ /dev/null @@ -1,2 +0,0 @@ ---- -- Rubyworks diff --git a/var/repositories b/var/repositories deleted file mode 100644 index d841cb6..0000000 --- a/var/repositories +++ /dev/null @@ -1,2 +0,0 @@ ---- -upstream: git://github.com/rubyworks/tapout.git diff --git a/var/requirements b/var/requirements deleted file mode 100644 index a0f21ef..0000000 --- a/var/requirements +++ /dev/null @@ -1,6 +0,0 @@ ---- -- ansi -- json -- ergo (build) -- qed (test) -- ae (test) diff --git a/var/resources b/var/resources deleted file mode 100644 index 02d70ad..0000000 --- a/var/resources +++ /dev/null @@ -1,9 +0,0 @@ ---- -home: http://rubyworks.github.com/tapout -wiki: http://github.com/rubyworks/tapout/wiki -docs: http://rubydoc.info/gems/tapout/frames -code: http://github.com/rubyworks/tapout -bugs: http://github.com/rubyworks/tapout/issues -mail: http://groups.google.com/rubyworks-mailinglist -chat: irc://chat.us.freenode.net#rubyworks - diff --git a/var/summary b/var/summary deleted file mode 100644 index 8f6fc52..0000000 --- a/var/summary +++ /dev/null @@ -1 +0,0 @@ -Progressive TAP Harness \ No newline at end of file diff --git a/var/title b/var/title deleted file mode 100644 index d4be44d..0000000 --- a/var/title +++ /dev/null @@ -1 +0,0 @@ -TAPOUT diff --git a/var/version b/var/version deleted file mode 100644 index 0bfccb0..0000000 --- a/var/version +++ /dev/null @@ -1 +0,0 @@ -0.4.5 diff --git a/work/minitest.rb b/work/minitest.rb deleted file mode 100644 index 5917525..0000000 --- a/work/minitest.rb +++ /dev/null @@ -1,632 +0,0 @@ -# MiniTest adaptor for tapout. - -require 'minitest/unit' -require 'stringio' - -# Becuase of some wierdness in MiniTest -#debug, $DEBUG = $DEBUG, false -#require 'minitest/unit' -#$DEBUG = debug - -module MiniTest - - # Runner for MiniTest suites. - # - # This is a heavily refactored version of the built-in MiniTest runner. It's - # about the same speed, from what I can tell, but is significantly easier to - # extend. - # - # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License). - # - # @see https://github.com/seattlerb/minitest MiniTest - class TapoutRunner < ::MiniTest::Unit - - attr_accessor :suite_start_time, :test_start_time, :reporters - - def initialize - self.report = {} - self.errors = 0 - self.failures = 0 - self.skips = 0 - self.test_count = 0 - self.assertion_count = 0 - self.verbose = false - self.reporters = [] - - @_source_cache = {} - end - - # Top level driver, controls all output and filtering. - def _run args = [] - self.options = process_args args - - self.class.plugins.each do |plugin| - send plugin - break unless report.empty? - end - - return failures + errors if @test_count > 0 # or return nil... - rescue Interrupt - abort 'Interrupted' - end - - # - def _run_anything(type) - self.start_time = Time.now - - suites = suites_of_type(type) - tests = suites.inject({}) do |acc, suite| - acc[suite] = filtered_tests(suite, type) - acc - end - - self.test_count = tests.inject(0) { |acc, suite| acc + suite[1].length } - - if test_count > 0 - trigger(:before_suites, suites, type) - - fix_sync do - suites.each { |suite| _run_suite(suite, tests[suite]) } - end - - trigger(:after_suites, suites, type) - end - end - - def _run_suite(suite, tests) - unless tests.empty? - begin - self.suite_start_time = Time.now - - trigger(:before_suite, suite) - suite.startup if suite.respond_to?(:startup) - - tests.each { |test| _run_test(suite, test) } - ensure - suite.shutdown if suite.respond_to?(:shutdown) - trigger(:after_suite, suite) - end - end - end - - # - def _run_test(suite, test) - self.test_start_time = Time.now - - trigger(:before_test, suite, test) - - test_runner = TestRunner.new(suite, test) - test_runner.run - add_test_result(suite, test, test_runner) - - trigger(test_runner.result, suite, test, test_runner) - end - - # - def trigger(callback, *args) - send("tapout_#{callback}", *args) - end - - private - - # - def filtered_tests(suite, type) - filter = options[:filter] || '/./' - filter = Regexp.new($1) if filter =~ /\/(.*)\// - suite.send("#{type}_methods").grep(filter) - end - - # - def suites_of_type(type) - TestCase.send("#{type}_suites") - end - - # - def add_test_result(suite, test, test_runner) - self.report[suite] ||= {} - self.report[suite][test.to_sym] = test_runner - - self.assertion_count += test_runner.assertions - - case test_runner.result - when :skip then self.skips += 1 - when :failure then self.failures += 1 - when :error then self.errors += 1 - end - end - - # - def fix_sync - sync = output.respond_to?(:'sync=') # stupid emacs - old_sync, output.sync = output.sync, true if sync - yield - output.sync = old_sync if sync - end - - # - def tapout_before_suites(suites, type) - doc = { - 'type' => 'suite', - 'start' => self.start_time.strftime('%Y-%m-%d %H:%M:%S'), - 'count' => self.test_count, - 'seed' => 'fixme' - } - puts doc.to_yaml - end - - # - def tapout_after_suites(suites, type) - doc = { - 'type' => 'tally', - 'time' => Time.now - self.test_start_time, - 'counts' => { - 'total' => self.test_count, - 'pass' => self.test_count - self.failures - self.errors - self.skips, - 'fail' => self.failures, - 'error' => self.errors, - 'omit' => self.skips, - 'todo' => 0 # TODO: does minitest support pending tests? - } - } - puts doc.to_yaml - puts '...' - end - - # - def tapout_before_suite(suite) - doc = { - 'type' => 'case', - 'subtype' => '', - 'label' => "#{suite}", - 'level' => 0 - } - - puts doc.to_yaml - end - - # - def tapout_after_suite(suite) - end - - # - def tapout_before_test(suite, test) - end - - # - def tapout_pass(suite, test, test_runner) - doc = { - 'type' => 'test', - 'subtype' => '', - 'status' => 'pass', - #'setup': foo instance - 'label' => "#{test}", - #'expected' => 2 - #'returned' => 2 - #'file' => 'test/test_foo.rb' - #'line': 45 - #'source': ok 1, 2 - #'snippet': - # - 44: ok 0,0 - # - 45: ok 1,2 - # - 46: ok 2,4 - #'coverage': - # file: lib/foo.rb - # line: 11..13 - # code: Foo#* - 'time' => Time.now - self.suite_start_time - } - puts doc.to_yaml - end - - # - def tapout_skip(suite, test, test_runner) - e = test_runner.exeception - e_file, e_line = location(test_runner.exception) - - doc = { - 'type' => 'test', - 'subtype' => '', - 'status' => 'skip', - 'label' => "#{suite} #{test}", - #'setup' => "foo instance", - #'expected' => 2, - #'returned' => 1, - #'file' => test/test_foo.rb - #'line' => 45 - #'source' => ok 1, 2 - #'snippet' => - # - 44: ok 0,0 - # - 45: ok 1,2 - # - 46: ok 2,4 - #'coverage' => - # 'file' => lib/foo.rb - # 'line' => 11..13 - # 'code' => Foo#* - 'exception' => { - 'message' => clean_message(e.message), - 'file' => e_file, - 'line' => e_line, - #'source' => '', - 'snippet' => code_snippet(e_file, e_line), - 'backtrace' => filter_backtrace(e.backtrace) - }, - 'time' => Time.now - self.suite_start_time - } - - puts doc.to_yaml - end - - # - def tapout_failure(suite, test, test_runner) - e = test_runner.exception - e_file, e_line = location(test_runner.exception) - - doc = { - 'type' => 'test', - 'subtype' => '', - 'status' => 'fail', - 'label' => "#{suite} #{test}", - #'setup' => "foo instance", - #'expected' => 2, - #'returned' => 1, - #'file' => test/test_foo.rb - #'line' => 45 - #'source' => ok 1, 2 - #'snippet' => - # - 44: ok 0,0 - # - 45: ok 1,2 - # - 46: ok 2,4 - #'coverage' => - # 'file' => lib/foo.rb - # 'line' => 11..13 - # 'code' => Foo#* - 'exception' => { - 'message' => clean_message(e.message), - 'file' => e_file, - 'line' => e_line, - #'source' => '', - 'snippet' => code_snippet(e_file, e_line), - 'backtrace' => filter_backtrace(e.backtrace) - }, - 'time' => Time.now - self.suite_start_time - } - - puts doc.to_yaml - end - - # - def tapout_error(suite, test, test_runner) - e = test_runner.exception - e_file, e_line = location(test_runner.exception) - - doc = { - 'type' => 'test', - 'subtype' => '', - 'status' => 'error', - 'label' => "#{suite} #{test}", - #'setup' => "foo instance", - #'expected' => 2, - #'returned' => 1, - #'file' => test/test_foo.rb - #'line' => 45 - #'source' => ok 1, 2 - #'snippet' => - # - 44: ok 0,0 - # - 45: ok 1,2 - # - 46: ok 2,4 - #'coverage' => - # 'file' => lib/foo.rb - # 'line' => 11..13 - # 'code' => Foo#* - 'exception' => { - 'message' => clean_message("#{e.class}: #{e.message}"), - 'file' => e_file, - 'line' => e_line, - #'source' => '', - 'snippet' => code_snippet(e_file, e_line), - 'backtrace' => filter_backtrace(e.backtrace) - }, - 'time' => Time.now - self.suite_start_time - } - - puts doc.to_yaml - end - - # - INTERNALS = /(lib|bin)#{Regexp.escape(File::SEPARATOR)}tapout/ - - # - def filter_backtrace(bt) - bt = clean_backtrace(bt) - bt = MiniTest::filter_backtrace(bt) - bt - end - - # Clean the backtrace of any reference to ko/ paths and code. - def clean_backtrace(backtrace) - trace = backtrace.reject{ |bt| bt =~ INTERNALS } - trace = trace.map do |bt| - if i = bt.index(':in') - bt[0...i] - else - bt - end - end - trace = backtrace if trace.empty? - trace = trace.map{ |bt| bt.sub(Dir.pwd+File::SEPARATOR,'') } - trace - end - - # Returns a String of source code. - def code_snippet(file, line) - s = [] - - #case snippet - #when String - # lines = snippet.lines.to_a - # index = line - ((lines.size - 1) / 2) - # lines.each do |line| - # s << [index, line] - # index += 1 - # end - #when Array - # snippet.each do |h| - # s << [h.key, h.value] - # end - #else - ##backtrace = exception.backtrace.reject{ |bt| bt =~ INTERNALS } - ##backtrace.first =~ /(.+?):(\d+(?=:|\z))/ or return "" - #caller =~ /(.+?):(\d+(?=:|\z))/ or return "" - #source_file, source_line = $1, $2.to_i - - if File.file?(file) - source = source(file) - radius = 2 # TODO: make customizable (number of surrounding lines to show) - region = [line - radius, 1].max .. - [line + radius, source.length].min - - s = region.map do |n| - {n => source[n-1].chomp} - end - end - #end - return s - end - - # Cache source file text. This is only used if the TAP-Y stream - # doesn not provide a snippet and the test file is locatable. - def source(file) - @_source_cache[file] ||= ( - File.readlines(file) - ) - end - - # Parse source location from caller, caller[0] or an Exception object. - def parse_source_location(caller) - case caller - when Exception - trace = caller.backtrace.reject{ |bt| bt =~ INTERNALS } - caller = trace.first - when Array - caller = caller.first - end - caller =~ /(.+?):(\d+(?=:|\z))/ or return "" - source_file, source_line = $1, $2.to_i - returnf source_file, source_line - end - - # Get location of exception. - def location e # :nodoc: - last_before_assertion = "" - e.backtrace.reverse_each do |s| - break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/ - last_before_assertion = s - end - file, line = last_before_assertion.sub(/:in .*$/, '').split(':') - line = line.to_i if line - return file, line - end - - # - def clean_message(message) - message.strip #.gsub(/\s*\n\s*/, "\n") - end - - end - - - # Runner for individual MiniTest tests. - # - # You *should not* create instances of this class directly. Instances of - # {SuiteRunner} will create these and send them to the reporters. - # - # Based upon Ryan Davis of Seattle.rb's MiniTest (MIT License). - # - # @see https://github.com/seattlerb/minitest MiniTest - class TestRunner - attr_reader :suite, :test, :assertions, :result, :exception - - def initialize(suite, test) - @suite = suite - @test = test - @assertions = 0 - end - - def run - suite_instance = suite.new(test) - @result, @exception = fix_result(suite_instance.run(self)) - @assertions = suite_instance._assertions - end - - def puke(suite, test, exception) - case exception - when MiniTest::Skip then [:skip, exception] - when MiniTest::Assertion then [:failure, exception] - else [:error, exception] - end - end - - private - - def fix_result(result) - result == '.' ? [:pass, nil] : result - end - end - -end - - -=begin - - # MiniTest runner to produce tapout format test report streams. - # - class MiniRunner < ::MiniTest::Unit - - # - def initialize - #@turn_config = Turn.config - super() - - # route minitests traditional output to nowhere - # (instead of overriding #puts and #print) - @@out = ::StringIO.new - end - - # Turn calls this method to start the test run. - def start(args=[]) - # minitest changed #run in 6023c879cf3d5169953e on April 6th, 2011 - if ::MiniTest::Unit.respond_to?(:runner=) - ::MiniTest::Unit.runner = self - end - # FIXME: why isn't @test_count set? - run(args) - #return @turn_suite - end - - # Override #_run_suite to setup Turn. - def _run_suites suites, type - #@turn_suite = Turn::TestSuite.new(@turn_config.suite_name) - @tap_size = ::MiniTest::Unit::TestCase.test_suites.size - @tap_tome = Time.now - - puts { - 'type' => 'suite', - 'start' => @tap_time.strftime('%Y-%m-%d %H:%M:%S') - 'count' => @tap_size - }.to_yaml - - #if @turn_config.matchcase - # suites = suites.select{ |suite| @turn_config.matchcase =~ suite.name } - #end - - result = suites.map { |suite| _run_suite(suite, type) } - - puts { - 'type' => 'tally', - 'time' => @tap_time - Time.now, - 'counts' => { - 'total' => 2, - 'pass' => 1, - 'fail' => 1, - 'error' => 0, - 'omit' => 0, - 'todo' => 0 - } - }.to_yaml - - puts '...' - - return result - end - - # - def _run_suite suite, type - # suites are cases in minitest - @turn_case = @turn_suite.new_case(suite.name) - - filter = @turn_config.pattern || /./ - - suite.send("#{type}_methods").grep(filter).each do |test| - @turn_case.new_test(test) - end - - turn_reporter.start_case(@turn_case) - - header = "#{type}_suite_header" - puts send(header, suite) if respond_to? header - - assertions = @turn_case.tests.map do |test| - @turn_test = test - turn_reporter.start_test(@turn_test) - - inst = suite.new(test.name) #method - inst._assertions = 0 - - result = inst.run self - - if result == "." - turn_reporter.pass - end - - turn_reporter.finish_test(@turn_test) - - inst._assertions - end - - @turn_case.count_assertions = assertions.inject(0) { |sum, n| sum + n } - - turn_reporter.finish_case(@turn_case) - - return assertions.size, assertions.inject(0) { |sum, n| sum + n } - end - - # Override #puke to update Turn's internals and reporter. - def puke(klass, meth, err) - case err - when MiniTest::Skip - @turn_test.skip! - turn_reporter.skip #(e) - when MiniTest::Assertion - @turn_test.fail!(err) - turn_reporter.fail(err) - else - @turn_test.error!(err) - turn_reporter.error(err) - end - super(klass, meth, err) - end - - # To maintain compatibility with old versions of MiniTest. - # - # Hey, Ryan Davis wrote this code! - if ::MiniTest::Unit::VERSION < '2.0' - #attr_accessor :options - - # - def run(args=[]) - suites = ::MiniTest::Unit::TestCase.test_suites - return if suites.empty? - - @test_count, @assertion_count = 0, 0 - sync = @@out.respond_to? :"sync=" # stupid emacs - old_sync, @@out.sync = @@out.sync, true if sync - - results = _run_suites suites, :test #type - - @test_count = results.inject(0) { |sum, (tc, _)| sum + tc } - @assertion_count = results.inject(0) { |sum, (_, ac)| sum + ac } - - @@out.sync = old_sync if sync - - return failures + errors if @test_count > 0 # or return nil... - rescue Interrupt - abort 'Interrupted' - end - - end - - end - -end - -=end From 0b28ab68121299d849bbb6617eb5ed3a775080c9 Mon Sep 17 00:00:00 2001 From: Thomas Sawyer Date: Fri, 20 Nov 2026 17:41:10 -0500 Subject: [PATCH 2/2] Load only the parts of ANSI that are used require 'ansi' loads ansi/logger, which requires logger, and Ruby 4.0 no longer ships that as a default gem, so Tapout failed to load there under Bundler. Tapout uses String#ansi and the progress bar only. Co-Authored-By: Claude Fable 5.2 --- HISTORY.md | 2 ++ lib/tapout/reporters/abstract.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 270432d..2f3e04e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,8 @@ Changes: no longer part of Ruby. Reporter names are matched without it: a name can still be shortened to any unique beginning, as in `tapout pro`. * Work with frozen string literals. +* Work on Ruby 4.0, by loading only the parts of the ANSI library that + Tapout uses. Loading all of it fails there for want of `logger`. * Replace the old packaging (`.index`, `.gemspec`, `Assembly`, `MANIFEST`, `var/`) with a plain `tapout.gemspec`, and Travis with GitHub Actions, testing Ruby 2.7 to 4.0. diff --git a/lib/tapout/reporters/abstract.rb b/lib/tapout/reporters/abstract.rb index a480cf2..ef2a8cb 100644 --- a/lib/tapout/reporters/abstract.rb +++ b/lib/tapout/reporters/abstract.rb @@ -1,4 +1,6 @@ -require 'ansi' +# Only the parts of ANSI that are used: all of it brings in its logger, +# which needs the logger library that Ruby 4.0 no longer ships. +require 'ansi/core' module Tapout