From d40ba030d3cbf963c92752c3fcc1cf49f4fb9dbb Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Sat, 10 Feb 2024 15:41:40 +0100 Subject: [PATCH 01/10] t/common: print test target. --- t/common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/common.sh b/t/common.sh index f08d816..0e76b01 100644 --- a/t/common.sh +++ b/t/common.sh @@ -8,6 +8,8 @@ set -e -u dir="${0%/*}/.." prog="${UBANNER_TEST_TARGET:-"$dir/ubanner"}" +echo "# test target = $prog" + is_unicode_locale() { local charset=$'\u2591\u2592\u2588' From dcb3858737a65a5c557476c0d593c565091bc423 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Sat, 10 Feb 2024 15:45:38 +0100 Subject: [PATCH 02/10] Makefile: add. --- Makefile | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..75cc0c1 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +PYTHON = python3 + +PREFIX = /usr/local +DESTDIR = + +bindir = $(PREFIX)/bin +mandir = $(PREFIX)/share/man + +.PHONY: all +all: ; + +.PHONY: install +install: ubanner + install -d $(DESTDIR)$(bindir) + python_exe=$$($(PYTHON) -c 'import sys; print(sys.executable)') && \ + sed \ + -e "1 s@^#!.*@#!$$python_exe@" \ + -e "s#^basedir = .*#basedir = '$(basedir)/'#" \ + $(<) > $(<).tmp + install $(<).tmp $(DESTDIR)$(bindir)/$(<) + rm $(<).tmp + +.PHONY: test +test: verbose= +test: ubanner + prove $(and $(verbose),-v) + +.PHONY: test-installed +test-installed: verbose= +test-installed: $(or $(shell command -v ubanner;),$(bindir)/ubanner) + UBANNER_TEST_TARGET=ubanner prove $(and $(verbose),-v) + +.PHONY: clean +clean: + rm -f *.tmp + +.error = GNU make is required + +# vim:ts=4 sts=4 sw=4 noet From 6b3bd302dd4cf6a8a9f113db0948b1483f3f848b Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Sat, 10 Feb 2024 15:48:09 +0100 Subject: [PATCH 03/10] =?UTF-8?q?CI:=20use=20=E2=80=9Cmake=20test=E2=80=9D?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b385a6..d12510e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,14 +21,14 @@ jobs: printf 'Apt::Install-Recommends "false";\n' | tee -a /etc/apt/apt.conf apt-get update apt-get install -y python3-gi-cairo gir1.2-pango-1.0 - apt-get install -y perl + apt-get install -y make perl - name: check Python version run: | python3 --version - name: run tests run: | export LC_ALL=C.UTF-8 - prove -v + make test verbose=1 static: runs-on: ${{matrix.os}} From 2c36cc145da1235d580f74fd6bc7be7c0cb6ae1e Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Sat, 10 Feb 2024 15:48:18 +0100 Subject: [PATCH 04/10] CI: test installation. --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d12510e..046d46e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,10 @@ jobs: apt-get update apt-get install -y python3-gi-cairo gir1.2-pango-1.0 apt-get install -y make perl + - name: set up PATH + run: | + PATH="$PATH:$HOME/.local/bin" + echo "$PATH" >> $GITHUB_PATH - name: check Python version run: | python3 --version @@ -29,6 +33,19 @@ jobs: run: | export LC_ALL=C.UTF-8 make test verbose=1 + - name: install + run: | + make install PREFIX=~/.local + - name: check whether the executable was installed correctly + run: | + cd / + ubanner --help + - name: run post-install tests + run: | + mv ubanner ubanner.bak + export LC_ALL=C.UTF-8 + make test-installed verbose=1 + mv ubanner.bak ubanner static: runs-on: ${{matrix.os}} From 9e0188eae2fd0a8188eef679f20bf075c07ddb3a Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 10:24:19 +0100 Subject: [PATCH 05/10] Add --version. --- ubanner | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ubanner b/ubanner index 771ebb1..f83311a 100755 --- a/ubanner +++ b/ubanner @@ -22,6 +22,29 @@ from gi.repository import PangoCairo 0_0 # Python >= 3.6 is required +__version__ = '0' # not released yet + +class VersionAction(argparse.Action): + ''' + argparse --version action + ''' + + def __init__(self, option_strings, dest=argparse.SUPPRESS): + super().__init__( + option_strings=option_strings, + dest=dest, + nargs=0, + help='show version information and exit' + ) + + def __call__(self, parser, namespace, values, option_string=None): + print(f'{parser.prog} {__version__}') + print('+ Python {0}.{1}.{2}'.format(*sys.version_info)) + print('+ PyGI', gi.__version__) + print('+ Pango', Pango.version_string()) + print('+ Cairo', cairo.version) + parser.exit() + if sys.version_info < (3, 11): def kbisect(a, x, *, key): lo = 0 @@ -103,6 +126,7 @@ except UnicodeError: def main(): signal.signal(signal.SIGPIPE, signal.SIG_DFL) ap = argparse.ArgumentParser() + ap.add_argument('--version', action=VersionAction) ap.add_argument('--list-fonts', nargs=0, action=act_list_fonts, help='print list of available font faces', ) From 8ec0fbfd407520b0d676c1014042620efda208eb Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 10:24:23 +0100 Subject: [PATCH 06/10] CI: test --version. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 046d46e..3cc9371 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: run: | cd / ubanner --help + ubanner --version - name: run post-install tests run: | mv ubanner ubanner.bak From 5755894ef6b0fff91f18a3a4d3d362c48573b515 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 12:57:38 +0100 Subject: [PATCH 07/10] Overhaul short option names. Repurpose -s as --font-size (instead of --full-screen). Use -S for --full-screen. Use -f for --font. --- ubanner | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ubanner b/ubanner index f83311a..9ab4dd0 100755 --- a/ubanner +++ b/ubanner @@ -134,11 +134,11 @@ def main(): ap.add_argument('--trim', action='store_true', help='trim leading/trailing empty lines', ) - ap.add_argument('--font', help='use this font face') - ap.add_argument('--font-size', type=int, metavar='N', default=default.font_size, + ap.add_argument('-f', '--font', help='use this font face') + ap.add_argument('-s', '--font-size', type=int, metavar='N', default=default.font_size, help=f'font size in pixels (default: {default.font_size})' ) - ap.add_argument('-s', '--full-screen', dest='font_size', action='store_const', const=None) + ap.add_argument('-S', '--full-screen', dest='font_size', action='store_const', const=None) opts = ap.parse_args() if not opts.text: if sys.stdin.isatty(): From be7a8c5b42705abb394b1e02c563d7a37abe3f42 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 13:03:08 +0100 Subject: [PATCH 08/10] t/help: add. --- t/help.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 t/help.t diff --git a/t/help.t b/t/help.t new file mode 100755 index 0000000..dd72ccc --- /dev/null +++ b/t/help.t @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +. "${0%/*}/common.sh" + +echo 1..1 +if out=$("$prog" --help) +then + sed -e 's/^/# /' <<< "$out" + case $out in + 'usage: ubanner '*) + echo ok 1;; + *) + echo not ok 1;; + esac +else + echo not ok 1 +fi + +# vim:ts=4 sts=4 sw=4 et ft=sh From 747211ba6bb91b3ea1c08a009e7069917967ca21 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 13:03:20 +0100 Subject: [PATCH 09/10] t/version: add. --- t/version.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 t/version.t diff --git a/t/version.t b/t/version.t new file mode 100755 index 0000000..5908ad7 --- /dev/null +++ b/t/version.t @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Copyright © 2024 Jakub Wilk +# SPDX-License-Identifier: MIT + +set -e -u + +. "${0%/*}/common.sh" + +echo 1..1 +if out=$("$prog" --version) +then + sed -e 's/^/# /' <<< "$out" + case $out in + $'ubanner 0\n'*) + echo ok 1;; + *) + echo not ok 1;; + esac +else + echo not ok 1 +fi + +# vim:ts=4 sts=4 sw=4 et ft=sh From 151033ae858bcd427323846c297de5e33d8ab0a4 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Mon, 26 Feb 2024 13:05:15 +0100 Subject: [PATCH 10/10] CI: drop redundant post-install testing. References: commit be7a8c5b42705abb394b1e02c563d7a37abe3f42 References: commit 747211ba6bb91b3ea1c08a009e7069917967ca21 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cc9371..e4d6333 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,8 +39,7 @@ jobs: - name: check whether the executable was installed correctly run: | cd / - ubanner --help - ubanner --version + command -v ubanner - name: run post-install tests run: | mv ubanner ubanner.bak