program MycTests;

{$IFNDEF TESTINSIGHT}
    {$APPTYPE CONSOLE}
{$ENDIF}
{$STRONGLINKTYPES ON}
uses
    FastMM5,
    DUnitX.MemoryLeakMonitor.FastMM5,
{$IFDEF TESTINSIGHT}
    TestInsight.DUnitX,
{$ELSE}
    DUnitX.Loggers.Console,
{$ENDIF }
    DUnitX.TestFramework,
    System.SysUtils,
    TestNotifier in 'TestNotifier.pas',
    TestNotifier_Threading in 'TestNotifier_Threading.pas' {/TestNotifier_ChaosStress in 'TestNotifier_ChaosStress.pas',},
    TestNotifier_ChaosStress in 'TestNotifier_ChaosStress.pas',
    TestTasks in 'TestTasks.pas',
    TestCoreFutures in 'TestCoreFutures.pas',
    TestFutures in 'TestFutures.pas',
    Myc.Test.Core.Atomic in '..\Src\Myc.Test.Core.Atomic.pas',
    Myc.Test.Signals.Latch in '..\Src\Myc.Test.Signals.Latch.pas',
    Myc.Test.Signals.Dirty in '..\Src\Myc.Test.Signals.Dirty.pas',
    Test.Core.Mutable in 'Test.Core.Mutable.pas',
    TestDataArray in 'TestDataArray.pas',
    TestDataDecimal in 'TestDataDecimal.pas',
    TestDataPOD in 'TestDataPOD.pas',
    Test.Myc.Ast.Scope in 'AST\Test.Myc.Ast.Scope.pas',
    Test.Myc.Ast.RTL in 'AST\Test.Myc.Ast.RTL.pas',
    Test.Myc.Ast.Script in 'AST\Test.Myc.Ast.Script.pas',
    Test.Myc.Ast.Compiler.Macros in 'AST\Test.Myc.Ast.Compiler.Macros.pas',
    Test.Myc.Ast.RTL.DateTime in 'AST\Test.Myc.Ast.RTL.DateTime.pas',
    Test.Myc.Ast.Compiler.Binder in '..\Src\AST\Test.Myc.Ast.Compiler.Binder.pas',
    Test.Myc.Ast.RTL.TypeRegistry in 'AST\Test.Myc.Ast.RTL.TypeRegistry.pas',
    Test.Myc.Ast.NullPropagation in 'AST\Test.Myc.Ast.NullPropagation.pas',
    Test.Myc.Ast.Pipes in 'AST\Test.Myc.Ast.Pipes.pas',
    Test.Myc.Ast.Integration in 'Test.Myc.Ast.Integration.pas',
    Demo.Finance in 'Demo.Finance.pas';

{ keep comment here to protect the following conditional from being removed by the IDE when adding a unit }
{$IFNDEF TESTINSIGHT}
var
    runner: ITestRunner;
    results: IRunResults;
    logger: ITestLogger;
    nunitLogger: ITestLogger;
{$ENDIF}
begin
{$IFDEF TESTINSIGHT}
    TestInsight.DUnitX.RunRegisteredTests;
{$ELSE}
    try
        //Check command line options, will exit if invalid
        TDUnitX.CheckCommandLine;
        //Create the test runner
        runner := TDUnitX.CreateRunner;
        //Tell the runner to use RTTI to find Fixtures
        runner.UseRTTI := True;
        //When true, Assertions must be made during tests;
        runner.FailsOnNoAsserts := False;

        //tell the runner how we will log things
        //Log to the console window if desired
        if TDUnitX.Options.ConsoleMode <> TDunitXConsoleMode.Off then
        begin
            logger := TDUnitXConsoleLogger.Create(TDUnitX.Options.ConsoleMode = TDunitXConsoleMode.Quiet);
            runner.AddLogger(logger);
        end;
        //Generate an NUnit compatible XML File
        nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
        runner.AddLogger(nunitLogger);

        //Run tests
        results := runner.Execute;
        if not results.AllPassed then
            System.ExitCode := EXIT_ERRORS;

    {$IFNDEF CI}
        //We don't want this happening when running under CI.
        if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
        begin
            System.Write('Done.. press <Enter> key to quit.');
            System.Readln;
        end;
    {$ENDIF}
    except
        on E: Exception do
            System.Writeln(E.ClassName, ': ', E.Message);
    end;
{$ENDIF}
end.
