[fpc-devel] Free Pascal/Delphi compatibility cross-tests

Dmitriy Pomerantsev pda2 at yandex.ru
Sat Mar 25 23:49:25 CET 2017


Hello everyone.

In my free time, I write a small (so far) set of tests to verify the compatibility of Delphi and Free Pascal. The main idea: Delphi has DUnit2, Free Pascal has fpcunit and it is partially compatible with DUnit2. Therefore, you can write tests that can be runned simultaneously in Delphi and Free Pascal.

The repository is located https://github.com/pda0/fp_cross_tests

Now there are not many ready-made tests. There are for TGuidHelper, TSingleHelper, TDoubleHelper and TExtendedHelper (I started with them, because it's not easy to test methods handling of floating point numbers). Write tests for the integer types will be easier.

Right now you can not just take Lazarus, trunk Free Pascal and run these tests. You will need a patches from the "patches" directory.

I myself ran tests on Windows 7 Delphi 10.2 Berlin Pro (i386 and x86_64), as well as on trunk Free Pascal 3.1.1 (i386 and x86_64). In addition, I ran them on Fedora 25 Linux (i386 and x86_64).

I need your opinion. Is it interesting to anyone besides me?

I need your help. I do not have access to a big endian machine and I don't know how correctly these tests will work there.

In addition, certain lines cause problems. In particular, lines

CheckException(BytesRangeOverflow, ERangeError);

and

CheckException(WordsRangeOverflow, ERangeError);

in files Test.SysUtils.TSingleHelper.pas, Test.SysUtils.TDoubleHelper.pas and Test.SysUtils.TExtendedHelper.pas are have to to test out of range situation. But despite the use of the SysUtils module, Free Pascal generates a runtime error, interrupting further execution of the tests. I still do not understand why.

If we temporarily remove them, we will see a number of problems.

1. Difference in implementation.
  For example, in Delphi, Exponent has a bias "For single precision floating-point values, the bias is 127." (http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.SysUtils.TsingleHelper.Exponent), Free Pascal does not (http://www.freepascal.org/docs-html/rtl/sysutils/tsinglehelper.exponent.html).
  Delphi returns Mantissa with a hidden bit "Mantissa, also known as the significand, is the raw fraction part of the number with the 1 bit before it." (http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.SysUtils.TsingleHelper.Mantissa), Free Pascal - does not "Mantissa is the value of the significand without the hidden bit." (http://www.freepascal.org/docs-html/rtl/sysutils/tsinglehelper.mantissa.html).

2. String handling differences. Free Pascal returns +Infinity as "+INF", Delphi as "INF". It can be important for programs that wait for certain literals. In addition, Free Pascal can convert literals "+INF", "-INF", "NAN" to floats, Delphi - does not. Some numbers are differently converted to strings. For example, 2.8E32 in Delphi turns into "2.8E32", and in Free Pascal is in "280000005400000000000000000000.00".

So what do you think?

Dmitriy Pomerantsev.



More information about the fpc-devel mailing list