Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderOneLine should render to one line #1759

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

## New features

* REPL command `:dumptests <FILE> <EXPR>` updated to write to stdout when
invoked as `:dumptests - <EXPR>` allowing for easier experimentation and
testing.

# 3.2.0 -- 2024-08-20

## Language changes
Expand Down
6 changes: 4 additions & 2 deletions src/Cryptol/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ commandList =
, "expression into a file. The first column in each line is"
, "the expected output, and the remainder are the inputs. The"
, "number of tests is determined by the \"tests\" option."
, "Use filename \"-\" to write tests to stdout."
glguy marked this conversation as resolved.
Show resolved Hide resolved
])
""
, CommandDescr [ ":generate-foreign-header" ] ["FILE"] (FilenameArg genHeaderCmd)
Expand Down Expand Up @@ -473,12 +474,13 @@ dumpTestsCmd outFile str pos fnm =
Nothing -> raise (TypeNotTestable ty)
Just gens -> return gens
tests <- withRandomGen (\g -> io $ TestR.returnTests' g gens val testNum)
out <- forM tests $
outs <- forM tests $
\(args, x) ->
do argOut <- mapM (rEval . E.ppValue Concrete ppopts) args
resOut <- rEval (E.ppValue Concrete ppopts x)
return (renderOneLine resOut ++ "\t" ++ intercalate "\t" (map renderOneLine argOut) ++ "\n")
writeResult <- io $ X.try (writeFile outFile (concat out))
let out = concat outs
writeResult <- io (X.try (if outFile == "-" then putStr out else writeFile outFile out))
case writeResult of
Right{} -> pure emptyCommandResult
Left e ->
Expand Down
6 changes: 5 additions & 1 deletion src/Cryptol/Utils/PP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ instance IsString Doc where
fromString = text

renderOneLine :: Doc -> String
renderOneLine d = PP.renderString (PP.layoutCompact (runDocWith defaultPPCfg d))
renderOneLine d = PP.renderString (PP.layoutPretty opts (runDocWith defaultPPCfg d))
where
opts = PP.LayoutOptions
{ PP.layoutPageWidth = PP.Unbounded
}

class PP a where
ppPrec :: Int -> a -> Doc
Expand Down
4 changes: 4 additions & 0 deletions tests/issues/issue_1314.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:set-seed 0
:dumptests - (sum : [100][8] -> [8])
:dumptests - (\(x,y) -> x + y : [64])
:dumptests - (\a b c -> a < b /\ b < (c : [100]))
Loading
Loading