repubmark/test.rb
2024-09-28 03:10:33 +04:00

49 lines
1.3 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'open3'
EXE = File.expand_path('exe/repubmark', __dir__).freeze
EXAMPLES = File.expand_path('examples', __dir__).freeze
EXAMPLES_GLOB = File.expand_path('examples/*.repub', __dir__).freeze
CONFIG = File.expand_path('examples/config.yml', __dir__).freeze
PROFILES = [
%w[summary_plain summary.txt],
%w[http html],
%w[gemini gmi],
%w[chapters chapters.json],
].map(&:freeze).freeze
Dir[EXAMPLES_GLOB].each do |example_filename|
example = File.read example_filename
PROFILES.each do |profile_name, expected_ext|
expected_filename = "#{example_filename[...-6]}.#{expected_ext}"
expected = File.read expected_filename
puts '=' * 80
puts "Config: #{CONFIG}"
puts "Example: #{example_filename}"
puts "Profile: #{profile_name}"
puts "Expected: #{expected_filename}"
puts '-' * 80
puts example.strip
puts '-' * 80
puts expected.strip
stdin, stdout, wait_thr = Open3.popen2 EXE, CONFIG, profile_name
stdin.puts example
stdin.close
result = stdout.read
stdout.close
raise 'Template engine error' unless wait_thr.value.success?
next if result == expected
puts '-' * 80
puts result.strip
puts '=' * 80
raise 'Invalid output'
end
end
puts '=' * 80