[TASK] Script finding duplicate exception codes for Travis 65/47765/7
authorChristoph Kratz <ckr@rtp.ch>
Mon, 18 Apr 2016 21:43:23 +0000 (23:43 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 19 Apr 2016 12:19:16 +0000 (14:19 +0200)
Resolves: #75761
Relates: #75737
Releases: master
Change-Id: I7b061ac9d9ec3c071b87994168ade87c43131d6d
Reviewed-on: https://review.typo3.org/47765
Reviewed-by: Stephan Großberndt <stephan@grossberndt.de>
Tested-by: Stephan Großberndt <stephan@grossberndt.de>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
.travis.yml
typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh [new file with mode: 0755]

index 320bae1..c3ab9c6 100644 (file)
@@ -5,7 +5,7 @@ matrix:
 
   include:
     - php: 7
-      env: UNIT_TESTS=yes FUNCTIONAL_TESTS=yes ACCEPTANCE_TESTS=yes PHP_LINT=yes XLF_CHECK=yes SUBMODULE_TEST=yes
+      env: UNIT_TESTS=yes FUNCTIONAL_TESTS=yes ACCEPTANCE_TESTS=yes PHP_LINT=yes XLF_CHECK=yes SUBMODULE_TEST=yes  EXCEPTIONCODE_TEST=yes
 
 sudo: false
 
@@ -13,6 +13,7 @@ addons:
   apt:
     packages:
       - parallel
+      - ack-grep
 
 cache:
   directories:
@@ -101,3 +102,10 @@ script:
               fi
           "
       fi
+
+  - >
+    if [[ "$EXCEPTIONCODE_TEST" == "yes" ]]; then
+        echo;
+        echo "Running duplicate exception code checker";
+        ./typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh
+    fi
diff --git a/typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh b/typo3/sysext/core/Build/Scripts/duplicateExceptionCodeCheck.sh
new file mode 100755 (executable)
index 0000000..e5066b8
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+#########################
+#
+# Find duplicate exception timestamps and list them
+#
+# Use within TYPO3 CMS source
+#
+#
+# The script searches for duplicate timestamps with
+# two exceptions:
+# 1. timestamps defined by the "IGNORE" array
+# 2. timestamps within Tests directories
+#
+#
+# @author  Christoph Kratz <ckr@rtp.ch>
+# @author  Christian Kuhn <lolli@schwarzbu.ch>
+# @date 2016-04-18
+#
+##########################
+
+cd typo3/
+
+# Array of timestamps which are allowed to be non-unique
+IGNORE=("1270853884")
+
+# The ack / ack-grep command can be different for different OS
+ACK=${ACK:-ack-grep}
+
+# Respect only php files and ignore files within a "Tests" directory
+EXCEPTIONS=$(${ACK} --type php --ignore-dir Tests 'throw new' -A5 | grep '[[:digit:]]\{10\}')
+
+DUPLICATES=$(echo ${EXCEPTIONS} | awk '{
+    for(i=1; i<=NF; i++) {
+        if(match($i, /[0-9]{10}/)) {
+            print $i
+        }
+    }
+}' | cut -d';' -f1 | tr -cd '0-9\012' | sort | uniq -d)
+
+COUNTER=0
+
+for CODE in ${DUPLICATES}; do
+
+    # Ignore timestamps which are defined by the "IGNORE" array
+    if [ ${IGNORE[@]} != ${CODE} ] ; then
+        echo "Possible duplicate exception code $CODE": ${ACK} --type php ${CODE}
+        COUNTER=$((COUNTER+1))
+    fi
+
+done
+
+if [ ${COUNTER} -gt 0 ] ; then
+    echo "$COUNTER possible duplicate exception codes found."
+    exit 1
+fi
+
+exit 0
+