Browse 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 7 years ago
parent
commit
41efeb2171
7 changed files with 102 additions and 2 deletions
  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 View File

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

+ 1
- 0
mkit.ini View File

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

+ 6
- 1
packaging/debian/control View File

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

+ 8
- 0
packaging/debian/rules View File

7
 override_dh_auto_install:
7
 override_dh_auto_install:
8
 
8
 
9
 	make install DESTDIR=debian/tmp PREFIX=/usr
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 View File

6
 License:        LGPLv2
6
 License:        LGPLv2
7
 Source0:        %{name}-%{version}.tar.gz
7
 Source0:        %{name}-%{version}.tar.gz
8
 BuildArch:      noarch
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
 Requires:       shellfu >= 0.10, shellfu < 0.11
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
 %description
14
 %description
13
 saturnin is Shellfu library that helps you easily build toolkit from
15
 saturnin is Shellfu library that helps you easily build toolkit from
14
 various scripts that you may have lying around.  Instead of having a
16
 various scripts that you may have lying around.  Instead of having a
28
 %install
30
 %install
29
 %make_install PREFIX=/usr
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
 %files
38
 %files
32
 %config %{_sysconfdir}/bash_completion.d/%{name}.bash
39
 %config %{_sysconfdir}/bash_completion.d/%{name}.bash
33
 %dir %{_datadir}/%{name}
40
 %dir %{_datadir}/%{name}

+ 8
- 0
tests/TF_HEADER View File

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 View File

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