#!/usr/bin/env ruby

outputfile = File.open(ARGV.shift, "w")
inputfiles = ARGV

outputfile.puts "// file: all.c"
outputfile.puts "// autogenerated from *_test.c in test/ by all.rb"
outputfile.puts "// don't modify this file - it will be overwritten"
outputfile.puts "// this script assumes it's begin ran from within the test/ directory"

tests = []

outputfile.puts "#define EULER_TEST_MAIN"
outputfile.puts "#include <euler/test.h>"
outputfile.puts

inputfiles.each do |inputfile|
  input = File.read(inputfile)
  input.scan(/void\s+(\w+)/).each do |match|
    tests << match[0]
  end
end

tests.each do |test|
  outputfile.puts "void #{test}();"
end

outputfile.puts

outputfile.puts "TESTS() {"
tests.each do |test|
  outputfile.puts "  RUN(#{test});"
end
outputfile.puts "}"
