Recent

Author Topic: FPCUnit returns 2 error level if tests failed  (Read 3625 times)

zamtmn

  • Hero Member
  • *****
  • Posts: 681
FPCUnit returns 2 error level if tests failed
« on: February 15, 2022, 04:35:15 pm »
FPCUnit returns an error code when detecting failed tests. At the same time, many free CI servers (like appveyor) interrupt build process when error codes appear, we have to go to the trick and receive them. I think we need add a command line option to consoletestrunner.pas for suppress this behavior so that it is possible to return 0 regardless of failures, and results can be viewed in the report.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: FPCUnit returns 2 error level if tests failed
« Reply #1 on: February 16, 2022, 10:50:56 am »
If I see it correctly then the console TTestRunner only sets the ExitCode, but does not terminate the process. So you should be able to simply do ExitCode := 0 at the end of the main program file of the test.

zamtmn

  • Hero Member
  • *****
  • Posts: 681
Re: FPCUnit returns 2 error level if tests failed
« Reply #2 on: February 16, 2022, 11:34:17 am »
  Yes, it is, I had to run tests through an additional wrapper bat file. to cheat a server script that I don't have access to. I think an additional command line key to configure the behavior would be a good solution.
  I also ran into a problem in the time format. FPCUnit does not have a time format setting, always HH:MM:SS.FF but most test systems (like junit) wait time in seconds SS.FF It is also desirable to add this setting to FPCUnit
  I solved these problems separately, but if you are interested, I will do it for consoletestrunner.pas

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: FPCUnit returns 2 error level if tests failed
« Reply #3 on: February 16, 2022, 02:15:26 pm »
  Yes, it is, I had to run tests through an additional wrapper bat file. to cheat a server script that I don't have access to. I think an additional command line key to configure the behavior would be a good solution.

You don't need a wrapper, you simply need to adjust your main program file:

Code: Pascal  [Select][+][-]
  1. var
  2.   Application: TTestRunner;
  3.  
  4. begin
  5.   Application := TTestRunner.Create(nil);
  6.   Application.Initialize;
  7.   Application.Title := 'My unit tests';
  8.   Application.Run;
  9.   Application.Free;  
  10.   ExitCode := 0;
  11. end.
  12.  

Whether you do this or Application.UpdateExitCode := False or whatever isn't that much of a difference...

  I also ran into a problem in the time format. FPCUnit does not have a time format setting, always HH:MM:SS.FF but most test systems (like junit) wait time in seconds SS.FF It is also desirable to add this setting to FPCUnit

And using the JUnit format is no solution for you? (using --format=junit)

zamtmn

  • Hero Member
  • *****
  • Posts: 681
Re: FPCUnit returns 2 error level if tests failed
« Reply #4 on: February 16, 2022, 02:59:59 pm »
>>You don't need a wrapper, you simply need to adjust your main program file:
I know that. I want to run the same source code in different situations in different ways. If you think it's superfluous, I don't insist

>>And using the JUnit format is no solution for you? (using --format=junit)
This was added recently, I haven't seen it yet. Great, thanks!

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: FPCUnit returns 2 error level if tests failed
« Reply #5 on: February 16, 2022, 03:55:20 pm »
>>You don't need a wrapper, you simply need to adjust your main program file:
I know that. I want to run the same source code in different situations in different ways. If you think it's superfluous, I don't insist

Well, you can file a bug report if you want. It's mainly MvC who maintains FPCUnit...

>>And using the JUnit format is no solution for you? (using --format=junit)
This was added recently, I haven't seen it yet. Great, thanks!

Ah, hadn't seen that it was only added recently... :-[

zamtmn

  • Hero Member
  • *****
  • Posts: 681
Re: FPCUnit returns 2 error level if tests failed
« Reply #6 on: February 16, 2022, 04:02:21 pm »
>>Well, you can file a bug report if you want. It's mainly MvC who maintains FPCUnit...
You sound like you're suggesting I play the lottery. I don't understand such a policy

PascalDragon

  • Hero Member
  • *****
  • Posts: 6356
  • Compiler Developer
Re: FPCUnit returns 2 error level if tests failed
« Reply #7 on: February 17, 2022, 09:02:20 am »
I'm saying that I'm not the one maintaining FPCUnit. So if you want to have something changed there then ask someone who does and MvC is the one. However as he doesn't frequent this forum the place to ask is the bug tracker which is the place anyway to do feature requests.

zamtmn

  • Hero Member
  • *****
  • Posts: 681
Re: FPCUnit returns 2 error level if tests failed
« Reply #8 on: February 17, 2022, 10:01:16 am »
OK, thanks!

n7800

  • Hero Member
  • *****
  • Posts: 650
  • Lazarus IDE contributor
    • GitLab profile
Re: FPCUnit returns 2 error level if tests failed
« Reply #9 on: February 07, 2026, 02:43:55 am »
Just for reference: the patch was proposed in #39587 by the author, edited and applied by Michael, and slightly fixed by me. We're a great team ))

 

TinyPortal © 2005-2018