{-# OPTIONS -fallow-overlapping-instances #-} module Main where import qualified Test.FIT.ParseTest as ParseTest import qualified Test.FIT.FixtureTest as FixtureTest import qualified Test.FIT.Parse as Parser import qualified Test.FIT.Fixture as Fixture import qualified Test.FIT.LoadFixture as Loader import Test.HUnit import System.IO import System.Directory import System.Time import System.Environment import Data.HashTable as Hash {- TODO: - fix Parse string util functions to be 0-indexed, not 1-indexed - tests for LoadFixture.makeModulePath -} main = do prog <- getProgName args <- getArgs case args of [i, o] -> fileRunner i o "" [i, o, p] -> fileRunner i o p [a] | a == "runtests" -> runTests otherwise -> do putStrLn "usage: " putStrLn $ " " ++ prog ++ " runtests" putStrLn $ " " ++ prog ++ " html-input-file html-output-file [module-root-path]" runTests = do _ <- runTestTT ParseTest.parsingTests _ <- runTestTT FixtureTest.fixtureTests return () fileRunner inFile outFile path = do inputHtml <- readFile inFile case Parser.parse inputHtml ["table", "tr", "td"] 0 0 of Left e -> error $ "parse failed on " ++ inFile Right p -> do summary <- Hash.new (==) hashString update summary "input file" inFile update summary "output file" outFile ct <- getModificationTime inFile calTime <- toCalendarTime ct update summary "input last updated" (calendarTimeToString calTime) output <- Loader.doTables p summary path putStrLn "main: output parse" writeFile outFile (Parser.printParse output)