summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Cowgill <jcowgill@debian.org>2023-11-29 20:17:40 +0000
committerJames Cowgill <jcowgill@debian.org>2023-11-29 22:51:07 +0000
commita7eeaaae3020172095d16cff1c0585fdd77e3070 (patch)
tree8b9c15876487b664e0efb6e8bdacb7d22ab8cfee
parentf0f70f2b5e9dc18db02192e40d295e133df8b352 (diff)
d/tests: Add cmake build test
-rw-r--r--debian/tests/CMakeLists.txt15
-rw-r--r--debian/tests/cmake35
-rw-r--r--debian/tests/control3
3 files changed, 53 insertions, 0 deletions
diff --git a/debian/tests/CMakeLists.txt b/debian/tests/CMakeLists.txt
new file mode 100644
index 0000000..02a9b48
--- /dev/null
+++ b/debian/tests/CMakeLists.txt
@@ -0,0 +1,15 @@
+# Test CMake project to ensure uchardet config files work properly
+
+cmake_minimum_required(VERSION 3.13)
+project(uchardet_test)
+
+# Try to find uchardet using CMake config file
+find_package(uchardet 0.0.7 REQUIRED CONFIG)
+
+# Build the executables
+add_executable(detect_dynamic detect.c)
+target_link_libraries(detect_dynamic PRIVATE uchardet::libuchardet)
+
+add_executable(detect_static detect.c)
+target_link_libraries(detect_static PRIVATE uchardet::libuchardet_static)
+target_link_options(detect_static PRIVATE -static)
diff --git a/debian/tests/cmake b/debian/tests/cmake
new file mode 100644
index 0000000..128c727
--- /dev/null
+++ b/debian/tests/cmake
@@ -0,0 +1,35 @@
+#!/bin/sh
+# autopkgtest check: Build and run a very simple program against uchardet
+
+set -e
+
+# Require $AUTOPKGTEST_TMP for temporary build files
+if [ -z "$AUTOPKGTEST_TMP" ]
+then
+ echo "Required envvar \"\$AUTOPKGTEST_TMP\" is not set" >&2
+ exit 1
+fi
+
+cp debian/tests/CMakeLists.txt debian/tests/detect.c "$AUTOPKGTEST_TMP"
+cd "$AUTOPKGTEST_TMP"
+
+if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then
+ export CC="$DEB_HOST_GNU_TYPE-gcc"
+ export CXX="$DEB_HOST_GNU_TYPE-g++"
+fi
+
+# Run CMake and build program
+CFLAGS='-Wall -Werror' cmake .
+make VERBOSE=1
+echo "build: OK"
+
+# Run each program
+for prog in detect_dynamic detect_static; do
+ # Run it on some ascii
+ [ $(echo 'hello world' | ./$prog) = 'ASCII' ]
+ echo "run1: $prog OK"
+
+ # Run it on some chinese
+ [ $(echo '汉字漢字統一編碼萬國碼' | ./$prog) = 'UTF-8' ]
+ echo "run2: $prog OK"
+done
diff --git a/debian/tests/control b/debian/tests/control
index 49de7b7..8f2c327 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -3,3 +3,6 @@ Depends: build-essential, libuchardet-dev, pkg-config
Tests: cli
Depends: uchardet
+
+Tests: cmake
+Depends: build-essential, cmake, libuchardet-dev