فهرست منبع

feat(testing): add code coverage and streamline unit testing (#2620)

Daniel Gibbs 6 سال پیش
والد
کامیت
75c3238377
8فایلهای تغییر یافته به همراه74 افزوده شده و 51 حذف شده
  1. 26 31
      .travis.yml
  2. 0 0
      README.md
  3. 2 2
      lgsm/functions/command_fastdl.sh
  4. 14 12
      tests/tests_fctrserver.sh
  5. 6 2
      tests/tests_jc2server.sh
  6. 14 0
      tests/tests_kcov.sh
  7. 6 2
      tests/tests_mcserver.sh
  8. 6 2
      tests/tests_ts3server.sh

+ 26 - 31
.travis.yml

@@ -1,49 +1,44 @@
 language: node_js
 dist: bionic
 node_js:
-  - 10
+  - "stable"
+env:
+  global:
+    secure: VsS98cwJ5X/Ev3HEm7KEOPftYay+7jNTHepTS7d+gQNHcDR1UYKTmqlQNSIoUC52Ejs1cHq43jOfle4330zDPOYI0v5BMri6/iZKpmMxAw6KWNiUgSkziTP2kHC4NRLwEoU2WQTI3JZQjrBEfsPmD81+yR/eWXV3rph+YcSOxao=
 
 before_script:
-    - curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx
+  - curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx
+
 install:
-  npm install gamedig
+  - npm install gamedig
+
 addons:
   apt:
     packages:
     - mailutils
     - postfix
-    - curl
-    - wget
-    - file
-    - bzip2
-    - gzip
-    - unzip
-    - bsdmainutils
-    - python3
-    - util-linux
-    - ca-certificates
-    - binutils
-    - bc
     - jq
-    - tmux
     - lib32gcc1
-    - libstdc++6
     - libstdc++6:i386
-    - net-tools
-    - iproute2
     - shellcheck
+    - libcurl4-openssl-dev
+    - libdw-dev
+    - cmake
 
 jobs:
   include:
-    - stage: jobs
-      script: bash tests/tests_jc2server.sh
-    - # stage name not required
-      script: bash tests/tests_fctrserver.sh
-    - # stage name not required
-      script: bash tests/tests_mcserver.sh
-    - # stage name not required
-      script: bash tests/tests_ts3server.sh
-    - # stage name not required
-      script: bash tests/tests_defaultcfg/tests_defaultcfg.sh
-    - # retired as codacy does this check.
-      # script: bash tests/tests_shellcheck.sh
+    - stage: "Jobs"
+      name: "code coverage"
+      script: bash tests/tests_kcov.sh; kcov --bash-method=DEBUG coverage tests/tests_mcserver.sh
+    - script: bash tests/tests_mcserver.sh
+      name: "Minecraft"      
+    - script: bash tests/tests_jc2server.sh      
+      name: "Just Cause 2"
+    - script: bash tests/tests_fctrserver.sh
+      name: "Factorio" 
+    - script: bash tests/tests_ts3server.sh
+      name: "Teamspeak 3"     
+    - script: bash tests/tests_defaultcfg/tests_defaultcfg.sh
+      name: "_default.cfg checks"
+after_success:
+- bash <(curl -Ls https://coverage.codacy.com/get.sh)

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
README.md


+ 2 - 2
lgsm/functions/command_fastdl.sh

@@ -194,7 +194,7 @@ fn_fastdl_preview(){
 						tput rc; tput el
 						echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..."
 						echo -e "${ext}" >> "${tmpdir}/fastdl_files_to_compress.txt"
-					done < <(find "${systemdir}/${directory}" -type f -iname ${allowed_extention})
+					done < <(find "${systemdir}/${directory}" -type f -iname "${allowed_extention}")
 					tput rc; tput el
 					echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..."
 					if [ ${fileswc} != 0 ]; then
@@ -213,7 +213,7 @@ fn_fastdl_preview(){
 		# Calculates total file size.
 		while read -r dufile; do
 			filesize=$(stat -c %s "${dufile}")
-			filesizetotal=$(( ${filesizetotal} + ${filesize} ))
+			filesizetotal=$(( filesizetotal+filesize ))
 			exitcode=$?
 			if [ "${exitcode}" != 0 ]; then
 				fn_print_fail_eol_nl

+ 14 - 12
tests/tests_fctrserver.sh

@@ -66,8 +66,6 @@ core_functions.sh(){
 
 # Bootstrap
 # Fetches the core functions required before passed off to core_dl.sh.
-
-# Fetches core functions.
 fn_bootstrap_fetch_file(){
 	remote_fileurl="${1}"
 	local_filedir="${2}"
@@ -280,15 +278,15 @@ if [ "$(whoami)" == "root" ]; then
 	fi
 fi
 
-# Download the latest serverlist. This is the complete list of all supported servers.
-fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
-if [ ! -f "${serverlist}" ]; then
-	echo -e "[ FAIL ] serverlist.csv could not be loaded."
-	exit 1
-fi
-
 # LinuxGSM installer mode.
 if [ "${shortname}" == "core" ]; then
+	# Download the latest serverlist. This is the complete list of all supported servers.
+	fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
+	if [ ! -f "${serverlist}" ]; then
+		echo -e "[ FAIL ] serverlist.csv could not be loaded."
+		exit 1
+	fi
+
 	if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then
 		{
 			tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
@@ -380,7 +378,7 @@ else
 	# Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
 	fn_ansi_loader
 	# Prevents running of core_exit.sh for Travis-CI.
-		if [ -z "${travistest}" ]; then
+	if [ -z "${travistest}" ]; then
 		getopt=$1
 		core_getopt.sh
 	fi
@@ -480,6 +478,8 @@ fn_test_result_na(){
 	fn_print_fail_nl "TEST N/A"
 }
 
+sleeptime="0"
+
 echo -e "================================="
 echo -e "Travis CI Tests"
 echo -e "Linux Game Server Manager"
@@ -1011,6 +1011,8 @@ echo -e "Using: ${gamename}"
 echo -e "================================="
 requiredstatus="OFFLINE"
 fn_setstatus
-fn_print_info "Tidying up directories."
-rm -rfv "${serverfiles}"
+if [ ! -v TRAVIS ]; then
+	fn_print_info "Tidying up directories."
+	rm -rfv "${serverfiles}"
+fi
 core_exit.sh

+ 6 - 2
tests/tests_jc2server.sh

@@ -478,6 +478,8 @@ fn_test_result_na(){
 	fn_print_fail_nl "TEST N/A"
 }
 
+sleeptime="0"
+
 echo -e "================================="
 echo -e "Travis CI Tests"
 echo -e "Linux Game Server Manager"
@@ -1170,6 +1172,8 @@ echo -e "Using: ${gamename}"
 echo -e "================================="
 requiredstatus="OFFLINE"
 fn_setstatus
-fn_print_info "Tidying up directories."
-rm -rfv "${serverfiles}"
+if [ ! -v TRAVIS ]; then
+	fn_print_info "Tidying up directories."
+	rm -rfv "${serverfiles}"
+fi
 core_exit.sh

+ 14 - 0
tests/tests_kcov.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+echo -e "Installing kcov"
+curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx
+wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
+tar xzf master.tar.gz
+cd kcov-master || exit
+mkdir build
+cd build || exit
+cmake ..
+make
+sudo make install
+cd ../..
+rm -rf kcov-master
+mkdir -p coverage

+ 6 - 2
tests/tests_mcserver.sh

@@ -478,6 +478,8 @@ fn_test_result_na(){
 	fn_print_fail_nl "TEST N/A"
 }
 
+sleeptime="0"
+
 echo -e "================================="
 echo -e "Travis CI Tests"
 echo -e "Linux Game Server Manager"
@@ -1056,6 +1058,8 @@ echo -e "Using: ${gamename}"
 echo -e "================================="
 requiredstatus="OFFLINE"
 fn_setstatus
-fn_print_info "Tidying up directories."
-rm -rfv "${serverfiles}"
+if [ ! -v TRAVIS ]; then
+	fn_print_info "Tidying up directories."
+	rm -rfv "${serverfiles}"
+fi
 core_exit.sh

+ 6 - 2
tests/tests_ts3server.sh

@@ -478,6 +478,8 @@ fn_test_result_na(){
 	fn_print_fail_nl "TEST N/A"
 }
 
+sleeptime="0"
+
 echo -e "================================="
 echo -e "Travis CI Tests"
 echo -e "Linux Game Server Manager"
@@ -1009,6 +1011,8 @@ echo -e "Using: ${gamename}"
 echo -e "================================="
 requiredstatus="OFFLINE"
 fn_setstatus
-fn_print_info "Tidying up directories."
-rm -rfv "${serverfiles}"
+if [ ! -v TRAVIS ]; then
+	fn_print_info "Tidying up directories."
+	rm -rfv "${serverfiles}"
+fi
 core_exit.sh

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است