Skip to content
Snippets Groups Projects
Commit 0c38cf17 authored by BinderDavid's avatar BinderDavid
Browse files

Add markup tests

parent d1780eb2
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,7 @@ test-suite hpc-test
ShowTix.Tests
Report.Tests
Version.Tests
Markup.Tests
Map.Tests
Sum.Tests
Combine.Tests
......
......@@ -6,6 +6,7 @@ import ShowTix.Tests (showTixTests)
import Report.Tests (reportTests)
import Version.Tests (versionTests)
import Map.Tests (mapTests)
import Markup.Tests (markupTests)
import Sum.Tests (sumTests)
import Combine.Tests (combineTests)
......@@ -13,4 +14,4 @@ main :: IO ()
main = defaultMain tests
tests :: TestTree
tests = testGroup "hpc" [ ghcTests, showTixTests, reportTests, versionTests, mapTests, sumTests, combineTests]
tests = testGroup "hpc" [ ghcTests, showTixTests, reportTests, versionTests, mapTests, sumTests, combineTests, markupTests]
module Markup.Tests (markupTests) where
import System.Process
import Control.Monad (void)
import qualified System.FilePath as FP
import Test.Tasty (TestTree, testGroup)
import qualified Data.ByteString.Lazy.UTF8 as BS
import Test.Tasty.Golden (goldenVsString, goldenVsFile)
import Utils (runCommands)
import Data.List (intercalate)
inputBaseDir :: FilePath
inputBaseDir = FP.joinPath ["test", "Markup", "input"]
goldBaseDir :: FilePath
goldBaseDir = FP.joinPath ["test", "Markup", "gold"]
-- | Tests of the "hpc markup" subcommand
markupTests :: TestTree
markupTests = testGroup "markup" [helpTextTest, recipTest, recipTestIndex]
helpTextTest :: TestTree
helpTextTest = goldenVsString "Help" (goldBaseDir FP.</> "Help.stdout") go
where
go :: IO BS.ByteString
go = runCommands "." ["hpc help markup"]
-- | Remove all generated *.html files in the Recip subdirectory
rmHtml :: IO ()
rmHtml = void $ readCreateProcess ((shell "rm -r *.html") { cwd = Just(inputBaseDir FP.</> "Recip") }) ""
rm :: [FilePath] -> IO ()
rm files = void $ readCreateProcess ((shell (intercalate " && " . map ("rm -r " <>) $ files)) { cwd = Just (inputBaseDir FP.</> "Recip")}) ""
recipTest :: TestTree
recipTest = goldenVsString "RecipStdout" (goldBaseDir FP.</> "Recip.stdout") go
where
go :: IO BS.ByteString
go = runCommands (inputBaseDir FP.</> "Recip") ["hpc markup Recip.tix"] <* rmHtml
recipTestIndex :: TestTree
recipTestIndex = goldenVsFile "RecipIndexHtml" (goldBaseDir FP.</> "hpc_index.html") (inputBaseDir FP.</> "Recip" FP.</> "hpc_index.html") go
where
go :: IO ()
go = do
_ <- runCommands (inputBaseDir FP.</> "Recip") ["hpc markup Recip.tix"]
rm ["hpc_index_alt.html", "hpc_index_fun.html", "hpc_index_exp.html", "Main.hs.html"]
pure ()
\ No newline at end of file
Usage: hpc markup [OPTION] .. <TIX_FILE> [<MODULE> [<MODULE> ..]]
Markup Haskell source with program coverage
Options:
--exclude=[PACKAGE:][MODULE] exclude MODULE and/or PACKAGE
--include=[PACKAGE:][MODULE] include MODULE and/or PACKAGE
--srcdir=DIR path to source directory of .hs files
multi-use of srcdir possible
--hpcdir=DIR append sub-directory that contains .mix files
default .hpc [rarely used]
--reset-hpcdirs empty the list of hpcdir's
[rarely used]
--fun-entry-count show top-level function entry counts
--highlight-covered highlight covered code, rather that code gaps
--destdir=DIR path to write output to
--verbosity=[0-2] verbosity level, 0-2
default 1
Writing: Main.hs.html
Writing: hpc_index.html
Writing: hpc_index_fun.html
Writing: hpc_index_alt.html
Writing: hpc_index_exp.html
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">table.bar { background-color: #f25913; }
td.bar { background-color: #60de51; }
td.invbar { background-color: #f25913; }
table.dashboard { border-collapse: collapse ; border: solid 1px black }
.dashboard td { border: solid 1px black }
.dashboard th { border: solid 1px black }
</style>
</head><body><table class="dashboard" width="100%" border=1>
<tr><th rowspan=2><a href="hpc_index.html">module</a></th><th colspan=3><a href="hpc_index_fun.html">Top Level Definitions</a></th><th colspan=3><a href="hpc_index_alt.html">Alternatives</a></th><th colspan=3><a href="hpc_index_exp.html">Expressions</a></th></tr><tr><th>%</th><th colspan=2>covered / total</th><th>%</th><th colspan=2>covered / total</th><th>%</th><th colspan=2>covered / total</th></tr><tr>
<td>&nbsp;&nbsp;<tt>module <a href="Main.hs.html">Main</a></tt></td>
<td align="right">100%</td><td>5/5</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="100%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td><td align="right">88%</td><td>8/9</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="88%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td><td align="right">96%</td><td>94/97</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="96%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td></tr>
<tr></tr><tr style="background: #e0e0e0">
<th align=left>&nbsp;&nbsp;Program Coverage Total</tt></th>
<td align="right">100%</td><td>5/5</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="100%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td><td align="right">88%</td><td>8/9</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="88%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td><td align="right">96%</td><td>94/97</td><td width=100><table cellpadding=0 cellspacing=0 width="100" class="bar"><tr><td><table cellpadding=0 cellspacing=0 width="96%"><tr><td height=12 class="bar"></td></tr></table></td></tr></table></td></tr>
</table></body></html>
Mix "Recip.hs" 2023-10-06 14:57:37.985747475 UTC 1606722211 8 [(18:21-18:21,ExpBox False),(18:24-18:24,ExpBox False),(18:21-18:24,BinBox GuardBinBox True),(18:21-18:24,BinBox GuardBinBox False),(18:21-18:24,ExpBox False),(18:33-18:33,ExpBox True),(19:21-19:29,BinBox GuardBinBox True),(19:21-19:29,BinBox GuardBinBox False),(19:21-19:29,ExpBox False),(19:33-19:33,ExpBox False),(19:46-19:46,ExpBox False),(19:48-19:49,ExpBox False),(19:37-19:49,ExpBox False),(19:33-19:49,ExpBox True),(18:1-19:49,TopLevelBox ["position"]),(14:13-14:13,ExpBox False),(14:15-14:16,ExpBox False),(14:12-14:17,ExpBox False),(14:29-14:29,ExpBox False),(14:12-14:29,ExpBox False),(15:28-15:28,ExpBox False),(15:30-15:30,ExpBox False),(15:33-15:33,ExpBox False),(15:35-15:36,ExpBox False),(15:32-15:37,ExpBox False),(15:21-15:37,ExpBox False),(10:17-10:17,ExpBox False),(10:26-10:27,ExpBox False),(10:17-10:27,BinBox GuardBinBox True),(10:17-10:27,BinBox GuardBinBox False),(10:17-10:27,ExpBox False),(10:32-10:33,ExpBox False),(10:45-10:45,ExpBox False),(10:47-10:48,ExpBox False),(10:36-10:48,ExpBox False),(10:31-10:49,ExpBox True),(11:17-11:17,ExpBox False),(11:22-11:22,ExpBox False),(11:17-11:22,BinBox GuardBinBox True),(11:17-11:22,BinBox GuardBinBox False),(11:17-11:22,ExpBox False),(11:37-11:37,ExpBox False),(11:32-11:37,ExpBox False),(11:40-11:40,ExpBox False),(11:31-11:41,ExpBox True),(12:17-12:17,ExpBox False),(12:22-12:22,ExpBox False),(12:17-12:22,BinBox GuardBinBox True),(12:17-12:22,BinBox GuardBinBox False),(12:17-12:22,ExpBox False),(12:37-12:37,ExpBox False),(12:32-12:37,ExpBox False),(12:42-12:47,ExpBox False),(12:32-12:47,ExpBox False),(12:50-12:54,ExpBox False),(12:31-12:55,ExpBox True),(10:1-15:37,TopLevelBox ["divide"]),(8:28-8:28,ExpBox False),(8:30-8:30,ExpBox False),(8:32-8:33,ExpBox False),(8:21-8:33,ExpBox False),(4:16-4:16,ExpBox False),(4:20-4:20,ExpBox False),(4:16-4:20,BinBox GuardBinBox True),(4:16-4:20,BinBox GuardBinBox False),(4:16-4:20,ExpBox False),(4:25-4:27,ExpBox False),(4:31-4:33,ExpBox False),(4:37-4:42,ExpBox False),(4:31-4:42,ExpBox False),(4:25-4:42,ExpBox False),(4:45-4:49,ExpBox False),(4:24-4:50,ExpBox True),(5:16-5:24,BinBox GuardBinBox True),(5:16-5:24,BinBox GuardBinBox False),(5:16-5:24,ExpBox False),(6:15-6:63,ExpBox False),(5:28-6:63,ExpBox True),(4:1-8:33,TopLevelBox ["reciprocal"]),(27:23-27:23,ExpBox False),(27:12-27:23,ExpBox False),(26:14-26:14,ExpBox False),(26:7-26:14,ExpBox False),(26:18-26:18,ExpBox False),(26:7-26:18,ExpBox False),(26:3-26:18,LocalBox ["showRecip","p"]),(23:3-23:6,ExpBox False),(23:16-23:16,ExpBox False),(23:11-23:16,ExpBox False),(23:21-23:25,ExpBox False),(24:6-24:6,ExpBox False),(24:9-24:9,ExpBox False),(24:6-24:9,BinBox CondBinBox True),(24:6-24:9,BinBox CondBinBox False),(24:6-24:9,ExpBox False),(24:16-24:16,ExpBox True),(24:28-24:28,ExpBox False),(24:30-24:30,ExpBox False),(24:23-24:30,ExpBox False),(24:35-24:37,ExpBox False),(24:47-24:47,ExpBox False),(24:49-24:49,ExpBox False),(24:42-24:49,ExpBox False),(24:54-24:56,ExpBox False),(24:42-24:56,ExpBox False),(24:35-24:56,ExpBox False),(24:23-24:56,ExpBox True),(24:3-24:56,ExpBox False),(23:21-24:56,ExpBox False),(23:11-24:56,ExpBox False),(23:3-24:56,ExpBox False),(22:1-27:23,TopLevelBox ["showRecip"]),(30:13-30:18,ExpBox False),(31:23-31:28,ExpBox False),(31:12-31:29,ExpBox False),(31:3-31:29,ExpBox False),(32:3-32:6,ExpBox False),(29:8-32:6,ExpBox False),(29:1-32:6,TopLevelBox ["main"])]
\ No newline at end of file
module Main where
reciprocal :: Int -> (String, Int)
reciprocal n | n > 1 = ('0' : '.' : digits, recur)
| otherwise = error
"attempting to compute reciprocal of number <= 1"
where
(digits, recur) = divide n 1 []
divide :: Int -> Int -> [Int] -> (String, Int)
divide n c cs | c `elem` cs = ([], position c cs)
| r == 0 = (show q, 0)
| r /= 0 = (show q ++ digits, recur)
where
(q, r) = (c*10) `quotRem` n
(digits, recur) = divide n r (c:cs)
position :: Int -> [Int] -> Int
position n (x:xs) | n==x = 1
| otherwise = 1 + position n xs
showRecip :: Int -> String
showRecip n =
"1/" ++ show n ++ " = " ++
if r==0 then d else take p d ++ "(" ++ drop p d ++ ")"
where
p = length d - r
(d, r) = reciprocal n
main = do
number <- readLn
putStrLn (showRecip number)
main
Tix [ TixModule "Main" 1606722211 119 [7,7,2,5,7,2,5,0,5,5,5,5,5,5,7,12,12,12,12,12,9,11,11,10,11,11,11,14,2,12,14,2,2,2,2,2,12,12,1,11,12,1,1,1,1,11,11,11,0,11,11,11,11,11,11,11,14,3,3,3,3,3,3,3,0,3,3,3,3,3,3,3,3,0,0,0,0,0,3,3,3,2,2,2,2,2,3,3,3,3,3,3,1,2,3,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,1,3,3,3,3,1,1]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment