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

tests: Minimal Base Refactor #1531

Merged
merged 2 commits into from
Mar 8, 2024
Merged
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
90 changes: 67 additions & 23 deletions tests/tests.wake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ def wakeUnitToTest Unit =

Pass result

def showDiff (expect: String) (actual: String): Result Unit Error =
require Pass expectFile = writeTempFile "diff.expect" expect
else failWithError "Unable to write expect file"

require Pass actualFile = writeTempFile "diff.actual" actual
else failWithError "Unable to write actual file"

def cmd =
"diff",
"-u",
actualFile.getPathName,
expectFile.getPathName,

# The job outputs here don't actually matter, depending on them forces the output order for
# failed tests so they print out nicely.
require Exited _ =
makeExecPlan cmd (expectFile, actualFile, Nil)
| setPlanStdout logWarning
| setPlanStderr logWarning
| setPlanIsAtty True
| runJobWith defaultRunner
| getJobStatus
else failWithError "Unable to diff files"

Pass Unit

export def runTests (cmdline: List String): Result String Error =
require Pass filter = match cmdline
Nil -> Pass `.*`
Expand Down Expand Up @@ -235,42 +261,60 @@ def runTest (testScript: Path): Result Unit Error =
| setPlanShare False
| runJobWith localRunner # On OS/X you cannot mount fuse within fuse

def removeCarriageReturns = replace `\r` ""

require Pass jobStdout =
testJob.getJobFailedStdout
| rmap (replace `\r` "")
| rmap removeCarriageReturns

require Pass jobStderr =
testJob.getJobFailedStderr
| rmap (replace `\r` "")
| rmap removeCarriageReturns

require Pass _ = match shouldPass testJob.isJobOk
True True -> Pass Unit
False False -> Pass Unit
True False ->
Fail (makeError "Test failed ({format testJob.getJobStatus}) with '{replace `\n.*` "" jobStderr}'")
False True ->
Fail (makeError "Test should not have passed with '{replace `\n.*` "" jobStderr}'")
def _ =
"{testName} failed! Stdout: \n{jobStdout}"
| printlnLevel logWarning

require Pass _ = match expectedStderr
Some x if x ==* jobStderr -> Pass Unit
None -> Pass Unit
Some _ ->
# TODO: use diff prim to compare jobStderr with expectedStderr
def _ =
(testName, "\n", jobStderr, Nil)
| cat
| println
"{testName} failed! Stderr: \n{jobStderr}"
| printlnLevel logWarning

Fail (makeError "Unexpected standard error. See above for details")
Fail (makeError "Test failed. Expected: Ok, Actual: {format testJob.getJobStatus}. See above for details")
False True ->
def _ =
"{testName} failed! Stdout: \n{jobStdout}"
| printlnLevel logWarning

match expectedStdout
Some x if x ==* jobStdout -> Pass Unit
None -> Pass Unit
_ ->
# TODO: use diff prim to compare jobStdout with expectedStdout
def _ =
(testName, "\n", jobStdout, Nil)
| cat
| println
"{testName} failed! Stderr: \n{jobStderr}"
| printlnLevel logWarning

Fail (makeError "Unexpected standard output. See above for details")
Fail (makeError "Test failed. Expected: Err, Actual: {format testJob.getJobStatus}. See above for details")

def expectEqualOutput (stream: String) (expected: Option String) (actual: String): Result Unit Error =
# If the integration test doesn't provide an expected output then anything is allowed.
require Some expect = expected
else Pass Unit

# If they are equal, pass the expect
require False = expect ==* actual
else Pass Unit

# They are not equal, show a nice diff and fail.
require Pass _ =
"{testName} failed! The diff below should be applied to jobs {stream}"
| printlnLevel logWarning
| Pass

require Pass _ = showDiff expect actual

Fail (makeError "Unexpected {stream}. See above for details")

require Pass Unit = expectEqualOutput "stderr" expectedStderr jobStderr
require Pass Unit = expectEqualOutput "stdout" expectedStdout jobStdout

Pass Unit
Loading