diff --git a/prelude/__internal__/IO.mad b/prelude/__internal__/IO.mad index 69b6e54d..7a98e222 100644 --- a/prelude/__internal__/IO.mad +++ b/prelude/__internal__/IO.mad @@ -51,6 +51,7 @@ export colortrace = (fn, v, a) => trace(prettyCase(fn, v), a) export red = Terminal.text.red export green = Terminal.text.green +export blue = Terminal.text.blue export yellow = Terminal.text.yellow export grey = Terminal.text.white diff --git a/prelude/__internal__/Terminal.mad b/prelude/__internal__/Terminal.mad index 0cad6077..9dcb579d 100644 --- a/prelude/__internal__/Terminal.mad +++ b/prelude/__internal__/Terminal.mad @@ -1,5 +1,7 @@ import String from "String" + + type HandlerId = HandlerId export type HandlerId @@ -24,7 +26,6 @@ export ansi = { FGMagenta: "35", FGCyan: "36", FGWhite: "37", - FGBrightBlack: "90", FGBrightRed: "91", FGBrightGreen: "92", @@ -33,7 +34,6 @@ export ansi = { FGBrightMagenta: "95", FGBrightCyan: "96", FGBrightWhite: "97", - BGBlack: "40", BGRed: "41", BGGreen: "42", @@ -42,7 +42,6 @@ export ansi = { BGMagenta: "45", BGCyan: "46", BGWhite: "47", - BGBrightBlack: "100", BGBrightRed: "101", BGBrightGreen: "102", @@ -51,12 +50,10 @@ export ansi = { BGBrightMagenta: "105", BGBrightCyan: "106", BGBrightWhite: "107", - FormatUnderline: "4", FormatNoUnderline: "24", FormatBold: "1", FormatNoBold: "21", - FormatInvert: "7", } @@ -69,10 +66,7 @@ export ansi = { * ansiColor([ansi.FormatBold, ansi.FGBrightRed], "will be red and bold") */ ansiColor :: List String -> String -> String -export ansiColor = (parts, str) => colorize( - `\x1b[${String.join(";", parts)}m`, - str -) +export ansiColor = (parts, str) => colorize(`\x1b[${String.join(";", parts)}m`, str) export text = { black: ansiColor([ansi.FGBlack]), @@ -161,9 +155,7 @@ onWindowResizedFFI :: ({} -> {}) -> HandlerId onWindowResizedFFI = extern "madlib__stdio__onWindowResized" onWindowResized :: (#[Integer, Integer] -> {}) -> HandlerId -export onWindowResized = (cb) => onWindowResizedFFI(() => { - cb(getWindowSize()) -}) +export onWindowResized = (cb) => onWindowResizedFFI(() => { cb(getWindowSize()) }) clearWindowResizeHandler :: HandlerId -> {} @@ -221,10 +213,7 @@ export clearKeyPressedHandler = (id) => #- { getWindowSize :: {} -> #[Integer, Integer] -export getWindowSize = () => #[ - #- process.stdout.columns -#, - #- process.stdout.rows -#, -] +export getWindowSize = () => #[#- process.stdout.columns -#, #- process.stdout.rows -#] getTTYMode :: {} -> TTYMode diff --git a/prelude/__internal__/Test.mad b/prelude/__internal__/Test.mad index 6996b8fc..c5461f6e 100644 --- a/prelude/__internal__/Test.mad +++ b/prelude/__internal__/Test.mad @@ -48,8 +48,11 @@ PREFIX_FAIL = IS_COLOR_ENABLED CHAR_CROSS :: String CHAR_CROSS = "×" +CHAR_INCOMPLETE :: String +CHAR_INCOMPLETE = "⧜" + EMPTY_REPORT :: TestReport -EMPTY_REPORT = TestReport("", 0, 0, 0) +EMPTY_REPORT = TestReport("", 0, 0, 0, 0) CWD :: String CWD = Process.getCurrentWorkingDirectory() @@ -60,7 +63,7 @@ CWD = Process.getCurrentWorkingDirectory() // SuiteResult(total, succeeded, failed) type SuiteResult = SuiteResult(Integer, Integer, Integer) -type TestResult = Success(String) | Failure(String, String) +type TestResult = Success(String) | Failure(String, String) | Skipped(String) isSuccess :: TestResult -> Boolean isSuccess = (res) => where(res) { @@ -104,47 +107,60 @@ export type AssertionError | NotImplemented -// Contains the accumulated String to be displayed, -// the amount of tests run, the amount of successful tests, -// and the amount of failed tests -type TestReport = TestReport(String, Integer, Integer, Integer) +/** + * TestReport + * accumulated report - String + * total tests - Integer + * successful runs - Integer + * failed runs- Integer + * skipped - Integer + */ +type TestReport = TestReport(String, Integer, Integer, Integer, Integer) getMessage :: TestReport -> String getMessage = where { - TestReport(str, _, _, _) => + TestReport(str, _, _, _, _) => str } getTotal :: TestReport -> Integer getTotal = where { - TestReport(_, total, _, _) => + TestReport(_, total, _, _, _) => total } getSuccessCount :: TestReport -> Integer getSuccessCount = where { - TestReport(_, _, success, _) => + TestReport(_, _, success, _, _) => success } getFailureCount :: TestReport -> Integer getFailureCount = where { - TestReport(_, _, _, failed) => + TestReport(_, _, _, failed, _) => failed } +getSkippedCount :: TestReport -> Integer +getSkippedCount = where { + TestReport(_, _, _, _, skipped) => + skipped +} resultToReport :: TestResult -> TestReport resultToReport = (result) => where(result) { Failure(_, message) => - TestReport(message, 1, 0, 1) + TestReport(message, 1, 0, 1, 0) Success(_) => - TestReport("", 1, 1, 0) + TestReport("", 1, 1, 0, 0) + + Skipped(_) => + TestReport("", 1, 0, 0, 1) } @@ -154,6 +170,7 @@ mergeReports = (t1, t2) => TestReport( getTotal(t1) + getTotal(t2), getSuccessCount(t1) + getSuccessCount(t2), getFailureCount(t1) + getFailureCount(t2), + getSkippedCount(t1) + getSkippedCount(t2), ) @@ -200,10 +217,11 @@ renderAssertionError = (description, assertionError) => where(assertionError) { IS_COLOR_ENABLED ? IO.red(`${CHAR_CROSS} ${show(err)}`) : `${CHAR_CROSS} ${show(err)}` NotImplemented => - IS_COLOR_ENABLED ? IO.red(`${CHAR_CROSS} not implemented`) : `${CHAR_CROSS} not implemented` + IS_COLOR_ENABLED + ? IO.yellow(`${CHAR_INCOMPLETE} "${description}" not implemented`) + : `${CHAR_INCOMPLETE} "${description}" not implemented` } - test :: String -> (String -> Wish.Wish AssertionError {}) -> Wish.Wish TestResult TestResult export test = (description, testFunction) => pipe( testFunction, @@ -216,6 +234,19 @@ export test = (description, testFunction) => pipe( ), )(description) +skip :: String -> (String -> Wish.Wish AssertionError {}) -> Wish.Wish TestResult TestResult +export skip = (description, testFunction) => pipe( + testFunction, + bimap( + pipe( + always(NotImplemented), + renderAssertionError(description), + Skipped, + ), + always(Skipped(description)), + ), +)(description) + generateReportSuiteEndMessage :: List (Wish.Wish e a) -> String generateReportSuiteEndMessage = pipe( @@ -410,15 +441,16 @@ runTestSuite = (suitePath, beforeAll, afterAll, testsInSuite) => pipe( pipe( List.reduce(mergeReports, EMPTY_REPORT), where { - TestReport(msg, total, success, failed) => + TestReport(msg, total, success, failed, skipped) => (total == 0 || failed > 0) ? TestReport( `${suitePath}\n${msg}${generateReportSuiteEndMessage(testsInSuite)}`, total, success, failed, + skipped, ) - : TestReport("", total, success, failed) + : TestReport("", total, success, failed, skipped) }, ), ), @@ -431,6 +463,7 @@ runTestSuite = (suitePath, beforeAll, afterAll, testsInSuite) => pipe( List.length(testsInSuite), 0, List.length(testsInSuite), + List.length(testsInSuite), ), ) },