From 007119f2610131392890e25b55c773b5c26ec1ec Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 31 Oct 2018 11:28:54 +0100
Subject: [PATCH] allow testing in cmake build

---
 .gitlab-ci.yml                 | 25 +++++++++++++++++++++-
 CMake/CMakeLists_library.txt   |  2 +-
 CMake/CMakeLists_root.txt      |  2 +-
 all-cmake-debug.sh             | 38 ++++++++++++++++++++++++++++++++++
 all-cmake-release.sh           | 38 ++++++++++++++++++++++++++++++++++
 cmake-debug.sh                 | 21 -------------------
 makefile                       |  4 ++--
 tests.aarbology.sh             |  6 +++---
 tests.aconversion.sh           |  6 +++---
 tests.aconvert.sh              |  6 +++---
 tests.aderivation.aintegral.sh |  6 +++---
 tests.adeterminize.sh          |  6 +++---
 tests.anormalize.sh            |  6 +++---
 tests.astringology.sh          |  6 +++---
 tests.examples.sh              |  6 +++---
 tests.glushkovrte.sh           |  6 +++---
 tests.glushkovrte_naive.sh     |  6 +++---
 tests.repeats.sh               | 16 +++++++-------
 tniceprint/makefile.conf       |  2 +-
 19 files changed, 143 insertions(+), 65 deletions(-)
 create mode 100755 all-cmake-debug.sh
 create mode 100755 all-cmake-release.sh
 delete mode 100755 cmake-debug.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 76ba0abc5c..d0f4175a51 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -47,7 +47,7 @@ build-gcc:
 build-clang:
   <<: *build
 
-build-cmake:
+build-cmake-clang:
   variables:
     EXTRA_PKGS: cmake python3 py3-click
   script:
@@ -58,6 +58,19 @@ build-cmake:
     - cd release
     - cmake -DCMAKE_BUILD_TYPE=Release ..
     - make
+    - mkdir bin
+    - cd bin
+    - find .. -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) -exec test -x {} \; -print | grep -v 'CMakeFiles' | while read line; do ln -s $line $(basename $line); done
+    - cp ../../translateAddresses .
+    - cp ../../xmlFormat .
+  artifacts:
+    paths:
+      - release/bin
+      - "release/*/a*2" #select binaries
+      - release/tniceprint/tniceprint #explicit binary
+      - "release/*/lib*.so" #select libraries
+      - "release/*/test-alib2*" #select libraries test
+    expire_in: 1 day
   stage: build
 
 build-doc:
@@ -100,3 +113,13 @@ test-clang:
   <<: *test
   dependencies:
     - build-clang
+
+test-cmake-clang:
+  variables:
+    # coreutils are needed because of timeout command used in tests.
+    EXTRA_PKGS: bc coreutils python3
+  script:
+    - for test in $(ls tests.*.sh); do ./${test} release/bin ${JOBS}; touch release/bin/log_tests.txt; cat release/bin/log_tests.txt; done
+  stage: test
+  dependencies:
+    - build-cmake-clang
diff --git a/CMake/CMakeLists_library.txt b/CMake/CMakeLists_library.txt
index 702d7469d7..f9991016f1 100644
--- a/CMake/CMakeLists_library.txt
+++ b/CMake/CMakeLists_library.txt
@@ -26,7 +26,7 @@ set_target_properties(${{PROJECT_NAME}} PROPERTIES
         )
 
 # Install
-install(TARGETS ${{PROJECT_NAME}} LIBRARY DESTINATION bin)
+install(TARGETS ${{PROJECT_NAME}} LIBRARY DESTINATION lib)
 
 ########################################################################################################################
 # cppunit tests
diff --git a/CMake/CMakeLists_root.txt b/CMake/CMakeLists_root.txt
index 14990f191e..2a35d6d294 100644
--- a/CMake/CMakeLists_root.txt
+++ b/CMake/CMakeLists_root.txt
@@ -43,7 +43,7 @@ endif ()
 # Flags according to Debug/Release decision
 #  - CMake uses -g on Debug implicitly
 #  - fPIC for libraries will be enabled explicitly
-set(ALIB_BUILD_FLAGS_COMMON -Wall -pedantic -pipe -Wextra -Werror)
+set(ALIB_BUILD_FLAGS_COMMON -Wall -pedantic -pipe -Wextra -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wdelete-non-virtual-dtor -Wredundant-decls)
 set(ALIB_BUILD_FLAGS_DEBUG ${{ALIB_BUILD_FLAGS_COMMON}} -Og)
 set(ALIB_BUILD_FLAGS_RELEASE ${{ALIB_BUILD_FLAGS_COMMON}} -O3)
 
diff --git a/all-cmake-debug.sh b/all-cmake-debug.sh
new file mode 100755
index 0000000000..bc4671cc54
--- /dev/null
+++ b/all-cmake-debug.sh
@@ -0,0 +1,38 @@
+THREADS=${1:-5}
+DIRECTORY=$(pwd)
+
+cd CMake
+./alib_cmake.py -w -m
+cd ..
+
+if [ ! -d debug ]; then
+  mkdir debug
+fi
+
+if [ -L debug ]; then
+  cd $(readlink debug)
+  cmake ${DIRECTORY}
+  cd ${DIRECTORY}/debug
+else
+  cd debug
+  cmake ..
+fi
+
+CXX=clang++ make -j${THREADS} || exit 1
+
+if [ ! -d bin ]; then
+  mkdir bin
+fi
+
+rm bin/*
+cd bin
+find .. -executable -type f | grep -v 'CMakeFiles' | while read line; do ln -s $line $(basename $line); done
+
+cp ${DIRECTORY}/translateAddresses .
+cp ${DIRECTORY}/xmlFormat .
+
+cd ${DIRECTORY}
+
+for test in $(ls tests.*.sh); do \
+  ./${test} debug/bin ${THREADS}; \
+done
diff --git a/all-cmake-release.sh b/all-cmake-release.sh
new file mode 100755
index 0000000000..3ad0b45489
--- /dev/null
+++ b/all-cmake-release.sh
@@ -0,0 +1,38 @@
+THREADS=${1:-5}
+DIRECTORY=$(pwd)
+
+cd CMake
+./alib_cmake.py -w -m
+cd ..
+
+if [ ! -d release ]; then
+  mkdir release
+fi
+
+if [ -L release ]; then
+  cd $(readlink release)
+  cmake -DCMAKE_BUILD_TYPE=Release ${DIRECTORY}
+  cd ${DIRECTORY}/release
+else
+  cd release
+  cmake -DCMAKE_BUILD_TYPE=Release ..
+fi
+
+CXX=clang++ make -j${THREADS} || exit 1
+
+if [ ! -d bin ]; then
+  mkdir bin
+fi
+
+rm bin/*
+cd bin
+find .. -executable -type f | grep -v 'CMakeFiles' | while read line; do ln -s $line $(basename $line); done
+
+cp ${DIRECTORY}/translateAddresses .
+cp ${DIRECTORY}/xmlFormat .
+
+cd ${DIRECTORY}
+
+for test in $(ls tests.*.sh); do \
+  ./${test} release/bin ${THREADS}; \
+done
diff --git a/cmake-debug.sh b/cmake-debug.sh
deleted file mode 100755
index 56cd0b8365..0000000000
--- a/cmake-debug.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-THREADS=${1:-5}
-cd CMake
-./alib_cmake.py -w -m
-cd ..
-
-if [ ! -d debug ]; then
-  mkdir debug
-fi
-
-if [ -L debug ]; then
-  DIRECTORY=$(pwd)
-  cd $(readlink debug)
-  cmake ${DIRECTORY}
-  cd ${DIRECTORY}
-  cd debug
-else
-  cd debug
-  cmake ..
-fi
-
-CXX=clang++ make -j${THREADS}
diff --git a/makefile b/makefile
index fad496193f..10b4f0add1 100644
--- a/makefile
+++ b/makefile
@@ -139,12 +139,12 @@ build-code-debug build-code-release:
 
 test-debug:
 	for test in $(wildcard tests.*.sh); do \
-		./$$test debug $(JOBS); \
+		./$$test bin-debug $(JOBS); \
 	done
 
 test-release:
 	for test in $(wildcard tests.*.sh); do \
-		./$$test release $(JOBS); \
+		./$$test bin-release $(JOBS); \
 	done
 
 install-debug:
diff --git a/tests.aarbology.sh b/tests.aarbology.sh
index e1e4f30d83..1a6387563c 100755
--- a/tests.aarbology.sh
+++ b/tests.aarbology.sh
@@ -29,13 +29,13 @@ MATCHES=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.aconversion.sh b/tests.aconversion.sh
index 33c70b1c96..29a722962f 100755
--- a/tests.aconversion.sh
+++ b/tests.aconversion.sh
@@ -26,13 +26,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.aconvert.sh b/tests.aconvert.sh
index 073d824dcd..704b4ae99a 100755
--- a/tests.aconvert.sh
+++ b/tests.aconvert.sh
@@ -19,13 +19,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 # ----------------------------
diff --git a/tests.aderivation.aintegral.sh b/tests.aderivation.aintegral.sh
index 527d11f221..190e4b8c55 100755
--- a/tests.aderivation.aintegral.sh
+++ b/tests.aderivation.aintegral.sh
@@ -10,13 +10,13 @@ TESTS_DIR="`pwd`/examples2/regexp"
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 
 # ----------------------------
 
diff --git a/tests.adeterminize.sh b/tests.adeterminize.sh
index 99e448f6aa..24542df3aa 100755
--- a/tests.adeterminize.sh
+++ b/tests.adeterminize.sh
@@ -19,13 +19,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 # ----------------------------
diff --git a/tests.anormalize.sh b/tests.anormalize.sh
index 3025346028..2a5a50ae73 100755
--- a/tests.anormalize.sh
+++ b/tests.anormalize.sh
@@ -27,13 +27,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.astringology.sh b/tests.astringology.sh
index 07339f02d7..741826059a 100755
--- a/tests.astringology.sh
+++ b/tests.astringology.sh
@@ -27,13 +27,13 @@ MATCHES=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.examples.sh b/tests.examples.sh
index d8942b1aa1..f2cd662900 100755
--- a/tests.examples.sh
+++ b/tests.examples.sh
@@ -19,13 +19,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 # ----------------------------
diff --git a/tests.glushkovrte.sh b/tests.glushkovrte.sh
index 33bfcc3473..4f96da7eb7 100755
--- a/tests.glushkovrte.sh
+++ b/tests.glushkovrte.sh
@@ -20,13 +20,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.glushkovrte_naive.sh b/tests.glushkovrte_naive.sh
index 3689c7fe0b..0ac3920976 100755
--- a/tests.glushkovrte_naive.sh
+++ b/tests.glushkovrte_naive.sh
@@ -20,13 +20,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
diff --git a/tests.repeats.sh b/tests.repeats.sh
index 7dc0ac391b..2702a42a56 100755
--- a/tests.repeats.sh
+++ b/tests.repeats.sh
@@ -15,7 +15,7 @@ NODES=100
 HEIGHT=15
 ALPHABET_SIZE=10
 
-EXECUTABLES="aarbology2 acast2 atniceprint arand2 "
+EXECUTABLES="aarbology2 acast2 tniceprint arand2 "
 TESTS_DIR="`pwd`/examples2/tree"
 
 RES_GOOD=
@@ -28,13 +28,13 @@ RES_UNKN=
 # ----------------------------
 
 for FILE in $EXECUTABLES; do
-	if [ ! -f bin-$1/$FILE ]; then
-		echo "Executable $FILE is required for testing. Make sure it is in bin-$1 folder."
+	if [ ! -f $1/$FILE ]; then
+		echo "Executable $FILE is required for testing. Make sure it is in $1 folder."
 		exit 1
 	fi
 done
 
-cd bin-$1/
+cd $1/
 rm -f $LOGFILE
 
 JOBS=$2
@@ -60,8 +60,8 @@ function log {
 	TWO=$(mktemp)
 	echo "Naive : " >> $ONE
 	echo "Yours : " >> $TWO
-	cat $5 | ./atniceprint >> $ONE
-	cat $6 | ./atniceprint >> $TWO
+	cat $5 | ./tniceprint >> $ONE
+	cat $6 | ./tniceprint >> $TWO
 	paste $ONE $TWO | pr -t -e$(awk 'n<length {n=length} END {print n+1}' $ONE) >> $LOGFILE
 	rm $ONE $TWO
 }
@@ -92,8 +92,8 @@ function runPostfix2RankedAlgorithmTest {
 	RANKED2POSTFIX2RANKED=$(mktemp)
 	RANKED=$(mktemp)
 
-	./acast2 -t RankedTree -i $1 | ./atniceprint > $RANKED
-	./acast2 -t RankedTree -i $1 | ./acast2 -t PostfixRankedTree | ./acast2 -t RankedTree | ./atniceprint > $RANKED2POSTFIX2RANKED
+	./acast2 -t RankedTree -i $1 | ./tniceprint > $RANKED
+	./acast2 -t RankedTree -i $1 | ./acast2 -t PostfixRankedTree | ./acast2 -t RankedTree | ./tniceprint > $RANKED2POSTFIX2RANKED
 
 	OUT=`timeout $TESTCASE_TIMEOUT bash -c "diff $RANKED $RANKED2POSTFIX2RANKED"`
 	RET=$?
diff --git a/tniceprint/makefile.conf b/tniceprint/makefile.conf
index 2ccf83f653..f3454f9d08 100644
--- a/tniceprint/makefile.conf
+++ b/tniceprint/makefile.conf
@@ -1,4 +1,4 @@
-EXECUTABLE:=atniceprint
+EXECUTABLE:=tniceprint
 LINK_LIBRARIES=alib2cli alib2elgo alib2algo alib2str alib2data alib2xml alib2common alib2abstraction alib2measure alib2std
 SYSTEM_LIBRARIES=xml2
 SYSTEM_INCLUDE_PATHS=/usr/include/libxml2
-- 
GitLab