module PDQTest::PDQTest1x

Constants

PDQTEST_FILES

Urgh… I wish I'd put my own magic marker in these files… then I would have been able to find them easily(!) This is a list of known PDQTest integrations and their MD5 sums. Thankfully I didn't make _too many_ upgrades

PDQTEST_GEM
PDQTEST_RUBYGEMS

These plus the `pdqtest` gem are the only gems that PDQTest 1x ever used If we only see these gems and our own, then we are almost certainly safe to replace the file with the PDK version List was extracted with some awk-foo gist.github.com/GeoffWilliams/21de190c5f6285b68f777885d92dba72

Public Class Methods

is_pdqtest_file(f) click to toggle source
# File lib/pdqtest/pdqtest1x.rb, line 63
def self.is_pdqtest_file(f)
  detected = false

  if PDQTEST_FILES.include?(f)
    if File.exist? f
      # check for known PDQTest files spanning all versions
      project_md5 = Digest::MD5.file(f).hexdigest
      if PDQTEST_FILES[f].include?(project_md5)
        $logger.debug("File at #{f} matches a known PDQTest 1x file")
        detected = true
      end
    else
      $logger.debug "Missing PDQTest file #{f}"
      detected = false
    end
  elsif f == "Gemfile"
    if File.exist? f
      # to detect if PDQTest is the Gemfile, just look for the gem itself
      if File.readlines(f).grep(PDQTEST_GEM).any?
        # this project previously used PDQTest, now check to see if there
        # are any unknown gems in the file
        $logger.debug("Detected PDQTest 1.x in your Gemfile")
        detected = true
        project_gems = File.readlines(f).grep(/^\s*gem /)
        project_gems.reject { |line|
          line =~ PDQTEST_GEM
        }.each { |project_gem|
          found = false
          PDQTEST_RUBYGEMS.each { |pdqtest_gem|
            if project_gem =~ pdqtest_gem
              $logger.debug "known gem detected: #{project_gem.strip}"
              found = true
            end
          }
          if ! found
            $logger.error("unknown gem line in your Gemfile: '#{project_gem.strip}'")
            detected = false
          end
        }
      end
    else
      $logger.debug("missing Gemfile: #{f}")
      detected = false
    end
  else
    raise("File #{f} was never managed by PDQTest, why are you testing it?")
  end

  detected
end
was_pdqtest_file(f) click to toggle source

Did PDQTest ever manage this file?

# File lib/pdqtest/pdqtest1x.rb, line 54
def self.was_pdqtest_file(f)
  [
      ".rspec",
      "Gemfile",
      "Rakefile",
      "spec/fixtures",
  ].include? f
end