Recent

Author Topic: FPC 3.0.0: advice re dunit, initc  (Read 5187 times)

pascalpopper

  • Newbie
  • Posts: 4
FPC 3.0.0: advice re dunit, initc
« on: December 03, 2015, 01:04:02 am »
Re FPC 3.0.0, I am wondering:

Which dunit system is best to use for maximum compatibility with recent versions of Delphi? (I tried what I believe is the latest fptest via svn update and the output at cmd level had too many ? symbols for my taste.)  Is anyone using unit-test source code that they share easily between Delphi DX10 and FPC 3.0.0 ?  Console output or GUI ?  I need something that can show unicode output without distortion because I need to test string content carefully.

Why is the initc unit shipped for win32 rtl but not win64 ?  After install, I find i386-win32\rtl\initc.o and .ppu  but nothing in the win64 area for that unit.  I found this source file, https://github.com/graemeg/freepascal/blob/master/rtl/win32/initc.pp, which compiles using win64 as long as the "property" line 23 is commented out.  Not sure what is going on with a property of a unit.  Is there a new/better cross-platform way to get the last system error number as an integer ??

The good news is that I have some of my core units compiling with FPC 3.  Now I just need to find out whether any of the code actually works. 

Seriously, congratulations on a big milestone with version 3.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC 3.0.0: advice re dunit, initc
« Reply #1 on: December 03, 2015, 04:27:32 am »
Is there a new/better cross-platform way to get the last system error number as an integer ??
http://www.freepascal.org/docs-html/rtl/sysutils/getlastoserror.html

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7510
Re: FPC 3.0.0: advice re dunit, initc
« Reply #2 on: December 03, 2015, 09:27:20 am »
afiak initc on windows is only a service unit to keep libgdb working in the IDE. IOW contrary to initc on *nix, it is not really an unit meant for end users.

This is visible in the cygwin dependency (and outdated anyway, since libgdb stopped using cygwin and switched mingw years ago)

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: FPC 3.0.0: advice re dunit, initc
« Reply #3 on: December 04, 2015, 11:22:11 am »
fptest via svn update and the output at cmd level had too many ? symbols for my taste.)  Is anyone using unit-test source code that they share easily between Delphi DX10 and FPC 3.0.0 ?  Console output or GUI ?  I need something that can show unicode output without distortion because I need to test string content carefully.
I don't fully understand what you mean. What ? symbols?  For unit info and line number information (backtrace), or for failed test output?

If the latter, I don't see the need in using Unicode text in failed test messages either. eg: I write my unit tests as follows:

Code: Pascal  [Select]
  1. procedure TTestTIUtils.tiIntlDateStorAsDateTime;
  2. var
  3.   dt: TDateTime;
  4. begin
  5.   dt := EncodeDate(2006, 1, 18) + EncodeTime(15, 19, 22, 0);
  6.   CheckNearEnough(dt, tiUtils.tiIntlDateStorAsDateTime('20060118T151922'), 'Failed on 1');
  7.  
  8.   dt := EncodeDate(2006, 1, 18);
  9.   CheckEquals(dt, tiUtils.tiIntlDateStorAsDateTime('20060118T000000'), 'Failed on 2');
  10.  
  11.   dt := 0;
  12.   CheckEquals(dt, tiUtils.tiIntlDateStorAsDateTime('00000000T000000'), 'Failed on 3');
  13.  
  14.   dt := EncodeTime(9, 10, 41, 22);
  15.   CheckNearEnough(dt, tiUtils.tiIntlDateStorAsDateTime('00000000T091041'), 'Failed on 4');
  16.  
  17.   dt := EncodeDate(1652, 6, 15) + EncodeTime(12, 34, 56, 12);
  18.   CheckNearEnough(dt, tiUtils.tiIntlDateStorAsDateTime('16520615T123456'), 'Failed on 5');
  19. end;
  20.  


Note that I always use error messages in the format "Failed on xxx", meaning if I get a failed report that says "TTestTIUtils.tiIntlDateStorAsDateTime failed on 5", I immediately know where to look in the unit tests, and know exactly what test failed.  In this case, I never need to bother with unicode output.

Can you give an example of a test case where you have ? symbol (assuming Unicode) issues?

Saying all that, FPC 3.0 has just been release - I haven't had the time to test FPTest thoroughly with FPC 3.0 yet.  But I would imaging that the RTL's TextCompare(), SameText() etc should handle Unicode text comparisons correctly. If not, that is likely an issue with FPC, not FPTest. FPTest uses the generic String data type, I still need to investigate how that translates in FPC 3.0

As for unit testing frameworks and compatibility with Delphi. In that case, use DUnit2 for Delphi and FPTest for FPC. The FPTest code is a fork of DUnit2, and both frameworks are used successfully in tiOPF's test suite - which is Delphi and FPC compatible.
« Last Edit: December 04, 2015, 11:24:02 am by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8112
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FPC 3.0.0: advice re dunit, initc
« Reply #4 on: December 04, 2015, 12:20:58 pm »
I don't fully understand what you mean. What ? symbols?  For unit info and line number information (backtrace), or for failed test output?
From the next paragraph, I assume it's unicode characters which are not properly displayed so they become ? in the console output. No idea about this though, I haven't tried testing unicode string with fptest myself.

pascalpopper

  • Newbie
  • Posts: 4
Re: FPC 3.0.0: advice re dunit, initc
« Reply #5 on: December 05, 2015, 02:28:53 am »
Confirming: GetLastOSError in SysUtils solves my initc issue. THANKS.

Will sort through the DUnit advice next...

pascalpopper

  • Newbie
  • Posts: 4
Re: FPC 3.0.0: advice re dunit, initc
« Reply #6 on: December 07, 2015, 06:50:40 am »
Confirming: I am compiling in FPC 3 with the TextTestRunner and the ftptest files.  I gather the GUITestRunner requires installation of some more files to get fpg_base and I am going to avoid all that for now and see how far I can get with the text output.

The ?? symbols in the output were my own fault.  I didn't remember that I had this line in my console app from years ago,

  WriteLn(ModuleFilename);

And THAT was not working in FPC the same as in Delphi because I wasn't calling the WIDE api.  When I changed from GetModuleFileName to GetModuleFileNameW, the data was fine and the ?? symbols disappeared.

This is very encouraging, actually.

Graeme

  • Hero Member
  • *****
  • Posts: 1430
    • Graeme on the web
Re: FPC 3.0.0: advice re dunit, initc
« Reply #7 on: December 10, 2015, 12:24:30 pm »
Confirming: I am compiling in FPC 3 with the TextTestRunner and the ftptest files.  I gather the GUITestRunner requires installation of some more files to get fpg_base and I am going to avoid all that for now and see how far I can get with the text output.
I'm glad you got the symbol issue sorted out. The FPTest TextTestRunner works very well, and I use it often. It is also handy to use it to see if there are any memory leaks (when compiled with FPC -gl -gh parameters).

But sometimes I love the visual look of a green bar success to show I have made progress, so then I use the GUI Runners. There are fpGUI and LCL versions available. They require their respective GUI toolkits to compile.

The GUI Runners also make it much easier to manage the tests (and changes stored in fptest.ini). You get a nice visual tree hierarchy, you can easily select or deselect which tests you want to run, jump to failing tests, auto select only failed tests etc.  Regarding this, I am working on improvements for the TextTestRunner to more easily specify exact tests to run (without reading them from the fptest.ini file) - this will help with debugging failing tests via a IDE (running only the test to debug).

If you haven't seen yet, here is a screenshot of the FPTest GUI Runner under fpGUI.
  http://wiki.freepascal.org/FPTest#Screenshots
« Last Edit: December 10, 2015, 12:27:35 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/