2024-02-24 23:54:16 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'open3'
|
|
|
|
|
2024-10-15 14:40:19 -04:00
|
|
|
ROOT = File.expand_path('..', __dir__).freeze
|
|
|
|
|
|
|
|
EXE = File.expand_path('exe/repubmark', ROOT).freeze
|
|
|
|
EXAMPLES = File.expand_path('examples', ROOT).freeze
|
|
|
|
EXAMPLES_GLOB = File.expand_path('examples/*.repub', ROOT).freeze
|
|
|
|
CONFIG = File.expand_path('examples/config.yml', ROOT).freeze
|
2024-02-24 23:54:16 -05:00
|
|
|
|
|
|
|
PROFILES = [
|
2024-02-25 02:43:16 -05:00
|
|
|
%w[summary_plain summary.txt],
|
2024-02-24 23:54:16 -05:00
|
|
|
%w[http html],
|
|
|
|
%w[gemini gmi],
|
2024-09-27 18:49:30 -04:00
|
|
|
%w[chapters chapters.json],
|
2024-02-24 23:54:16 -05:00
|
|
|
].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
|