Parcourir la source

Add build-time tests

This requires newer Saturnin version in order to avoid bug where
SATURNIN_CONF_PATH environment variable would be ignored.
Alois Mahdal il y a 7 ans
Parent
révision
41efeb2171
7 fichiers modifiés avec 102 ajouts et 2 suppressions
  1. 3
    0
      Makefile
  2. 1
    0
      mkit.ini
  3. 6
    1
      packaging/debian/control
  4. 8
    0
      packaging/debian/rules
  5. 8
    1
      packaging/template.spec
  6. 8
    0
      tests/TF_HEADER
  7. 68
    0
      tests/sd_echo/TF_RUN

+ 3
- 0
Makefile Voir le fichier

@@ -3,3 +3,6 @@
3 3
 
4 4
 MKIT_DIR=utils/mkit
5 5
 include $(MKIT_DIR)/mkit.mk
6
+
7
+TF_DIR=utils/tfkit
8
+include $(TF_DIR)/tfkit.mk

+ 1
- 0
mkit.ini Voir le fichier

@@ -14,6 +14,7 @@
14 14
     tarball  = mkit.ini
15 15
     tarball  = packaging
16 16
     tarball  = src
17
+    tarball  = tests
17 18
     tarball  = utils
18 19
     rpmstuff = packaging/template.spec
19 20
     debstuff = packaging/debian

+ 6
- 1
packaging/debian/control Voir le fichier

@@ -6,6 +6,11 @@ Priority: extra
6 6
 Standards-Version: 3.9.2
7 7
 Build-Depends:
8 8
  debhelper (>= 9),
9
+ shellfu (>= 0.10),
10
+ shellfu (<< 0.11),
11
+ shellfu-bash-pretty,
12
+ shellfu-bash-saturnin (>= 0.4.8),
13
+ shellfu-bash-saturnin (<< 5.0),
9 14
 
10 15
 Package: __MKIT_PROJ_PKGNAME__
11 16
 Architecture: all
@@ -13,7 +18,7 @@ Depends:
13 18
  shellfu (>= 0.10),
14 19
  shellfu (<< 0.11),
15 20
  shellfu-bash-pretty,
16
- shellfu-bash-saturnin (>= 0.4.7),
21
+ shellfu-bash-saturnin (>= 0.4.8),
17 22
  shellfu-bash-saturnin (<< 5.0),
18 23
 Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
19 24
  saturnin is Shellfu library that helps you easily build toolkit from

+ 8
- 0
packaging/debian/rules Voir le fichier

@@ -7,3 +7,11 @@
7 7
 override_dh_auto_install:
8 8
 
9 9
 	make install DESTDIR=debian/tmp PREFIX=/usr
10
+
11
+override_dh_auto_test:
12
+
13
+	make clean
14
+	make install PREFIX=/usr DESTDIR=TEST
15
+	make test \
16
+		PATH="$(shell pwd)/TEST/usr/bin:$(PATH)" \
17
+		SATURNIN_CONF_PATH="$(shell pwd)/TEST/usr/share/bmo/ini.d"

+ 8
- 1
packaging/template.spec Voir le fichier

@@ -6,9 +6,11 @@ URL:            __MKIT_PROJ_VCS_BROWSER__
6 6
 License:        LGPLv2
7 7
 Source0:        %{name}-%{version}.tar.gz
8 8
 BuildArch:      noarch
9
+BuildRequires:  shellfu >= 0.10, shellfu < 0.11
10
+BuildRequires:  shellfu-bash-saturnin >= 0.4.8, shellfu-bash-saturnin < 0.5.0
9 11
 
10 12
 Requires:       shellfu >= 0.10, shellfu < 0.11
11
-Requires:       shellfu-bash-saturnin >= 0.4.7, shellfu-bash-saturnin < 0.5.0
13
+Requires:       shellfu-bash-saturnin >= 0.4.8, shellfu-bash-saturnin < 0.5.0
12 14
 %description
13 15
 saturnin is Shellfu library that helps you easily build toolkit from
14 16
 various scripts that you may have lying around.  Instead of having a
@@ -28,6 +30,11 @@ make %{?_smp_mflags} PREFIX=/usr
28 30
 %install
29 31
 %make_install PREFIX=/usr
30 32
 
33
+%check
34
+make test \
35
+    PATH="%{buildroot}/%{_bindir}:$PATH" \
36
+    SATURNIN_CONF_PATH="%{buildroot}/%{_datadir}/%{name}/ini.d"
37
+
31 38
 %files
32 39
 %config %{_sysconfdir}/bash_completion.d/%{name}.bash
33 40
 %dir %{_datadir}/%{name}

+ 8
- 0
tests/TF_HEADER Voir le fichier

@@ -0,0 +1,8 @@
1
+#!/bin/bash
2
+
3
+. "$(sfpath)" || exit 3
4
+
5
+echo "version: $(saturnin-demo -V)"
6
+echo "binary: $(which saturnin-demo)"
7
+echo "saturnin-version: $(saturnin-demo --saturnin-get-saturnin-version)"
8
+echo "saturnin-conf-path: $(saturnin-demo --saturnin-get-saturnin-conf-path)"

+ 68
- 0
tests/sd_echo/TF_RUN Voir le fichier

@@ -0,0 +1,68 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$TF_DIR/include/subtest.sh"
5
+. "$TF_DIR/include/tools.sh"
6
+
7
+
8
+tf_enum_subtests() {
9
+    echo name
10
+    echo name_ex
11
+    echo world
12
+}
13
+
14
+mkini() {
15
+    mkdir -p "test/ini"
16
+    {
17
+        echo '[echo]'
18
+        echo '    prefix = Hello'
19
+    } > "test/ini/echo.ini"
20
+}
21
+
22
+mkoracle_out() {
23
+    mkdir -p oracle
24
+    case $TF_SUBTEST in
25
+        name)     echo 'HelloJoe' ;;
26
+        name_ex)  echo 'HelloMaggie!' ;;
27
+        world)    echo 'HelloWorld' ;;
28
+    esac > "oracle/$TF_SUBTEST.stdout"
29
+}
30
+
31
+mkoracle_err() {
32
+    mkdir -p oracle
33
+    true > "oracle/$TF_SUBTEST.stderr"
34
+}
35
+
36
+mkoracle_es() {
37
+    return 0
38
+}
39
+
40
+mkresult() {
41
+    local what
42
+    case $TF_SUBTEST in
43
+        name)    what="Joe" ;;
44
+        name_ex) what="Maggie!" ;;
45
+        world)   what="World" ;;
46
+    esac
47
+    (
48
+        export PRETTY=plain
49
+        export SATURNIN_CONF_PATH="test/ini"
50
+        saturnin-demo echo "$what"
51
+    )
52
+}
53
+
54
+tf_do_subtest() {
55
+    local o_es
56
+    mkini
57
+    mkoracle_out
58
+    mkoracle_err
59
+    mkoracle_es; o_es=$?
60
+    tf_testflt \
61
+      -n "$TF_SUBTEST" \
62
+      -O "oracle/$TF_SUBTEST.stdout" \
63
+      -E "oracle/$TF_SUBTEST.stderr" \
64
+      -S "$o_es" \
65
+      "mkresult"
66
+}
67
+
68
+tf_do_subtests