Add integration-test

This commit is contained in:
satotake 2021-10-24 08:08:34 +00:00 committed by GitHub
parent b8ed7414d0
commit 23bed5b6bf
7 changed files with 223 additions and 0 deletions

View File

@ -0,0 +1,89 @@
{-# LANGUAGE OverloadedStrings #-}
module IntegrationTests.ArgumentParsing where
import Data.List (intercalate)
import Data.Text (pack)
import EasyTest
import Shellmet (($|))
import System.Exit (ExitCode (ExitFailure, ExitSuccess))
import System.Process (readProcessWithExitCode)
uFile :: String
uFile = "cli/integration-tests/IntegrationTests/print.u"
transcriptFile :: String
transcriptFile = "cli/integration-tests/IntegrationTests/transcript.md"
tempCodebase :: String
tempCodebase = "tempcodebase"
test :: Test ()
test =
scope "argument-parsing" . tests $
map
(expectExitCode ExitSuccess)
[ ["--help"],
["-h"],
["version", "--help"],
["init", "--help"],
["run", "--help"],
-- ,["run.compile", "--help"] -- Invalid Argument?
["run.file", "--help"],
["run.pipe", "--help"],
["transcript", "--help"],
["transcript.fork", "--help"],
["headless", "--help"],
["version"],
["init"], -- removed
-- ,["run"] -- how?
,["run.file", uFile, "print"]
,["transcript", transcriptFile]
,["transcript.fork", transcriptFile]
-- ,["headless"] -- ?
-- options
,["--port", "8000"]
,["--host", "localhost"]
,["--token", "MY_TOKEN"] -- ?
,["--codebase-create", tempCodebase]
,["--codebase", tempCodebase]
,["--ui", tempCodebase]
["--no-base"]
]
++ map
(expectExitCode (ExitFailure 1))
[ ["--port", "x"], -- must be number
["run.compile", "--help"], -- ?
["run.file"], -- without file
["run.file", uFile], -- without SYMBOL
["transcript"], -- without file
["transcript.fork"] -- without file
]
++ [testRunPipe, clearTempCodebase]
expectExitCode :: ExitCode -> [String] -> Test ()
expectExitCode expected args = scope (intercalate " " args) do
(code, _, _) <- io $ readProcessWithExitCode "stack" fullargs ""
expectEqual code expected
where
fullargs :: [String]
fullargs = ["exec", "--", "unison"] ++ args
testRunPipe :: Test ()
testRunPipe = scope "run.pipe print" do
(code, _, _) <- io $ readProcessWithExitCode "stack" fullargs stdin
expectEqual code ExitSuccess
where
stdin =
"print : '{IO, Exception} () \n\
\print _ = base.io.printLine \"ok\""
fullargs :: [String]
fullargs = ["exec", "--", "unison", "run.pipe", "print"]
clearTempCodebase :: Test ()
clearTempCodebase = scope "(clear)" do
_ <- io do
"rm" $| (map pack ["-rf", tempCodebase])
ok

View File

@ -0,0 +1,2 @@
print : '{IO, Exception} ()
print _ = base.io.printLine "ok"

View File

@ -0,0 +1,20 @@
# Integration test: transcript
```ucm:hide
.> builtins.mergeio
```
Test
```unison
use .builtin
coolFunction x = x * 2
coolFunction.doc = [: This is a cool function. :]
```
```ucm
.> add
.> link coolFunction.doc coolFunction
```

View File

@ -0,0 +1,40 @@
# Integration test: transcript
Test
```unison
use .builtin
coolFunction x = x * 2
coolFunction.doc = [: This is a cool function. :]
```
```ucm
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`:
coolFunction : Nat -> Nat
coolFunction.doc : Doc.Deprecated
```
```ucm
.> add
⍟ I've added these definitions:
coolFunction : Nat -> Nat
coolFunction.doc : Doc.Deprecated
.> link coolFunction.doc coolFunction
Updates:
1. coolFunction : Nat -> Nat
+ 2. coolFunction.doc : builtin.Doc
```

View File

@ -0,0 +1,25 @@
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
module Main where
import Control.Monad
import EasyTest
import qualified IntegrationTests.ArgumentParsing as ArgumentParsing
import System.Environment (getArgs)
import System.IO
test :: Test ()
test =
tests
[ ArgumentParsing.test
]
main :: IO ()
main = do
args <- getArgs
mapM_ (`hSetEncoding` utf8) [stdout, stdin, stderr]
case args of
[] -> runOnly "" test
[prefix] -> runOnly prefix test
[seed, prefix] -> rerunOnly (read seed) prefix test

View File

@ -67,6 +67,19 @@ executables:
build-tools:
- unison-cli:unison
integration-tests:
source-dirs: integration-tests
main: Suite.hs
ghc-options: -W -threaded -rtsopts "-with-rtsopts=-N -T" -v0
dependencies:
- base
- easytest
- process
- shellmet
- text
- unison-core1
- unison-parser-typechecker
- unison-prelude
when:
- condition: flag(optimized)

View File

@ -21,6 +21,40 @@ flag optimized
manual: True
default: False
executable integration-tests
main-is: Suite.hs
other-modules:
IntegrationTests.ArgumentParsing
Paths_unison_cli
hs-source-dirs:
integration-tests
default-extensions:
ApplicativeDo
BlockArguments
DeriveFunctor
DerivingStrategies
DoAndIfThenElse
FlexibleContexts
FlexibleInstances
LambdaCase
MultiParamTypeClasses
ScopedTypeVariables
TupleSections
TypeApplications
ghc-options: -W -threaded -rtsopts "-with-rtsopts=-N -T" -v0
build-depends:
base
, easytest
, process
, shellmet
, text
, unison-core1
, unison-parser-typechecker
, unison-prelude
if flag(optimized)
ghc-options: -O2 -funbox-strict-fields
default-language: Haskell2010
executable transcripts
main-is: Transcripts.hs
other-modules: