I have a strange problem. I have a DUnit application, which I need to run as both GUI (on my development machine) and as a console app (on the build machine). I just copied the project file, renamed it. I have the usual :

I have a strange problem. I have a DUnit application, which I need to run as both GUI (on my development machine) and as a console app (on the build machine). I just copied the project file, renamed it. I have the usual :

{$IFDEF CONSOLE_TESTRUNNER}
{$APPTYPE CONSOLE}
{$ENDIF}

And in one app I define the CONSOLE_TESTRUNNER conditional define and in the other I don't.

If I COMPILE the console application, it works as a console app. However, if I BUILD then it runs as a GUI app. I have even tried removing the conditional define and explicitly setting it as {$APPTYPE CONSOLE}, to remove the conditional define out of the equation, but then the application just throws out an EInOutError I/O error 105. I guess it's trying to write to the output but failing. But why?

Comments

  1. What do you have under Project > Options > Delphi Compiler > Linking > Generate console application ?? Is that checked or not?

    ReplyDelete
  2. It was not checked. However if I check it, it makes no difference. If I compile I get a console app, if I build I get a gui app.

    ReplyDelete
  3. Did you check what kind of build you're doing. If you specified CONSOLE_TESTRUNNER in the DEBUG-build, it might not be defined for the RELEASE-build (or visa versa).

    ReplyDelete
  4. Yeah checked as well. I also tried eliminating the define by explicitly setting APPTYPE. If I build it is not a console app. If I compile it is.

    ReplyDelete
  5. How do you build and how do you compile.

    ReplyDelete
  6. I can build and compile from the IDE or using MSBuild. Same result!

    ReplyDelete
  7. Build and compile from the IDE should have the same result. Building outside the IDE with MSBuild could have different results. If you have different results with the build and compile in the IDE itself you might want to create a small test-project just to see if that works fine.

    program test_project;
    {$APPTYPE CONSOLE}
    uses
    System.SysUtils;
    begin
    try
    writeln('works');
    Readln;
    except
    on E: Exception do
    Writeln(E.ClassName, ': ', E.Message);
    end;
    end.

    ReplyDelete
  8. Probably wrong, but clean up all build artifacts (.dcu's etc) everywhere. Aside, we have our testsuite always build as a GUI app. It has been slightly tailored to recognize a command line switch such that it (nevertheless) produces output to an NUnit compatible output for reporting by the build CI server (Jenkins).

    ReplyDelete
  9. I do have some vcl units in the project due to some old dependencies..

    ReplyDelete

Post a Comment