From 882e49b8d9173ddfe760b820f419e3d1bf8d16f3 Mon Sep 17 00:00:00 2001 From: Andrew Haines Date: Fri, 8 Jun 2018 09:29:38 +0100 Subject: [PATCH 1/2] Create gem --- .gitignore | 4 ++ .rubocop.yml | 35 ++++++++++++ .ruby-version | 1 + .travis.yml | 6 ++ .yardopts | 5 ++ CODE_OF_CONDUCT.md | 53 +++++++++++++++++ Gemfile | 5 ++ Gemfile.lock | 54 +++++++++++++++++ README.md | 51 +++++++++++++++++ Rakefile | 18 ++++++ bin/bundle | 105 ++++++++++++++++++++++++++++++++++ bin/console | 8 +++ bin/rake | 29 ++++++++++ bin/setup | 4 ++ lib/rake/multilogs.rb | 9 +++ lib/rake/multilogs/version.rb | 8 +++ rake-multilogs.gemspec | 36 ++++++++++++ test/rake/multilogs_test.rb | 8 +++ test/test_helper.rb | 4 ++ 19 files changed, 443 insertions(+) create mode 100644 .gitignore create mode 100644 .rubocop.yml create mode 100644 .ruby-version create mode 100644 .travis.yml create mode 100644 .yardopts create mode 100644 CODE_OF_CONDUCT.md create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 Rakefile create mode 100755 bin/bundle create mode 100755 bin/console create mode 100755 bin/rake create mode 100755 bin/setup create mode 100644 lib/rake/multilogs.rb create mode 100644 lib/rake/multilogs/version.rb create mode 100644 rake-multilogs.gemspec create mode 100644 test/rake/multilogs_test.rb create mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f97cc22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.bundle/ +/.yardoc/ +/doc/ +/pkg/ diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6a3ce9f --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,35 @@ +AllCops: + TargetRubyVersion: 2.3 + Exclude: + - bin/bundle + - bin/rake + - vendor/bundle/**/* + +Metrics/LineLength: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Style/BlockDelimiters: + EnforcedStyle: semantic + +Style/Documentation: + Exclude: + - test/**/* + +Style/HashSyntax: + Exclude: + - Rakefile + +Style/Lambda: + EnforcedStyle: literal + +Style/StringLiterals: + EnforcedStyle: double_quotes + +Style/SymbolArray: + EnforcedStyle: brackets + +Style/WordArray: + EnforcedStyle: brackets diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..73462a5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.5.1 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f5a64ed --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +sudo: false +language: ruby +rvm: + - 2.3 + - 2.4 + - 2.5 diff --git a/.yardopts b/.yardopts new file mode 100644 index 0000000..d4da7ed --- /dev/null +++ b/.yardopts @@ -0,0 +1,5 @@ +--markup markdown +--no-private +--plugin relative_markdown_links +- +*.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..59ac70b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,53 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. +Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. +Representation of a project may be further defined and clarified by project maintainers. + + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at andrew@haines.org.nz. +All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. +The project team is obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org) [version 1.4](http://contributor-covenant.org/version/1/4/). diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..be173b2 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..590b8f2 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,54 @@ +PATH + remote: . + specs: + rake-multilogs (0.1.0) + rake (~> 12.1) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.0) + coderay (1.1.2) + jaro_winkler (1.5.1) + method_source (0.9.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + parallel (1.12.1) + parser (2.5.1.0) + ast (~> 2.4.0) + powerpack (0.1.2) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + rainbow (3.0.0) + rake (12.3.1) + rubocop (0.57.1) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.9.0) + unicode-display_width (1.4.0) + yard (0.9.14) + yard-relative_markdown_links (0.1.2) + nokogiri (~> 1.8.1) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.16) + minitest (~> 5.11) + pry (~> 0.11) + rake-multilogs! + rubocop (~> 0.57.1) + yard (~> 0.9) + yard-relative_markdown_links (~> 0.1) + +BUNDLED WITH + 1.16.2 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e267685 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Rake::Multilogs + +Rake multitask logs can be confusing, with output from each of the concurrently-running tasks being interleaved. +`Rake::Multilogs` untangles the mess by capturing each task's output and displaying it after all the tasks are finished. + + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem "rake-multilogs" +``` + +And then execute: + +```console +$ bundle install +``` + +Or install it yourself as: + +```console +$ gem install rake-multilogs +``` + + +## Usage + +TODO: Write usage instructions here + + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. +Then, run `bin/rake test` to run the tests. +You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bin/rake install`. +To release a new version, update the version number in `lib/rake/multilogs/version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [RubyGems](https://rubygems.org). + + +## Contributing + +Bug reports and pull requests are welcome [on GitHub](https://github.com/haines/rake-multilogs). +This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md). + + +## License + +© 2018 Andrew Haines, released under the [MIT license](LICENSE.md). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..5f9e190 --- /dev/null +++ b/Rakefile @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rake/testtask" +require "rubocop/rake_task" +require "yard" + +Rake::TestTask.new do |task| + task.test_files = FileList["test/**/*_test.rb"] +end + +RuboCop::RakeTask.new + +desc "Generate documentation" +YARD::Rake::YardocTask.new :doc +CLOBBER << "doc/" + +task :default => [:doc, :rubocop, :test] diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..524dfd3 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,105 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= begin + env_var_version || cli_arg_version || + lockfile_version || "#{Gem::Requirement.default}.a" + end + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + # must dup string for RG < 1.8 compatibility + activate_bundler(bundler_version.dup) + end + + def activate_bundler(bundler_version) + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") + bundler_version = "< 2" + end + gem_error = activation_error_handling do + gem "bundler", bundler_version + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..e37ab5d --- /dev/null +++ b/bin/console @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "rake/multilogs" + +require "pry" +Pry.start diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..9275675 --- /dev/null +++ b/bin/rake @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path("../bundle", __FILE__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..6e2106c --- /dev/null +++ b/bin/setup @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail + +bundle install diff --git a/lib/rake/multilogs.rb b/lib/rake/multilogs.rb new file mode 100644 index 0000000..830f9a1 --- /dev/null +++ b/lib/rake/multilogs.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "rake/multilogs/version" + +module Rake + # Capture log output from Rake multitasks. + module Multilogs + end +end diff --git a/lib/rake/multilogs/version.rb b/lib/rake/multilogs/version.rb new file mode 100644 index 0000000..e34ed8c --- /dev/null +++ b/lib/rake/multilogs/version.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Rake + module Multilogs + # Current version of the rake-multilogs gem. + VERSION = "0.1.0" + end +end diff --git a/rake-multilogs.gemspec b/rake-multilogs.gemspec new file mode 100644 index 0000000..136c507 --- /dev/null +++ b/rake-multilogs.gemspec @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +lib = File.expand_path("lib", __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +require "rake/multilogs/version" + +Gem::Specification.new do |spec| + spec.name = "rake-multilogs" + spec.version = Rake::Multilogs::VERSION + spec.authors = ["Andrew Haines"] + spec.email = ["andrew@haines.org.nz"] + + spec.summary = "Capture log output from Rake multitasks" + spec.description = <<~DESCRIPTION + Rake multitask logs can be confusing, with interleaved output from all parallel tasks. + Rake::Multilogs untangles the mess by capturing each task's output and displaying it after all the tasks are finished. + DESCRIPTION + + spec.homepage = "https://github.com/haines/rake-multilogs" + spec.license = "MIT" + + spec.files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0").reject { |path| path.match(%r{^test/}) } } + spec.require_paths = ["lib"] + + spec.metadata["yard.run"] = "yri" + + spec.add_dependency "rake", "~> 12.1" + + spec.add_development_dependency "bundler", "~> 1.16" + spec.add_development_dependency "minitest", "~> 5.11" + spec.add_development_dependency "pry", "~> 0.11" + spec.add_development_dependency "rubocop", "~> 0.57.1" + spec.add_development_dependency "yard", "~> 0.9" + spec.add_development_dependency "yard-relative_markdown_links", "~> 0.1" +end diff --git a/test/rake/multilogs_test.rb b/test/rake/multilogs_test.rb new file mode 100644 index 0000000..0be3c8a --- /dev/null +++ b/test/rake/multilogs_test.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Rake + class MultilogsTest < Minitest::Test + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..400b676 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +require "rake/multilogs" +require "minitest/autorun" From 1b0a834bc4c1b8418f88433277aa46ef8860571a Mon Sep 17 00:00:00 2001 From: Andrew Haines Date: Fri, 8 Jun 2018 18:23:09 +0100 Subject: [PATCH 2/2] Group multitask output by task --- README.md | 18 +++++++- lib/rake/multilogs.rb | 17 ++++++- lib/rake/multilogs/fork.rb | 49 ++++++++++++++++++++ lib/rake/multilogs/forks.rb | 27 +++++++++++ lib/rake/multilogs/task.rb | 20 ++++++++ test/rake/multilogs/output_test.rb | 73 ++++++++++++++++++++++++++++++ test/rake/multilogs_test.rb | 8 ---- test/test_helper.rb | 31 ++++++++++++- 8 files changed, 231 insertions(+), 12 deletions(-) create mode 100644 lib/rake/multilogs/fork.rb create mode 100644 lib/rake/multilogs/forks.rb create mode 100644 lib/rake/multilogs/task.rb create mode 100644 test/rake/multilogs/output_test.rb delete mode 100644 test/rake/multilogs_test.rb diff --git a/README.md b/README.md index e267685..58032d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ # Rake::Multilogs -Rake multitask logs can be confusing, with output from each of the concurrently-running tasks being interleaved. +[![Docs](https://img.shields.io/badge/docs-github.io-blue.svg?style=flat-square)](https://haines.github.io/rake-multilogs/) +[![Gem](https://img.shields.io/gem/v/rake-multilogs.svg?style=flat-square)](https://rubygems.org/gems/rake-multilogs) +[![GitHub](https://img.shields.io/badge/github-haines%2Frake--multilogs-blue.svg?style=flat-square)](https://github.com/haines/rake-multilogs) +[![License](https://img.shields.io/github/license/haines/rake-multilogs.svg?style=flat-square)](https://github.com/haines/rake-multilogs/blob/master/LICENSE.md) +[![Travis](https://img.shields.io/travis/haines/rake-multilogs.svg?style=flat-square)](https://travis-ci.org/haines/rake-multilogs) + + +Rake [multitask](https://ruby.github.io/rake/Rake/DSL.html#method-i-multitask) logs can be confusing, with output from each of the concurrently-running tasks being interleaved. `Rake::Multilogs` untangles the mess by capturing each task's output and displaying it after all the tasks are finished. @@ -24,10 +31,17 @@ Or install it yourself as: $ gem install rake-multilogs ``` +JRuby and Windows are not supported, because [`Process.fork`](https://ruby-doc.org/core/Process.html#method-c-fork) is unavailable. +`Rake::Multilogs` will gracefully fall back to the default (interleaved) output on those platforms. + ## Usage -TODO: Write usage instructions here +Add this line to your application's Rakefile: + +```ruby +require "rake/multilogs" +``` ## Development diff --git a/lib/rake/multilogs.rb b/lib/rake/multilogs.rb index 830f9a1..d53e17b 100644 --- a/lib/rake/multilogs.rb +++ b/lib/rake/multilogs.rb @@ -1,9 +1,24 @@ # frozen_string_literal: true +require "rake" +require "rake/multilogs/fork" +require "rake/multilogs/forks" +require "rake/multilogs/task" require "rake/multilogs/version" module Rake - # Capture log output from Rake multitasks. + # `Rake::Multilogs` groups multitask output by task, displaying it when all + # tasks have completed, rather than the default behavior of displaying output + # immediately (which means that output from different tasks becomes + # confusingly interleaved). + # + # This requires `Process.fork`, so is not supported on JRuby or Windows. module Multilogs end end + +if Process.respond_to?(:fork) + Rake::Task.prepend Rake::Multilogs::Task +else + warn "Rake::Multilogs is disabled because Process.fork is not available on this platform" +end diff --git a/lib/rake/multilogs/fork.rb b/lib/rake/multilogs/fork.rb new file mode 100644 index 0000000..10fb1ae --- /dev/null +++ b/lib/rake/multilogs/fork.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Rake + module Multilogs + # @private + class Fork + def initialize(task:, args:, invocation_chain:) + @task = task + @args = args + @invocation_chain = invocation_chain + end + + def invoke + @reader, @writer = IO.pipe + @pid = fork { invoke_in_child_process } + @writer.close + end + + def wait + _, @status = Process.wait2(@pid) + end + + def report + puts @reader.read + end + + def failed? + !@status.success? + end + + def to_s + @task.to_s + end + + private + + def invoke_in_child_process + @reader.close + [STDOUT, STDERR].each do |stream| + stream.reopen @writer + end + + @task.application.standard_exception_handling do + @task.send :invoke_with_call_chain, @args, @invocation_chain + end + end + end + end +end diff --git a/lib/rake/multilogs/forks.rb b/lib/rake/multilogs/forks.rb new file mode 100644 index 0000000..d62ab3e --- /dev/null +++ b/lib/rake/multilogs/forks.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Rake + module Multilogs + # @private + class Forks + def initialize(tasks:, args:, invocation_chain:) + @forks = tasks.map { |task| + Fork.new( + task: task, + args: args.new_scope(task.arg_names), + invocation_chain: invocation_chain + ) + } + end + + def invoke + @forks + .each(&:invoke) + .each(&:wait) + .each(&:report) + + abort if @forks.any?(&:failed?) + end + end + end +end diff --git a/lib/rake/multilogs/task.rb b/lib/rake/multilogs/task.rb new file mode 100644 index 0000000..86e186d --- /dev/null +++ b/lib/rake/multilogs/task.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Rake + module Multilogs + # Monkey-patches `Rake::Task` to group multitask output by task and display + # it when all tasks have completed. + module Task + # Invoke all the prerequisites of a task in parallel, grouping output by + # task and displaying it when all tasks have completed. + # @return [void] + def invoke_prerequisites_concurrently(task_args, invocation_chain) + Forks.new( + tasks: prerequisite_tasks, + args: task_args, + invocation_chain: invocation_chain + ).invoke + end + end + end +end diff --git a/test/rake/multilogs/output_test.rb b/test/rake/multilogs/output_test.rb new file mode 100644 index 0000000..ee72a0f --- /dev/null +++ b/test/rake/multilogs/output_test.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require_relative "../../test_helper" + +module Rake + module Multilogs + class OutputTest < Test + def test_group_output_by_task + output, status = rake <<~RAKEFILE + tasks = [:one, :two] + + tasks.each do |name| + task name do + 3.times do + snooze + puts name + end + end + end + + multitask :default => tasks + RAKEFILE + + assert_equal <<~OUTPUT, output + one + one + one + two + two + two + OUTPUT + + assert status.success? + end + + def test_abort_on_failure + output, status = rake <<~RAKEFILE + tasks = [:one, :two] + + tasks.each do |name| + task name do + 3.times do + snooze + puts name + end + raise "\#{name} failed!" + end + end + + multitask :default => tasks + RAKEFILE + + assert_match <<~OUTPUT, output + one + one + one + rake aborted! + one failed! + OUTPUT + + assert_match <<~OUTPUT, output + two + two + two + rake aborted! + two failed! + OUTPUT + + refute status.success? + end + end + end +end diff --git a/test/rake/multilogs_test.rb b/test/rake/multilogs_test.rb deleted file mode 100644 index 0be3c8a..0000000 --- a/test/rake/multilogs_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -module Rake - class MultilogsTest < Minitest::Test - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 400b676..0b8f460 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,33 @@ # frozen_string_literal: true -require "rake/multilogs" require "minitest/autorun" +require "open3" +require "rake/multilogs" + +module Rake + module Multilogs + class Test < Minitest::Test + def rake(rakefile) + in_tmpdir { + File.write "Rakefile", <<~RAKEFILE + require "rake/multilogs" + + def snooze + sleep rand(0.01..0.1) + end + + #{rakefile} + RAKEFILE + + Open3.capture2e("rake") + } + end + + private + + def in_tmpdir(&block) + Dir.mktmpdir("rake-multilogs-test") { |dir| Dir.chdir(dir, &block) } + end + end + end +end