// Generated by purs version 0.12.5
"use strict";
var $foreign = require("./foreign.js");
var Control_Applicative = require("../Control.Applicative/index.js");
var Control_Bind = require("../Control.Bind/index.js");
var Data_Either = require("../Data.Either/index.js");
var Data_List = require("../Data.List/index.js");
var Data_Unit = require("../Data.Unit/index.js");
var Effect = require("../Effect/index.js");
var Effect_Aff = require("../Effect.Aff/index.js");
var Effect_Class = require("../Effect.Class/index.js");
var Test_Unit = require("../Test.Unit/index.js");
var Test_Unit_Console = require("../Test.Unit.Console/index.js");
var Test_Unit_Output_Fancy = require("../Test.Unit.Output.Fancy/index.js");
var Test_Unit_Output_Simple = require("../Test.Unit.Output.Simple/index.js");
var Test_Unit_Output_TAP = require("../Test.Unit.Output.TAP/index.js");
var runTestWith = function (runner) {
    return function (suite) {
        return Control_Bind.bind(Effect_Aff.bindAff)(Control_Bind.bind(Effect_Aff.bindAff)(runner(Test_Unit.filterTests(suite)))(Test_Unit.collectResults))(function (v) {
            var errs = Test_Unit.keepErrors(v);
            var $5 = Data_List.length(errs) > 0;
            if ($5) {
                return Effect_Class.liftEffect(Effect_Aff.monadEffectAff)($foreign.exit(1));
            };
            return Control_Applicative.pure(Effect_Aff.applicativeAff)(Data_Unit.unit);
        });
    };
};
var run = function (e) {
    var successHandler = function (v) {
        return Control_Applicative.pure(Effect.applicativeEffect)(Data_Unit.unit);
    };
    var errorHandler = function (v) {
        return $foreign.exit(1);
    };
    return function __do() {
        var v = Effect_Aff.runAff(Data_Either.either(errorHandler)(successHandler))(e)();
        return Data_Unit.unit;
    };
};
var runTest = function (suite) {
    var runner = (function () {
        if (Test_Unit_Output_TAP.requested) {
            return Test_Unit_Output_TAP.runTest;
        };
        var $7 = Test_Unit_Console.hasStderr && Test_Unit_Console.hasColours;
        if ($7) {
            return Test_Unit_Output_Fancy.runTest;
        };
        return Test_Unit_Output_Simple.runTest;
    })();
    return run(runTestWith(runner)(suite));
};
module.exports = {
    runTest: runTest,
    runTestWith: runTestWith,
    run: run,
    exit: $foreign.exit
};
