From 328b63a5b4a83070b5381ed6a9de4d454ea65e9e Mon Sep 17 00:00:00 2001 From: Philip Harrison Date: Wed, 16 Jun 2021 10:12:35 +0100 Subject: [PATCH] Raise on ruby 2.7 deprecation warnings Break tests if we introduce any ruby 2.7 deprecation warnings. --- .github/workflows/ci.yml | 1 + common/spec/spec_helper.rb | 1 + common/spec/warning_monkey_patch.rb | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 common/spec/warning_monkey_patch.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 842c71452e..0088078d0f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,7 @@ jobs: run: | docker run \ --env "CI=true" \ + --env "RAISE_ON_WARNINGS=true" \ --env "DEPENDABOT_TEST_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}" \ --env "SUITE_NAME=${{ matrix.suite.name }}" \ --rm "$CORE_CI_IMAGE" bash -c \ diff --git a/common/spec/spec_helper.rb b/common/spec/spec_helper.rb index b0bfa57f4f..b3184786d6 100644 --- a/common/spec/spec_helper.rb +++ b/common/spec/spec_helper.rb @@ -10,6 +10,7 @@ require "dependabot/dependency_file" require_relative "dummy_package_manager/dummy" +require_relative "warning_monkey_patch" if ENV["COVERAGE"] SimpleCov::Formatter::Console.output_style = "block" diff --git a/common/spec/warning_monkey_patch.rb b/common/spec/warning_monkey_patch.rb new file mode 100644 index 0000000000..c7699f25a6 --- /dev/null +++ b/common/spec/warning_monkey_patch.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +ALLOW_PATTERNS = [ + # Ignore parser warnings for ruby 2.7 minor version mismatches + # TODO: Fix these by upgrading to ruby 2.7.3 (requires ubuntu upgrade) + %r{parser/current is loading parser/ruby27}, + /2.7.\d-compliant syntax, but you are running 2.7.\d/, + %r{whitequark/parser} +].freeze + +# Called internally by Ruby for all warnings +module Warning + def self.warn(message) + $stderr.print(message) + + raise message if ENV["RAISE_ON_WARNINGS"].to_s == "true" && ALLOW_PATTERNS.none? { |pattern| pattern =~ message } + + return unless ENV["DEBUG_WARNINGS"] + + warn caller + $stderr.puts + end +end