Skip to content

Commit

Permalink
adds tests for codedup rule (#22)
Browse files Browse the repository at this point in the history
* adds tests for codedup rule
* bump debian changelog
  • Loading branch information
psycofdj committed Jun 15, 2017
1 parent aaa24fe commit fa2b769
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 19 deletions.
21 changes: 21 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
xtdmake (1.2.0ppa1~xenial) xenial; urgency=medium

* adds codedup rule to detect code duplication
* handle MIN_VERSION in xtdmake_find_program

-- Xavier MARCELET <xavier@marcelet.com> Thu, 15 Jun 2017 22:56:53 +0200

xtdmake (1.2.0ppa1~trusty) trusty; urgency=medium

* adds codedup rule to detect code duplication
* handle MIN_VERSION in xtdmake_find_program

-- Xavier MARCELET <xavier@marcelet.com> Thu, 15 Jun 2017 22:56:53 +0200

xtdmake (1.2.0ppa1~precise) precise; urgency=medium

* adds codedup rule to detect code duplication
* handle MIN_VERSION in xtdmake_find_program

-- Xavier MARCELET <xavier@marcelet.com> Thu, 15 Jun 2017 22:56:53 +0200

xtdmake (1.1.0ppa1~xenial) xenial; urgency=medium

* allow external reports in xtdmake interface and graphs
Expand Down
8 changes: 5 additions & 3 deletions src/codedup/FindCodeDupRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ xtdmake_find_program(Xsltproc
URL "http://xmlsoft.org/"
VERSION_OPT " --version | head -n1 | cut -d' ' -f3 | sed 's/,//g'"
VERSION_POS "0"
REQUIRED CppcheckRule_FIND_REQUIRED)
REQUIRED ${CppcheckRule_FIND_REQUIRED})

xtdmake_find_program(Java
NAMES java
DOC "Java runtime environment"
URL "http://openjdk.java.net/"
REQUIRED CodeDupRule_FIND_REQUIRED
REQUIRED ${CodeDupRule_FIND_REQUIRED}
VERSION_OPT "-version 2>&1 | head -n1 | cut -d' ' -f3 | sed 's/\"//g' | cut -d_ -f1"
VERSION_POS 0)
VERSION_POS 0
MIN_VERSION 1.8.0)


if (NOT EXISTS "${CodeDupRule_PMD_HOME}/lib/pmd-core-${CodeDupRule_PMD_VERSION}.jar")
set(Pmd_FOUND 0)
Expand Down
4 changes: 2 additions & 2 deletions src/doc/FindDocRule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ xtdmake_find_program(Doxygen
URL "http://www.doxygen.org/"
VERSION_OPT "--version"
VERSION_POS "0"
REQUIRED DocRule_FIND_REQUIRED)
REQUIRED ${DocRule_FIND_REQUIRED})

xtdmake_find_program(Plantuml
NAMES plantuml
Expand All @@ -21,7 +21,7 @@ xtdmake_find_program(Dot
DOC "Graph drawing tools"
URL "http://www.graphviz.org/"
VERSION_OPT "-V 2>&1"
VERSION_POS "0")
VERSION_POS "4")

if (NOT Doxygen_FOUND)
set(DocRule_FOUND 0)
Expand Down
37 changes: 31 additions & 6 deletions src/xtdmake_find_program.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro(xtdmake_find_program var)
if (NOT DEFINED ${var}_FOUND)
set(multiValueArgs NAMES)
set(oneValueArgs DOC URL REQUIRED VERSION_OPT VERSION_POS)
set(oneValueArgs DOC URL REQUIRED VERSION_OPT VERSION_POS MIN_VERSION TOTO)
set(options NOWARNING)
cmake_parse_arguments(x
"${options}"
Expand All @@ -14,9 +14,15 @@ macro(xtdmake_find_program var)
DOC ${x_DOC}
${x_UNPARSED_ARGUMENTS})

if (${var}_EXECUTABLE)
set(${var}_FOUND 1 CACHE STRING "Program found")

set(l_found 0)
set(l_error "")
set(l_cause "")

if (NOT ${var}_EXECUTABLE)
set(l_error "Cannot find required program ${var}, ${x_DOC}, please install at (${x_URL})")
set(l_cause "${x_DOC}, please install at (${x_URL})")
else()
if (NOT ${x_VERSION_OPT} STREQUAL "")
execute_process(
COMMAND bash -c "${${var}_EXECUTABLE} ${x_VERSION_OPT} 2>&1"
Expand All @@ -31,14 +37,33 @@ macro(xtdmake_find_program var)
else()
set(${var}_VERSION "unknown" CACHE STRING "Program version")
endif()
message(STATUS "Found program ${var} : ${${var}_EXECUTABLE} (version \"${${var}_VERSION}\")")

if (x_MIN_VERSION)
if ("${l_version}" VERSION_LESS "${x_MIN_VERSION}")
set(l_error "Found ${var} but detected version ${l_version} is lower to ${x_MIN_VERSION}, please install at ${x_URL}")
set(l_cause "(found ${l_version} but need ${x_VERSION}), please install at (${x_URL})")
else()
set(l_found 1)
set(l_cause "${${var}_EXECUTABLE} (version \"${${var}_VERSION}\")")
endif()
else()
set(l_found 1)
set(l_cause "${${var}_EXECUTABLE} (version \"${${var}_VERSION}\")")
endif()

endif()

if (l_found)
set(${var}_FOUND 1 CACHE STRING "Program found")
message(STATUS "Found program ${var} : ${l_cause}")
else()
set(${var}_FOUND 0 CACHE STRING "Program found")
if (${x_REQUIRED})
message(SEND_ERROR "Cannot find required program ${var}, ${x_DOC}, please install at (${x_URL})")
message(SEND_ERROR "${l_error}")
elseif(NOT ${x_NOWARNING} STREQUAL "TRUE")
message(STATUS "Found program ${var} : FALSE")
message(STATUS "Found program ${var} : FALSE, ${l_cause}")
endif()
endif()

endif()
endmacro()
14 changes: 12 additions & 2 deletions tests/Dockerfile.precise
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM ubuntu:12.04


RUN apt-get update -y && \
apt-get install -y \
cmake \
Expand All @@ -15,12 +16,21 @@ RUN apt-get update -y && \
libboost-dev \
libboost-thread-dev \
libcppunit-dev \
wget
RUN apt-get install -y make rcs
wget \
python-software-properties \
make \
rcs \
unzip \
debconf-utils

RUN apt-add-repository -y ppa:webupd8team/java
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN apt-get update -y && apt-get install -y oracle-java8-installer
RUN wget -O /usr/bin/cloc 'https://github.com/AlDanial/cloc/releases/download/v1.70/cloc-1.70.pl'
RUN chmod +x /usr/bin/cloc
RUN pip install coverxygen
RUN wget -O /tmp/pmd-bin-5.7.0.zip 'https://github.com/pmd/pmd/releases/download/pmd_releases%2F5.7.0/pmd-bin-5.7.0.zip'
RUN unzip -d /usr/share/ /tmp/pmd-bin-5.7.0.zip
RUN mkdir -p /env
COPY ./src /env/src
COPY ./tests /env/tests
Expand Down
15 changes: 13 additions & 2 deletions tests/Dockerfile.trusty
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ RUN apt-get update -y && \
g++ \
libboost-dev \
libboost-thread-dev \
libcppunit-dev
libcppunit-dev \
python-software-properties \
debconf-utils \
wget \
unzip \
rcs

RUN apt-get install -y rcs

RUN apt-get install -y software-properties-common
RUN apt-add-repository -y ppa:webupd8team/java
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN apt-get update -y && apt-get install -y oracle-java8-installer
RUN pip install coverxygen
RUN wget -O /tmp/pmd-bin-5.7.0.zip https://github.com/pmd/pmd/releases/download/pmd_releases%2F5.7.0/pmd-bin-5.7.0.zip
RUN unzip -d /usr/share/ /tmp/pmd-bin-5.7.0.zip
RUN mkdir -p /env
COPY ./src /env/src
COPY ./tests /env/tests
Expand Down
8 changes: 6 additions & 2 deletions tests/Dockerfile.xenial
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ RUN apt-get update -y && \
g++ \
libboost-dev \
libboost-thread-dev \
libcppunit-dev
libcppunit-dev \
openjdk-8-jre \
wget

RUN apt-get install -y rcs
RUN apt-get install -y rcs unzip
RUN pip install coverxygen
RUN wget -O /tmp/pmd-bin-5.7.0.zip https://github.com/pmd/pmd/releases/download/pmd_releases%2F5.7.0/pmd-bin-5.7.0.zip
RUN unzip -d /usr/share/ /tmp/pmd-bin-5.7.0.zip
RUN mkdir -p /env
COPY ./src /env/src
COPY ./tests /env/tests
Expand Down
3 changes: 2 additions & 1 deletion tests/build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fi

l_checks=(check/m1/index.html cppcheck/m1/index.html doc-coverage/m1/index.html
check/m1/status.json cppcheck/m1/status.json doc-coverage/m1/status.json
cloc/m1/index.html doc-coverage/m1/data.json cloc/m1/status.json)
cloc/m1/index.html doc-coverage/m1/data.json cloc/m1/status.json
codedup/m1/index.html codedup/m1/codedup.xml codedup/m1/status.json)

if [ "${l_buildType}" == "Debug" ]; then
l_checks+=(coverage/m1/status.json coverage/m1/index.html)
Expand Down
1 change: 1 addition & 0 deletions tests/default/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ xtdmake_init(
Cppunit ${REQUIRED}
CovRule ${REQUIRED}
MemcheckRule ${REQUIRED}
CodeDupRule ${REQUIRED}
Reports ${REQUIRED})

enable_tracking()
Expand Down
2 changes: 1 addition & 1 deletion tests/default/m1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_doc(m1)
add_doc_coverage(m1)
add_cloc(m1)
add_cppcheck(m1)

add_codedup(m1)
add_check_test(m1 MyTest
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/unit/test.sh
ENVIRONMENT var=toto
Expand Down

0 comments on commit fa2b769

Please sign in to comment.