From 25a779eae40489e17a5ec35445f26f26ce0dc9f6 Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Thu, 26 May 2022 15:41:48 +0200 Subject: [PATCH] docstrings --- TAP.idr | 99 +++++++++++++++++++++++++++++++++++++++---------- TAP/Options.idr | 54 ++++++++++++++++++++++++--- 2 files changed, 128 insertions(+), 25 deletions(-) diff --git a/TAP.idr b/TAP.idr index 8e61271..a83f976 100644 --- a/TAP.idr +++ b/TAP.idr @@ -1,3 +1,4 @@ +||| basic test framework using the TAP output format (https://testanything.org) module TAP import public TAP.Options @@ -14,10 +15,14 @@ import System %default total +||| extra info attached to a result (positive or negative). the TAP spec allows +||| any YAML, but this is what you get for now public export Info : Type Info = List (String, String) + +||| result of running a test. or not doing so, in the case of `Skip` and `Todo` private data Result = Tried Bool Info | Skip String | Todo String @@ -28,27 +33,32 @@ record TestBase where run : IO Result -private -toLines1 : (String, String) -> List String -toLines1 (k, v) = - let vs = lines v in - if length vs == 1 - then ["\{k}: \{v}"] - else "\{k}: |" :: map (indent 2) vs - -private +||| render an `Info` value as a YAML document, including the `---`/`...` +||| delimiters. returns nothing at all if the `Info` is empty +export toLines : Info -> List String toLines [] = [] -toLines xs = "---" :: concatMap toLines1 xs <+> ["..."] +toLines xs = "---" :: concatMap toLines1 xs <+> ["..."] where + toLines1 : (String, String) -> List String + toLines1 (k, v) = + let vs = lines v in + if length vs == 1 then ["\{k}: \{v}"] + else "\{k}: |" :: map (indent 2) vs -public export interface ToInfo e where toInfo : e -> Info +||| represent a value (e.g. an error message) as an `Info` for including in the +||| output. +public export +interface ToInfo e where + toInfo : e -> Info +||| an info of `()` prints nothing export ToInfo () where toInfo () = [] export Show a => ToInfo (List (String, a)) where toInfo = map (map show) +||| a test or group of tests export data Test = One TestBase @@ -56,6 +66,7 @@ data Test | Note String +||| is this a real test or just a note? export isRealTest : Test -> Bool isRealTest (One _) = True @@ -67,10 +78,15 @@ private result : ToInfo a => Bool -> a -> IO Result result ok = pure . Tried ok . toInfo + +||| promote a lazy value to an IO action that will run it private lazyToIO : Lazy a -> IO a lazyToIO val = primIO $ \w => MkIORes (force val) w + +||| a test that can do some IO before returning `Left` for a failure or `Right` +||| for a success export testIO : (ToInfo e, ToInfo a) => String -> EitherT e IO a -> Test testIO label act = One $ MakeTest label $ do @@ -78,32 +94,45 @@ testIO label act = One $ MakeTest label $ do Right val => result True val Left err => result False err +||| a pure test that returns `Left` for a failure or `Right` for a success export test : (ToInfo e, ToInfo a) => String -> Lazy (Either e a) -> Test test label val = testIO label $ MkEitherT $ lazyToIO val +||| a todo with a reason given. the reason is the first argument, e.g. +||| `todo "" "