Files
jekyll-build-pages/bin/compare_expected_output
Jess Bees 5a78e45c89 Support recording expected output in an action!
the `record_expected_output` script now uses the `act` utility
(https://github.com/nektos/act) to run this repo's action in a container
as github actions would.

You can now pass one argument to that, `local`, to go back to running
`github-pages` on your local ruby install. (I removed the `.ruby-version`
file since we don't *need* to record using the local env anymore, so
make sure that you're on Ruby 2.7.4)

This eliminates the inconsistency between recorded output and generated
output on actions, so we don't need to ignore any lines in `diff` anymore.
2022-02-02 12:50:26 -05:00

36 lines
1.1 KiB
Ruby
Executable File

#! /usr/bin/env ruby
require "pathname"
require "shellwords"
project_path = ARGV[0]
Dir.chdir(project_path)
expected_files = Dir["_expected/**/*"].select { |path| File.file?(path) }.map { |path| Pathname.new(path).relative_path_from("_expected").to_s }
actual_files = Dir["_site/**/*"].select { |path| File.file?(path) }.map { |path| Pathname.new(path).relative_path_from("_site").to_s }
differences = []
expected_files.each do |expected_file|
if actual_files.include?(expected_file)
diff = `diff #{Shellwords.escape(File.join("_expected", expected_file))} #{Shellwords.escape(File.join("_site", expected_file))}`
if !$?.success?
differences << "Expected output of #{expected_file} differs:\n#{diff}"
end
else
differences << "Missing expected file: #{expected_file}"
end
end
unexpected_files = actual_files - expected_files
unexpected_files.each do |unexpected_file|
differences << "Unexpected file: #{unexpected_file}"
end
if !differences.empty?
STDERR.puts "Differences between expected and actual outputs:"
differences.each { |diff| STDERR.puts(diff) }
exit(1)
end