Skip to content

Commit

Permalink
More precise blank lines in transcript UCM blocks
Browse files Browse the repository at this point in the history
This avoids leading and trailing blanks, while ensuring they exist between commands & outputs.
  • Loading branch information
sellout committed Nov 26, 2024
1 parent 911c799 commit b7edcd6
Show file tree
Hide file tree
Showing 287 changed files with 740 additions and 647 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

``` ucm :hide
scratch/main> builtins.mergeio lib.builtins
scratch/main> load ./unison-src/transcripts-using-base/base.u
scratch/main> add
```

Expand Down Expand Up @@ -34,7 +36,6 @@ main = do
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand All @@ -58,5 +59,6 @@ scratch/main> add
type MyBool
main : '{IO, Exception} ()
resume : Request {g, Break} x -> x
scratch/main> compile main ./unison-cli-integration/integration-tests/IntegrationTests/main
```
27 changes: 15 additions & 12 deletions unison-cli/src/Unison/Codebase/Transcript/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,33 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
let patternMap = Map.fromList $ (\p -> (patternName p, p) : ((,p) <$> aliases p)) =<< validInputs
let output' :: Bool -> Stanza -> IO ()
output' inputEcho msg = do
hide <- readIORef isHidden
unless (hideOutput inputEcho hide) $ modifyIORef' out (<> pure msg)
hide <- hideOutput inputEcho
unless hide $ modifyIORef' out (<> pure msg)

hideOutput :: Bool -> Hidden -> Bool
hideOutput inputEcho = \case
hideOutput' :: Bool -> Hidden -> Bool
hideOutput' inputEcho = \case
Shown -> False
HideOutput -> not inputEcho
HideAll -> True

hideOutput :: Bool -> IO Bool
hideOutput inputEcho = hideOutput' inputEcho <$> readIORef isHidden

output, outputEcho :: Stanza -> IO ()
output = output' False
outputEcho = output' True

outputUcmLine :: UcmLine -> IO ()
outputUcmLine line = modifyIORef' ucmOutput (<> pure line)
outputUcmLine line = do
prev <- readIORef ucmOutput
modifyIORef' ucmOutput (<> ((if not (null prev) then pure (UcmOutputLine "\n") else mempty) <> pure line))

outputUcmResult :: Pretty.Pretty Pretty.ColorText -> IO ()
outputUcmResult line = do
hide <- readIORef isHidden
unless (hideOutput False hide) $
hide <- hideOutput False
unless hide $
-- We shorten the terminal width, because "Transcript" manages a 2-space indent for output lines.
modifyIORef'
ucmOutput
(<> pure (UcmOutputLine . Text.pack $ Pretty.toPlain (terminalWidth - 2) $ "\n" <> line))
outputUcmLine . UcmOutputLine . Text.pack $ Pretty.toPlain (terminalWidth - 2) line

maybeDieWithMsg :: String -> IO ()
maybeDieWithMsg msg = do
Expand All @@ -210,7 +213,7 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL

apiRequest :: APIRequest -> IO [APIRequest]
apiRequest req = do
hide <- readIORef isHidden
hide <- hideOutput False
case req of
-- We just discard this, because the runner will produce new output lines.
APIResponseLine {} -> pure []
Expand All @@ -222,7 +225,7 @@ run isTest verbosity dir codebase runtime sbRuntime nRuntime ucmVersion baseURL
(([] <$) . maybeDieWithMsg . (("Error decoding response from " <> Text.unpack path <> ": ") <>))
( \(v :: Aeson.Value) ->
pure $
if hide == HideOutput
if hide
then [req]
else
[ req,
Expand Down
3 changes: 3 additions & 0 deletions unison-src/builtin-tests/interpreter-tests.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Before merging the PR on Github, we'll merge your branch on Share and restore `r

``` ucm :hide:error
scratch/main> this is a hack to trigger an error, in order to swallow any error on the next line.
scratch/main> we delete the project to avoid any merge conflicts or complaints from ucm.
scratch/main> delete.project runtime-tests
```

Expand All @@ -18,6 +20,7 @@ scratch/main> clone @unison/runtime-tests/releases/0.0.1 runtime-tests/selected
runtime-tests/selected> run tests
()
runtime-tests/selected> run tests.interpreter.only
()
Expand Down
2 changes: 1 addition & 1 deletion unison-src/transcripts-manual/docs.to-html.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ some.outside = 3
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand Down Expand Up @@ -44,5 +43,6 @@ test-html-docs/main> add
some.ns.pretty.deeply.nested.doc : Doc2
some.outside : Nat
some.outside.doc : Doc2
test-html-docs/main> docs.to-html some.ns unison-src/transcripts-manual/docs.to-html
```
9 changes: 9 additions & 0 deletions unison-src/transcripts-manual/rewrites.output.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
``` ucm :hide
scratch/main> builtins.mergeio
scratch/main> load unison-src/transcripts-using-base/base.u
scratch/main> add
```

Expand Down Expand Up @@ -43,6 +45,7 @@ scratch/main> rewrite rule1
I found and replaced matches in these definitions: ex1
The rewritten file has been added to the top of scratch.u
scratch/main> rewrite eitherToOptional
☝️
Expand Down Expand Up @@ -115,6 +118,7 @@ rule2 x = @rewrite signature Optional ==> Optional2

``` ucm :hide
scratch/main> load
scratch/main> add
```

Expand Down Expand Up @@ -202,6 +206,7 @@ blah2 = 456

``` ucm :hide
scratch/main> load
scratch/main> add
```

Expand Down Expand Up @@ -239,7 +244,9 @@ sameFileEx =

``` ucm :hide
scratch/main> rewrite rule
scratch/main> load
scratch/main> add
```

Expand Down Expand Up @@ -421,6 +428,7 @@ scratch/main> sfind findEitherEx
1. eitherEx
Tip: Try `edit 1` to bring this into your scratch file.
scratch/main> sfind findEitherFailure
🔎
Expand All @@ -435,6 +443,7 @@ scratch/main> sfind findEitherFailure
Tip: Try `edit 1` or `edit 1-5` to bring these into your
scratch file.
scratch/main> find 1-5
1. Exception.catch : '{g, Exception} a ->{g} Either Failure a
Expand Down
13 changes: 12 additions & 1 deletion unison-src/transcripts-round-trip/main.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ This transcript verifies that the pretty-printer produces code that can be succe

``` ucm :hide
scratch/main> builtins.mergeio lib.builtins
scratch/a1> builtins.mergeio lib.builtins
scratch/a2> builtins.mergeio lib.builtins
```

``` ucm :hide
scratch/a1> load unison-src/transcripts-round-trip/reparses-with-same-hash.u
scratch/a1> add
```

Expand All @@ -16,7 +19,6 @@ x = ()
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand Down Expand Up @@ -833,6 +835,7 @@ scratch/a2> load

``` ucm :hide
scratch/a2> add
scratch/a2> delete.namespace.force lib.builtins
```

Expand All @@ -848,7 +851,9 @@ Now check that definitions in 'reparses.u' at least parse on round trip:

``` ucm :hide
scratch/a3> builtins.mergeio lib.builtins
scratch/a3> load unison-src/transcripts-round-trip/reparses.u
scratch/a3> add
```

Expand Down Expand Up @@ -897,9 +902,13 @@ sloppyDocEval =

``` ucm :hide
scratch/a3_new> builtins.mergeio lib.builtins
scratch/a3_new> load
scratch/a3_new> add
scratch/a3> delete.namespace.force lib.builtins
scratch/a3_new> delete.namespace.force lib.builtins
```

Expand All @@ -925,6 +934,7 @@ Regression test for https://github.com/unisonweb/unison/pull/3548
scratch/regressions> alias.term ##Nat.+ plus
Done.
scratch/regressions> edit.new plus
☝️
Expand All @@ -933,6 +943,7 @@ scratch/regressions> edit.new plus
You can edit them there, then run `update` to replace the
definitions currently in this namespace.
scratch/regressions> load
Loading changes detected in scratch.u.
Expand Down
4 changes: 3 additions & 1 deletion unison-src/transcripts-using-base/_base.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ transcripts which contain less boilerplate.

``` ucm :hide
scratch/main> builtins.mergeio
scratch/main> load unison-src/transcripts-using-base/base.u
scratch/main> add
```

Expand Down Expand Up @@ -50,7 +52,6 @@ testAutoClean _ =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand All @@ -68,6 +69,7 @@ scratch/main> add
⍟ I've added these definitions:
testAutoClean : '{IO} [Result]
scratch/main> io.test testAutoClean
New test results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ testABunchOfNats _ =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand Down Expand Up @@ -90,6 +89,7 @@ scratch/main> add
testABunchOfNats : ∀ _. _ ->{IO} [Result]
testNat : Nat -> '{IO, Stream Result} ()
testRoundTrip : Nat -> EncDec ->{IO, Stream Result} ()
scratch/main> io.test testABunchOfNats
New test results:
Expand Down
8 changes: 4 additions & 4 deletions unison-src/transcripts-using-base/codeops.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ swapped name link =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand Down Expand Up @@ -316,7 +315,6 @@ badLoad _ =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand Down Expand Up @@ -358,6 +356,7 @@ scratch/main> add
rotate : Three Nat Nat Nat -> Three Nat Nat Nat
tests : '{IO} [Result]
zapper : Three Nat Nat Nat -> Request {Zap} r -> r
scratch/main> io.test tests
New test results:
Expand All @@ -379,6 +378,7 @@ scratch/main> io.test tests
✅ 13 test(s) passing
Tip: Use view 1 to view the source of a test.
scratch/main> io.test badLoad
New test results:
Expand Down Expand Up @@ -427,7 +427,6 @@ codeTests =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand All @@ -445,6 +444,7 @@ scratch/main> add
⍟ I've added these definitions:
codeTests : '{IO} [Result]
scratch/main> io.test codeTests
New test results:
Expand Down Expand Up @@ -512,7 +512,6 @@ vtests _ =
```

``` ucm :added-by-ucm
Loading changes detected in scratch.u.
I found and typechecked these definitions in scratch.u. If you
Expand All @@ -532,6 +531,7 @@ scratch/main> add
validateTest : Link.Term ->{IO} Result
vtests : '{IO} [Result]
scratch/main> io.test vtests
New test results:
Expand Down
Loading

0 comments on commit b7edcd6

Please sign in to comment.