Source: pwgen
Version: 2.08-2
Severity: wishlist
Tags: patch

Dear Maintainer,

I was teaching a testing/autopgktest workshop yesterday and pwgen was
one of the suggested example packages. I realized you are also upstream,
so I went a bit further today and integrated the tests into the build
system.

I came up with the attached patch, I hope you find it useful.

-- System Information:
Debian Release: bookworm/sid
  APT prefers testing-debug
  APT policy: (900, 'testing-debug'), (900, 'testing'), (500, 
'unstable-debug'), (500, 'unstable'), (1, 'experimental-debug'), (1, 
'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.18.0-3-amd64 (SMP w/4 CPU threads; PREEMPT)
Kernel taint flags: TAINT_WARN
Locale: LANG=pt_BR.UTF-8, LC_CTYPE=pt_BR.UTF-8 (charmap=UTF-8), 
LANGUAGE=pt_BR:pt:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
From e18e9293ee39280f57a357cf0af1a4265afb4ee9 Mon Sep 17 00:00:00 2001
From: Antonio Terceiro <terce...@debian.org>
Date: Tue, 16 Aug 2022 09:03:49 -0300
Subject: [PATCH] Add simple automated tests

These tests are run as part of the test/check targets, and can help a
limited set of catch implementation issues, particularly on changes.
They get automatically run on Debian builds, and are explicitly run
under autopkgtest (debian/tests/control).

For autopktest, the tests are declared as `superficial`, because I
believe these tests don't cover enough of the pwgen features. This
causes test failures to count as regressions, but test passes don't
imply faster testing migration.

Signed-off-by: Antonio Terceiro <terce...@debian.org>
---
 Makefile.in          | 10 ++++++++++
 debian/control       |  2 +-
 debian/tests/control |  4 ++++
 test.sh              | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 debian/tests/control
 create mode 100755 test.sh

diff --git a/Makefile.in b/Makefile.in
index 7f09f67..ce5d286 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -63,6 +63,16 @@ distclean: clean
 		$(srcdir)/Makefile.in.old $(srcdir)/.exclude-file \
 		$(srcdir)/autom4te.cache
 
+
+#
+# Test...
+#
+
+check: test
+
+test: pwgen
+	PWGEN=./pwgen ./test.sh
+
 #
 # Build source tar ball...
 #
diff --git a/debian/control b/debian/control
index f266d44..202b3dc 100644
--- a/debian/control
+++ b/debian/control
@@ -1,7 +1,7 @@
 Source: pwgen
 Section: admin
 Priority: optional
-Build-Depends: debhelper (>= 12)
+Build-Depends: debhelper (>= 12), shunit2
 Maintainer: Theodore Y. Ts'o <ty...@mit.edu>
 Standards-Version: 4.4.0
 Homepage: https://github.com/tytso/pwgen
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..be3247b
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,4 @@
+Test-Command: ./test.sh
+Depends: @, shunit2
+Features: test-name=testsuite
+Restrictions: superficial
diff --git a/test.sh b/test.sh
new file mode 100755
index 0000000..a0d221b
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+if [ -z "${PWGEN}" ]; then
+  PWGEN=$(command -v pwgen)
+fi
+if [ -z "${PWGEN}" ]; then
+  echo "E: \`pwgen\` not found. Is it installed an in your \$PATH?"
+  exit 1
+fi
+
+pwgen() {
+  ${PWGEN} "$@"
+}
+
+test_new_password_every_time() {
+  password1=$(pwgen)
+  password2=$(pwgen)
+  assertNotEquals "${password1}" "${password2}"
+}
+
+test_password_length() {
+  password_length=$(pwgen 20 | sed -e 's/\S/./g')
+  assertEquals "...................." "${password_length}"
+}
+
+test_two_passwords() {
+  passwords=$(pwgen 5 2 | tr '\n' ' ' | sed -e 's/\S/./g')
+  assertEquals "..... ..... " "${passwords}"
+}
+
+test_no_numerals() {
+  password=$(pwgen --no-numerals 1000)
+  assertFalse "should not contain numbers: ${password}" "echo '${password}' | grep '[0-9]'"
+}
+
+test_no_capitals() {
+  password=$(pwgen --no-capitalize 1000)
+  assertFalse "should not contain capitals: ${password}" "echo '${password}' | grep '[A-Z]'"
+}
+
+. /usr/share/shunit2/shunit2
-- 
2.35.1

Attachment: signature.asc
Description: PGP signature

Reply via email to