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

Adding a test with cppcheck for Travis CI #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2016 Branden Archer <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are interested in adding the LGPL header to the file, can you do so in a separate commit?

Copy link
Author

Choose a reason for hiding this comment

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

Ok. #57

# Copyright (C) 2016 Joshua D. Boyd <[email protected]>
# Copyright (C) 2016 Nicola Spanti <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -35,6 +36,7 @@ addons:
apt:
packages:
- texinfo
- cppcheck

matrix:
exclude:
Expand All @@ -45,11 +47,12 @@ matrix:
env: USE_CMAKE=YES

script:
- if [ ${TRAVIS_OS_NAME} = 'linux' ]; then cppcheck --verbose --quiet --error-exitcode=1 --force --enable=performance,portability src/ tests/; fi
- mkdir build
- cd build
- if [ $USE_CMAKE == "YES" ] ; then cmake ../ ; fi
- if [ $USE_CMAKE == "NO" ] ; then pushd ../ ; autoreconf -i ; popd; fi
- if [ $USE_CMAKE == "NO" ] ; then ../configure ; fi
- if [ $USE_CMAKE == 'YES' ] ; then cmake .. ; fi
- if [ $USE_CMAKE == 'NO' ] ; then pushd .. ; autoreconf -i ; popd; fi
- if [ $USE_CMAKE == 'NO' ] ; then ../configure ; fi
- make
- if [ $USE_CMAKE == "YES" ] ; then CTEST_OUTPUT_ON_FAILURE=1 make test ; fi
- if [ $USE_CMAKE == "NO" ] ; then make check ; fi
- if [ $USE_CMAKE == 'YES' ] ; then CTEST_OUTPUT_ON_FAILURE=1 make test ; fi
- if [ $USE_CMAKE == 'NO' ] ; then make check ; fi
7 changes: 3 additions & 4 deletions src/check_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ static int percent_passed(TestStats * t)
{
if(t->n_failed == 0 && t->n_errors == 0)
return 100;
else if(t->n_checked == 0)
if(t->n_checked == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these style changes or logic changes? Are these because cppcheck indicated an issue?

As least for cppcheck 1.74 no issues were detected in the src dir. The test dir did mention the following:

[tests/check_check_pack.c:323] -> [tests/check_check_pack.c:328]: (warning) Either the condition 'rmsg!=0' is redundant or there is possible null pointer dereference: rmsg.

Which seems to indicate that there is a redundant null check. The following resolves this:

diff --git a/tests/check_check_pack.c b/tests/check_check_pack.c
index 7da7e57..dd5d557 100644
--- a/tests/check_check_pack.c
+++ b/tests/check_check_pack.c
@@ -325,7 +325,6 @@ START_TEST(test_ppack_onlyctx)
   ck_assert_msg (rmsg->test_line == -1,
               "Result loc line should be -1 with only CTX");

-  if (rmsg != NULL)
     free (rmsg);
   fclose(result_file);
 }

Would you mind including this into your pull request, to remove all errors/warnings before enabling the check?

Copy link
Author

Choose a reason for hiding this comment

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

No it is very small modification, so I putted it with cppcheck. else is useless as return in the previous exit the function if the test is true.

return 0;
else
return (int)((float)(t->n_checked - (t->n_failed + t->n_errors)) /
(float)t->n_checked * 100);
return (int)((float)(t->n_checked - (t->n_failed + t->n_errors)) /
(float)t->n_checked * 100);
}