Master gtest-gnc-datetime test fails.

John Ralls jralls at ceridwen.us
Sat Apr 15 12:12:31 EDT 2017


> On Apr 15, 2017, at 8:41 AM, Geert Janssens <geert.gnucash at kobaltwit.be> wrote:
> 
> On zaterdag 15 april 2017 16:15:00 CEST John Ralls wrote:
>>> On Apr 15, 2017, at 4:27 AM, Robert Fewell <14ubobit at gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> Built current master on my Linux VM and tried to run the tests but it
>>> fails
>>> on the following test, if they are commented out all other tests run
>>> successfully.
>>> 
>>> Checked my time zone information to be Europe/London
>>> 
>>> I think the offset is the difference between local time and utc time, so
>>> the first two failures are comparing times in GMT to UTC which I think are
>>> the same so expect 0 and the last one is after we have switched to BST and
>>> so 3600 makes sense to me.
>>> 
>>> zdump /etc/localtime
>>> /etc/localtime  Sat Apr 15 12:14:57 2017 BST
>>> 
>>> 
>>> gtest-gnc-datetime.cpp:103: Failure
>>> Value of: gncdt1.offset()
>>> 
>>> Actual: 0
>>> 
>>> Expected: -28800
>>> gtest-gnc-datetime.cpp:105: Failure
>>> Value of: gncdt2.offset()
>>> 
>>> Actual: 0
>>> 
>>> Expected: -25200
>>> gtest-gnc-datetime.cpp:107: Failure
>>> Value of: gncdt3.offset()
>>> 
>>> Actual: 3600
>>> 
>>> Expected: -25200
>>> 
>>> Not sure how to fix apart from changing the expected values.
>> 
>> The tests are checking that the offset is calculated correctly and works
>> only in Pacific Time (UTC - 8:00). If you run TZ=America/LosAngeles make
>> check
>> it will pass.
>> 
> Is setting the timezone something that's part of the Makefile/cmake invocation 
> of this test ?
> 
> Or better yet is this something that could be made part of the test source 
> itself ? Just wondering if we can set environment variable TZ at the beginning 
> of the test code (not in the makefile/cmake script but really in the C++ 
> source). Would the test then still pick this up as the timezone to use or 
> would that be too late ?

Geert,

No, it's not part of the build scripts and, as you know, we set the TZ in .travis.yml for that reason.

I think that setting TZ in the test program would be too late for the default TZ provider because it's a static in gnc-datetime.cpp so it gets created before main() runs.  What we can do is use either GncDateTime(struct tm) or GncDateTime(const std::string&), both of which include a timezone. Better yet, do both, and for multiple TZs.

Another approach (for another test, the more the merrier when it comes to test cases) would be to determine the current TZ's offset and check that against what GncDateTime::offset().

Regards,
John Ralls


More information about the gnucash-devel mailing list