Skip to content

Commit

Permalink
Merge pull request #756 from guwirth/enhancement/CxxProjectBuilder
Browse files Browse the repository at this point in the history
add an integration test example with absolute paths
  • Loading branch information
guwirth committed Jan 13, 2016
2 parents 3c4b7df + 99f51fa commit 397d9a9
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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(??)
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.61"/>
<errors>
<error id="unusedVariable" severity="style" msg="Unused variable: x" verbose="Unused variable: x">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="15"/>
</error>
<error id="unreadVariable" severity="style" msg="Variable 'i' is assigned a value that is never used." verbose="Variable 'i' is assigned a value that is never used.">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="35"/>
</error>
<error id="deallocDealloc" severity="error" msg="Deallocating a deallocated pointer: ip" verbose="Deallocating a deallocated pointer: ip">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="45"/>
</error>
<error id="doubleFree" severity="error" msg="Memory pointed to by 'ip' is freed twice." verbose="Memory pointed to by 'ip' is freed twice.">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="45"/>
</error>
<error id="uninitvar" severity="error" msg="Uninitialized variable: a" verbose="Uninitialized variable: a">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="30"/>
</error>
<error id="unusedFunction" severity="style" msg="The function 'do_valgrind_errors' is never used." verbose="The function 'do_valgrind_errors' is never used.">
<location file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cppcheck_with_absolute_paths_project/src/sample/component1.cc" line="22"/>
</error>
</errors>
</results>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef COMPONENT1_HH
#define COMPONENT1_HH

class Bar {
public:
int foo();
void do_valgrind_errors();
};
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <component1.hh>

int main(int argc, char* argv[])
{
return Bar().foo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

/**
Expand Down

0 comments on commit 397d9a9

Please sign in to comment.