]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
fix shellcheck issues in bats tests develop
authorBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jul 2026 07:05:22 +0000 (09:05 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jul 2026 07:05:22 +0000 (09:05 +0200)
tests/postinst.bats
tests/postrm.bats

index 18c0dc92c389f4e879f693dcac75a9a69ca36b61..fafe541befeb2e19a63588f404139b1a77303822 100755 (executable)
@@ -6,6 +6,7 @@ setup() {
        export BUILDDIR=${BUILDDIR:="../build"}
        mkdir --parents "$BUILDDIR"
        touch "$BUILDDIR/dllpostinst.conf"
+       export DLLCONFIG="$BUILDDIR/dllpostinst.conf"
 }
 
 teardown() {
@@ -24,25 +25,23 @@ teardown() {
 }
 
 @test "add entry kds_s2000w_net dll.conf" {
-       export DLLCONFIG="$BUILDDIR/dllpostinst.conf"
-
        run ../src/debian/postinst
 
        assert_success
        assert_line --index 0 "found $BUILDDIR/dllpostinst.conf"
        assert_line --index 1 "add kds_s2000w_net to $BUILDDIR/dllpostinst.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostinst.conf)" "kds_s2000w_net"
-       assert_equal "$(cat $BUILDDIR/dllpostinst.conf | wc --lines)" "1"
+       assert_equal "$(cat "$BUILDDIR/dllpostinst.conf")" "kds_s2000w_net"
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostinst.conf" \
+               | awk '{print $1}')" "1"
 }
 
 @test "entry exists in dll.conf do nothing" {
-       export DLLCONFIG="$BUILDDIR/dllpostinst.conf"
-
        run ../src/debian/postinst
        run ../src/debian/postinst
 
        assert_success
        assert_output "found $BUILDDIR/dllpostinst.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostinst.conf)" "kds_s2000w_net"
-       assert_equal "$(cat $BUILDDIR/dllpostinst.conf | wc --lines)" "1"
+       assert_equal "$(cat "$BUILDDIR/dllpostinst.conf")" "kds_s2000w_net"
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostinst.conf" \
+               | awk '{print $1}')" "1"
 }
\ No newline at end of file
index 67ee6c423f25d3e2e5d43bb758e150f9793d240e..36b2d4190a9994e4fe00bddea13960b2140d89ee 100755 (executable)
@@ -4,12 +4,13 @@ setup() {
        bats_load_library bats-support
        bats_load_library bats-assert
        export BUILDDIR=${BUILDDIR:="../build"}
-       mkdir --parents $BUILDDIR
-       echo kds_s2000w_net > $BUILDDIR/dllpostrm.conf
+       mkdir --parents "$BUILDDIR"
+       echo kds_s2000w_net > "$BUILDDIR/dllpostrm.conf"
+       export DLLCONFIG="$BUILDDIR/dllpostrm.conf"
 }
 
 teardown() {
-       rm -rf $BUILDDIR/dllpostrm.conf
+       rm -rf "$BUILDDIR/dllpostrm.conf"
        unset BUILDDIR
        unset DLLCONFIG
 }
@@ -24,47 +25,46 @@ teardown() {
 }
 
 @test "delete one entry kds_s2000w_net from dll.conf {
-       export DLLCONFIG="$BUILDDIR/dllpostrm.conf"
-
        run ../src/debian/postrm
 
        assert_success
        assert_line --index 0 "found $BUILDDIR/dllpostrm.conf"
        assert_line --index 1 "remove kds_s2000w_net from $BUILDDIR/dllpostrm.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf)" ""
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf | wc --lines)" "0"
+       assert_equal "$(cat "$BUILDDIR/dllpostrm.conf")" ""
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostrm.conf" \
+               | awk '{print $1}')" "0"
 }
 
 @test "delete multiple entry kds_s2000w_net from dll.conf {
-       echo kds_s2000w_net >> $BUILDDIR/dllpostrm.conf
-       echo kds_s2000w_net >> $BUILDDIR/dllpostrm.conf
-       echo kds_s2000w_net >> $BUILDDIR/dllpostrm.conf
-       export DLLCONFIG="$BUILDDIR/dllpostrm.conf"
+       printf "kds_s2000w_net\nkds_s2000w_net\nkds_s2000w_net\n" \
+               > "$BUILDDIR/dllpostrm.conf"
 
        run ../src/debian/postrm
 
        assert_line --index 0 "found $BUILDDIR/dllpostrm.conf"
        assert_line --index 1 "remove kds_s2000w_net from $BUILDDIR/dllpostrm.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf)" ""
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf | wc --lines)" "0"
+       assert_equal "$(cat "$BUILDDIR/dllpostrm.conf")" ""
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostrm.conf" \
+               | awk '{print $1}')" "0"
 
        run ../src/debian/postrm
 
        assert_success
        assert_line --index 0 "found $BUILDDIR/dllpostrm.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf)" ""
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf | wc --lines)" "0"
+       assert_equal "$(cat "$BUILDDIR/dllpostrm.conf")" ""
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostrm.conf" \
+               | awk '{print $1}')" "0"
 }
 
 @test "do nothing entry kds_s2000w_net not exists from dll.conf {
-       rm -rf $BUILDDIR/dllpostrm.conf
-       touch $BUILDDIR/dllpostrm.conf
-       export DLLCONFIG="$BUILDDIR/dllpostrm.conf"
+       rm -rf "$BUILDDIR/dllpostrm.conf"
+       touch "$BUILDDIR/dllpostrm.conf"
 
        run ../src/debian/postrm
 
        assert_success
        assert_output "found $BUILDDIR/dllpostrm.conf"
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf)" ""
-       assert_equal "$(cat $BUILDDIR/dllpostrm.conf | wc --lines)" "0"
+       assert_equal "$(cat "$BUILDDIR/dllpostrm.conf")" ""
+       assert_equal "$(wc --lines "$BUILDDIR/dllpostrm.conf" \
+               | awk '{print $1}')" "0"
 }
\ No newline at end of file