Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test framework, C++11 compilation mode and warning fixes #1021

Merged
merged 5 commits into from
May 30, 2018

Conversation

rouault
Copy link
Member

@rouault rouault commented May 29, 2018

3 somewhat related topics:

  • Fix warnings found by clang with new warning flags to be added in later commit
    Fixes consist in:
    • no use of comma operator for multi statement purpose
    • avoid confusing comma in for loops first and third clauses
    • addition of explicit long to int casts
  • Enable c++11 compilation with autotools and cmake, hardened compilation flags and add catch2 framework. Hardened compilation flags come from GDAL' configure.ac and are 'combat proven'. Dummy test added just to demonstrate catch2 based tests work.
  • CI environment: adapt for C++11 capable environments

Copy link
Member

@kbevers kbevers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give this a more thorough look tomorrow. For now I have once immediate comment:

addition of explicit long to int casts

This just seem to be screwing with what was done in #949. It may be that the type conversions can be done safer with a C++ compiler, but if that is the case this should be reverted more carefully to what it was before #949. There's going to be a bunch of unnecessary floor()s and lround()s otherwise.

@rouault rouault force-pushed the add_test_framework branch from 472ed39 to ea8098d Compare May 29, 2018 23:02
@rouault
Copy link
Member Author

rouault commented May 29, 2018

. It may be that the type conversions can be done safer with a C++ compiler

Not related at all with C++. .c files are still compiled with the C compiler. This is with the C compiler of clang with the -Wshorten-64-to-32 warning that warns when a long is implicitly cast to int. Basically, the cast makes it more obvious that we may have a truncation issue.

@rouault rouault force-pushed the add_test_framework branch from ea8098d to ea49d58 Compare May 29, 2018 23:27
@rouault
Copy link
Member Author

rouault commented May 29, 2018

I've revised the 'int x = (int)long_variable' casts to rather promote the storage type to long when possible, and when not practical adding explicit bound checking

@rouault rouault force-pushed the add_test_framework branch 3 times, most recently from f9e4616 to 9f08e49 Compare May 30, 2018 00:14
test/Makefile.am Outdated
@@ -1,3 +1,3 @@
SUBDIRS = gie gigs
SUBDIRS = gie gigs cpp
Copy link
Member

@mloskot mloskot May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/cpp - this is an unfortunate name as too generic, assuming the tests may be re-organized at some point, as @kbevers suggested on the list.

The structure could aim for something like

tests/gigs
tests/gie
tests/unit
tests/functional - might or might not be needed, as per the recent discussion on list
tests/apps
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK see 6fbfa8e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wished @kbevers commented on my comment first in case he disagrees, but LGMT, thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mloskot I think your suggested structure looks good

Copy link
Member

@kbevers kbevers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I've only got a few minor suggestions regarding the code changes to avoid warnings.

You've put the catch header in test/cpp/. Does that imply that we will be putting all catch tests in that directory? Or did it just go there for practical reasons? I am just thinking if it would be better to put it a level higher so we can have something like test/cpp/, test/apps/, test/whatever/ giving a bit of structure to the test framework while lowering the depth of the file tree. Just a thought.

src/dmstor.c Outdated
@@ -34,15 +34,19 @@ dmstor_ctx(projCtx ctx, const char *is, char **rs) {
*rs = (char *)is;
/* copy sting into work space */
while (isspace(sign = *is)) ++is;
for (n = MAX_WORK, s = work, p = (char *)is; isgraph(*p) && --n ; )
n = MAX_WORK;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are indented a level too much. Makes them look like they belong to the while loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/gen_cheb.c Outdated
@@ -16,7 +16,9 @@ extern void p_series(Tseries *, FILE *, char *);

void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P,
int iargc, char **iargv) {
int NU = 15, NV = 15, res = -1, errin = 0, pwr;
long NU = 15, NV = 15;
int errin = 0, pwr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation. This line and below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/optargpm.h Outdated
@@ -525,28 +525,40 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
*equals = 0;
c = opt_ordinal (o, crepr);
if (0==c)
return fprintf (stderr, "Invalid option \"%s\"\n", crepr), (OPTARGS *) 0;
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nit-picking, but since the rest of the code in this file has starting brackets at the same line as the statement I think that should be done here for consistency as well. Also, this is how clang-format would do it with the default llvm setup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

p = p1 + len_p1;
h1 = *--p;
for (; p - p1; )
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to comment above. Bracket on same line as statement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

rouault added 5 commits May 30, 2018 11:48
…er commit

Fixes consist in:
- no use of comma operator for multi statement purpose
- avoid confusing comma in for loops first and third clauses
- avoid implicit long to int casts by storing to long, or explicit bound checking before cast
… flags and add catch2 framework

Hardened compilation flags come from GDAL' configure.ac and are
'combat proven'

Dummy test added just to demonstrate catch2 based tests work.
@rouault rouault force-pushed the add_test_framework branch from 26e59cb to 6fbfa8e Compare May 30, 2018 10:06
@kbevers
Copy link
Member

kbevers commented May 30, 2018

Do you mind waiting until 5.1.0 is released to merge this? I'd rather not complicate the release process more than necessary.

@rouault
Copy link
Member Author

rouault commented May 30, 2018

Do you mind waiting until 5.1.0 is released to merge this?

Fine for me. An alternate way of proceeding would be to create a release/5.1 branch from master as soon as we want to 'freeze' it regarding new features and issue releases from it. That's typically how I proceed for GDAL releases, but that can involve some cherry-picking between the release and master branch if there are bugfixes. Anyway, that's not critical for me.

Oh, by the way, I just got my first green build on my WIP branch: https://travis-ci.org/rouault/proj.4/builds/385625895

@kbevers
Copy link
Member

kbevers commented May 30, 2018

An alternate way of proceeding would be to create a release/5.1 branch from master as soon as we want to 'freeze' it regarding new features and issue releases from it.

I was trying to avoid that but the PR's are piling up already so maybe I'll have to do it anyway. Maybe if I can find the time later today I'll do.

Oh, by the way, I just got my first green build on my WIP branch: travis-ci.org/rouault/proj.4/builds/385625895

Awesome!

@rouault
Copy link
Member Author

rouault commented May 30, 2018

It might be good anyway to create a "release/5.1" branch (or perhaps "release/5" ?) before merging this PR, so that we can issue bugfix releases for the 5.x stuff if needed

@kbevers
Copy link
Member

kbevers commented May 30, 2018

That was the plan, yes. It's just going to be "5.1", keeping in line with the existing branches with the same purpose.

@kbevers kbevers merged commit 559e8f1 into OSGeo:master May 30, 2018
@kbevers
Copy link
Member

kbevers commented May 30, 2018

I've created the 5.1 branch so merging won't interrupt my release preparations any more.

Contributors eager to migrate existing tests to Catch2 can get right on it :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants