From 99f51fab3f80d610d0daa65ea1a716168c731a8f Mon Sep 17 00:00:00 2001 From: guwirth Date: Mon, 11 Jan 2016 18:38:28 +0100 Subject: [PATCH] - add an integration test example with absolute paths - use ${TestDataFolder} in config file (~/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata) - add list of available property keys to log file --- .travis.yml | 4 +- .../importing_cppcheck_reports.feature | 8 ++- .../reports/cppcheck-v2.xml | 24 +++++++++ .../sonar-project.properties | 15 ++++++ .../src/sample/component1.cc | 50 +++++++++++++++++++ .../src/sample/component1.hh | 9 ++++ .../src/sample/main.cc | 6 +++ .../sonar/plugins/cxx/CxxProjectBuilder.java | 13 +++++ 8 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 integration-tests/testdata/cppcheck_with_absolute_paths_project/reports/cppcheck-v2.xml create mode 100644 integration-tests/testdata/cppcheck_with_absolute_paths_project/sonar-project.properties create mode 100644 integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc create mode 100644 integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.hh create mode 100644 integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/main.cc diff --git a/.travis.yml b/.travis.yml index 70d9e2d211..3f31f4e0d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,8 +50,8 @@ before_script: script: - mvn install -DskipTests=true - mvn test - - RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin behave - + - RAILS_ENV=production PATH=$PATH:/tmp/sonar-runner-2.4/bin TestDataFolder=~/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata behave + after_failure: - cat $SONARHOME/logs/sonar.log - find . -name "*.log" | xargs cat diff --git a/integration-tests/features/importing_cppcheck_reports.feature b/integration-tests/features/importing_cppcheck_reports.feature index b2a28f812c..372228045c 100644 --- a/integration-tests/features/importing_cppcheck_reports.feature +++ b/integration-tests/features/importing_cppcheck_reports.feature @@ -75,7 +75,13 @@ Feature: Importing Cppcheck reports """ AND the number of violations fed is 0 - + Scenario: The reports and issues in the reports have absolute paths + GIVEN the project "cppcheck_with_absolute_paths_project" + WHEN I run "sonar-runner -X" + THEN the analysis finishes successfully + AND the server log (if locatable) contains no error/warning messages + AND the number of violations fed is 6 + # This doesnt work. We dont support reports outside of the projects directory, # although there is no good reason for that(??) # diff --git a/integration-tests/testdata/cppcheck_with_absolute_paths_project/reports/cppcheck-v2.xml b/integration-tests/testdata/cppcheck_with_absolute_paths_project/reports/cppcheck-v2.xml new file mode 100644 index 0000000000..1a332ae443 --- /dev/null +++ b/integration-tests/testdata/cppcheck_with_absolute_paths_project/reports/cppcheck-v2.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/testdata/cppcheck_with_absolute_paths_project/sonar-project.properties b/integration-tests/testdata/cppcheck_with_absolute_paths_project/sonar-project.properties new file mode 100644 index 0000000000..ab8d88fd0a --- /dev/null +++ b/integration-tests/testdata/cppcheck_with_absolute_paths_project/sonar-project.properties @@ -0,0 +1,15 @@ +# required metadata +sonar.projectKey=cppcheck_with_absolute_paths_project +sonar.projectName=cppcheck_with_absolute_paths_project +sonar.projectVersion=1.0.0 +sonar.language=c++ + +# disable SCM support +sonar.scm.disabled=true + +# path to source directories +sonar.sources=. +sonar.cxx.includeDirectories=. + +# paths to the reports +sonar.cxx.cppcheck.reportPath=${TestDataFolder}/cppcheck_with_absolute_paths_project/reports/cppcheck-*.xml diff --git a/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc new file mode 100644 index 0000000000..fc9fd59754 --- /dev/null +++ b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc @@ -0,0 +1,50 @@ +#include \ + "component1.hh" + +/** + * Does something + * + * @return: an int indicating something + */ +int Bar::foo(){ + // single line comment + + /* + * multi-line comment + */ + int \ + x; //unused variable + + return 111; +} + + +void Bar::do_valgrind_errors(){ + ///// lets provoke some valgrind errors ///// + + // Memory leak (definitely lost) + new float(); + + // Condition depends on undefined value + int a; + if(a) a = a*a; + + // Invalid read + int* ip = new int(0); + delete ip; + int i = *ip; + + // Invalid write + ip = new int(0); + delete ip; + *ip = 1; + + // Invalid free + ip = new int(0); + delete ip; + delete ip; + + // Mismatched free() / delete / delete [] + ip = new int(0); + delete [] ip; +} diff --git a/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.hh b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.hh new file mode 100644 index 0000000000..de73f1a274 --- /dev/null +++ b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.hh @@ -0,0 +1,9 @@ +#ifndef COMPONENT1_HH +#define COMPONENT1_HH + +class Bar { +public: + int foo(); + void do_valgrind_errors(); +}; +#endif diff --git a/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/main.cc b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/main.cc new file mode 100644 index 0000000000..716bdf7734 --- /dev/null +++ b/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/main.cc @@ -0,0 +1,6 @@ +#include + +int main(int argc, char* argv[]) +{ + return Bar().foo(); +} diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxProjectBuilder.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxProjectBuilder.java index 8b983ace3f..f94355a54d 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxProjectBuilder.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxProjectBuilder.java @@ -80,6 +80,19 @@ public void build(Context context) { LOG.debug("property expansion: key '{}'; value '{}' => '{}'", new Object[]{key, oldValue, newValue}); } } + + // add list of available property keys + if (LOG.isDebugEnabled()) { + StringBuilder sb = new StringBuilder("analysis parameters:\n"); + for (String key : props.stringPropertyNames()) { + sb.append(" "); + sb.append(key); + sb.append("="); + sb.append(props.getProperty(key)); + sb.append("\n"); + } + LOG.debug(sb.toString()); + } } /**