unison/unison-src/transcripts-using-base/failure-tests.output.md
2022-12-01 23:51:11 -06:00

1.4 KiB

Tests the Failures generated by builtin functions.

There are three places that the builtins build Failures. One is for builtins that return Either Failure, one is for builtins that use the Exception ability directly, and the last is code validation. I don't have an easy way to test the last at the moment, but the other two are tested here.

test1 : '{IO, Exception} [Result]
test1 = do
  _ = fromUtf8 0xsee
  [Ok "test1"]

test2 : '{IO, Exception} [Result]
test2 = do
  _ = tryEval '(bug "whoa")
  [Ok "test2"]

  I found and typechecked these definitions in scratch.u. If you
  do an `add` or `update`, here's how your codebase would
  change:
  
    ⍟ These new definitions are ok to `add`:
    
      test1 : '{IO, Exception} [Result]
      test2 : '{IO, Exception} [Result]

.> add

  ⍟ I've added these definitions:
  
    test1 : '{IO, Exception} [Result]
    test2 : '{IO, Exception} [Result]

.> io.test test1

  💔💥
  
  The program halted with an unhandled exception:
  
    Failure
      (typeLink IOFailure)
      "Cannot decode byte '\\xee': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream"
      (Any ())
  
  
  Stack trace:
    ##raise

.> io.test test2

  💔💥
  
  The program halted with an unhandled exception:
  
    Failure (typeLink RuntimeFailure) "builtin.bug" (Any "whoa")
  
  
  Stack trace:
    ##raise