#!/usr/bin/env ruby # frozen_string_literal: true require 'open3' 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 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