git: 570d050f4e18 - main - ncal: convert legacy TAP tests to ATF

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Fri, 09 Oct 2026 15:12:42 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=570d050f4e182ea2cd6c26a996b69fde6049ac4f

commit 570d050f4e182ea2cd6c26a996b69fde6049ac4f
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2026-10-08 19:19:54 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2026-10-09 15:11:04 +0000

    ncal: convert legacy TAP tests to ATF
    
    MFC after:      2 weeks
    Sponsored by:   ConnectWise
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2465
    Reviewed by:    imp
---
 ObsoleteFiles.inc                 |   4 ++
 usr.bin/ncal/tests/Makefile       |   3 +-
 usr.bin/ncal/tests/legacy_test.sh |   5 --
 usr.bin/ncal/tests/ncal_test.sh   | 148 ++++++++++++++++++++++++++++++++++++++
 usr.bin/ncal/tests/regress.sh     |  79 --------------------
 5 files changed, 153 insertions(+), 86 deletions(-)

diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc
index 93a31ad8e6ac..0f6ebd3c8e78 100644
--- a/ObsoleteFiles.inc
+++ b/ObsoleteFiles.inc
@@ -51,6 +51,10 @@
 #   xargs -n1 | sort | uniq -d;
 # done
 
+# 20261008: replaced with ATF test
+OLD_FILES+=usr/tests/usr.bin/ncal/legacy_test
+OLD_FILES+=usr/tests/usr.bin/ncal/regress.sh
+
 # 20260930: apm(8) only displays ACPI status
 OLD_FILES+=etc/rc.d/apm
 
diff --git a/usr.bin/ncal/tests/Makefile b/usr.bin/ncal/tests/Makefile
index 96b9751c43e1..c270e28b12f2 100644
--- a/usr.bin/ncal/tests/Makefile
+++ b/usr.bin/ncal/tests/Makefile
@@ -1,6 +1,6 @@
 PACKAGE=	tests
 
-TAP_TESTS_SH=	legacy_test
+ATF_TESTS_SH=	ncal_test
 
 ${PACKAGE}FILES+=		regress.b-3m200901-jd-nhl.out
 ${PACKAGE}FILES+=		regress.b-3m200901-md-nhl.out
@@ -91,6 +91,5 @@ ${PACKAGE}FILES+=		regress.s-r-B-nhl.out
 ${PACKAGE}FILES+=		regress.s-r-gmgy-nhl.out
 ${PACKAGE}FILES+=		regress.s-r-m-nhl.out
 ${PACKAGE}FILES+=		regress.s-r-mgy-nhl.out
-${PACKAGE}FILES+=		regress.sh
 
 .include <bsd.test.mk>
diff --git a/usr.bin/ncal/tests/legacy_test.sh b/usr.bin/ncal/tests/legacy_test.sh
deleted file mode 100644
index 3c7842d07bf0..000000000000
--- a/usr.bin/ncal/tests/legacy_test.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-SRCDIR="$(dirname "${0}")"; export SRCDIR
-
-m4 "${SRCDIR}/../regress.m4" "${SRCDIR}/regress.sh" | sh
diff --git a/usr.bin/ncal/tests/ncal_test.sh b/usr.bin/ncal/tests/ncal_test.sh
new file mode 100644
index 000000000000..51bc99a888cc
--- /dev/null
+++ b/usr.bin/ncal/tests/ncal_test.sh
@@ -0,0 +1,148 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+
+export LC_ALL=C
+
+ncal_out()
+{
+	local name="$1"
+	shift
+
+	atf_check -s exit:0 \
+	    -o "file:$(atf_get_srcdir)/regress.${name}.out" -e empty \
+	    ncal "$@"
+}
+
+ncal_err()
+{
+	local name="$1"
+	shift
+
+	atf_check -s exit:64 \
+	    -o empty -e "file:$(atf_get_srcdir)/regress.${name}.out" \
+	    ncal "$@"
+}
+
+atf_test_case year_md
+year_md_head()
+{
+	atf_set "descr" "Full-year calendars in month-day format"
+}
+year_md_body()
+{
+	local y
+
+	for y in 2008 2009 2010 2011; do
+		ncal_out "r-y${y}-md-nhl" -N -h "${y}"
+		ncal_out "b-y${y}-md-nhl" -C -h "${y}"
+	done
+}
+
+atf_test_case year_jd
+year_jd_head()
+{
+	atf_set "descr" "Full-year calendars in Julian-day format"
+}
+year_jd_body()
+{
+	local y
+
+	for y in 2008 2009 2010 2011; do
+		ncal_out "r-y${y}-jd-nhl" -N -jh "${y}"
+		ncal_out "b-y${y}-jd-nhl" -C -jh "${y}"
+	done
+}
+
+atf_test_case three_month_md
+three_month_md_head()
+{
+	atf_set "descr" "Three-month calendars in month-day format"
+}
+three_month_md_body()
+{
+	local m
+
+	for m in $(jot -w %02d 12); do
+		ncal_out "r-3m2009${m}-md-nhl" -N -h3 "${m}" 2009
+		ncal_out "b-3m2009${m}-md-nhl" -C -h3 "${m}" 2009
+	done
+}
+
+atf_test_case three_month_jd
+three_month_jd_head()
+{
+	atf_set "descr" "Three-month calendars in Julian-day format"
+}
+three_month_jd_body()
+{
+	local m
+
+	for m in $(jot -w %02d 12); do
+		ncal_out "r-3m2009${m}-jd-nhl" -N -jh3 "${m}" 2009
+		ncal_out "b-3m2009${m}-jd-nhl" -C -jh3 "${m}" 2009
+	done
+}
+
+atf_test_case invalid_args
+invalid_args_head()
+{
+	atf_set "descr" "Unsupported option combinations"
+}
+invalid_args_body()
+{
+	ncal_err f-3y-nhl -N -3 -y
+	ncal_err f-3A-nhl -N -3 -A 3
+	ncal_err f-3B-nhl -N -3 -B 3
+	ncal_err f-3gy-nhl -N -3 2008
+	ncal_err f-3AB-nhl -N -3 -A 3 -B 3
+	ncal_err f-mgm-nhl -N -m 3 2 2008
+	ncal_err f-ym-nhl -N -y -m 2
+	ncal_err f-ygm-nhl -N -y 2 2008
+	ncal_err f-yA-nhl -N -y -A 3
+	ncal_err f-yB-nhl -N -y -B 3
+	ncal_err f-yAB-nhl -N -y -A 3 -B 3
+}
+
+atf_test_case cal_options
+cal_options_head()
+{
+	atf_set "descr" "cal-mode -3, -A, -B, and -m combinations"
+}
+cal_options_body()
+{
+	ncal_out s-b-3-nhl -C -d 2008.03 -3
+	ncal_out s-b-A-nhl -C -d 2008.03 -A 1
+	ncal_out s-b-B-nhl -C -d 2008.03 -B 1
+	ncal_out s-b-AB-nhl -C -d 2008.03 -A 1 -B 1
+	ncal_out s-b-m-nhl -C -d 2008.03 -m 1
+	ncal_out s-b-mgy-nhl -C -d 2008.03 -m 1 2007
+	ncal_out s-b-gmgy-nhl -C -d 2008.03 1 2007
+}
+
+atf_test_case ncal_options
+ncal_options_head()
+{
+	atf_set "descr" "ncal-mode -3, -A, -B, and -m combinations"
+}
+ncal_options_body()
+{
+	ncal_out s-r-3-nhl -N -d 2008.03 -3
+	ncal_out s-r-A-nhl -N -d 2008.03 -A 1
+	ncal_out s-r-B-nhl -N -d 2008.03 -B 1
+	ncal_out s-r-AB-nhl -N -d 2008.03 -A 1 -B 1
+	ncal_out s-r-m-nhl -N -d 2008.03 -m 1
+	ncal_out s-r-mgy-nhl -N -d 2008.03 -m 1 2007
+	ncal_out s-r-gmgy-nhl -N -d 2008.03 1 2007
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case year_md
+	atf_add_test_case year_jd
+	atf_add_test_case three_month_md
+	atf_add_test_case three_month_jd
+	atf_add_test_case invalid_args
+	atf_add_test_case cal_options
+	atf_add_test_case ncal_options
+}
diff --git a/usr.bin/ncal/tests/regress.sh b/usr.bin/ncal/tests/regress.sh
deleted file mode 100644
index cced1f3f1c72..000000000000
--- a/usr.bin/ncal/tests/regress.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-
-CAL_BIN="ncal"
-CAL="${CAL_BIN} -C"
-NCAL="${CAL_BIN} -N"
-YEARS="2008 2009 2010 2011"
-ONEYEAR="2009"
-
-echo 1..89
-
-REGRESSION_START($1)
-
-#
-# The first tests are layout tests, to make sure that the output is still the
-# same despite varying months.
-#
-
-# Full year calendars
-
-for y in ${YEARS}; do
-	# Regular calendar, Month days, No-highlight
-	REGRESSION_TEST(`r-y${y}-md-nhl', `$NCAL -h ${y}')
-	# Backwards calendar, Month days, No-highlight
-	REGRESSION_TEST(`b-y${y}-md-nhl', `$CAL -h ${y}')
-	# Regular calendar, Julian days, No-highlight
-	REGRESSION_TEST(`r-y${y}-jd-nhl', `$NCAL -jh ${y}')
-	# Backwards calendar, Julian days, No-highlight
-	REGRESSION_TEST(`b-y${y}-jd-nhl', `$CAL -jh ${y}')
-done
-
-# 3 month calendars
-
-for m in $(jot -w %02d 12); do
-	# Regular calendar, Month days, No-highlight
-	REGRESSION_TEST(`r-3m${ONEYEAR}${m}-md-nhl',
-	    `$NCAL -h3 ${m} ${ONEYEAR}')
-	# Backwards calendar, Month days, No-highlight
-	REGRESSION_TEST(`b-3m${ONEYEAR}${m}-md-nhl', `$CAL -h3 ${m} ${ONEYEAR}')
-	# Regular calendar, Julian days, No-highlight
-	REGRESSION_TEST(`r-3m${ONEYEAR}${m}-jd-nhl',
-	    `$NCAL -jh3 ${m} ${ONEYEAR}')
-	# Backwards calendar, Julian days, No-highlight
-	REGRESSION_TEST(`b-3m${ONEYEAR}${m}-jd-nhl', `$CAL -jh3 ${m} ${ONEYEAR}')
-done
-
-#
-# The next tests are combinations of the various arguments.
-#
-
-# These should fail
-REGRESSION_TEST(`f-3y-nhl',  `$NCAL -3 -y 2>&1')
-REGRESSION_TEST(`f-3A-nhl',  `$NCAL -3 -A 3 2>&1')
-REGRESSION_TEST(`f-3B-nhl',  `$NCAL -3 -B 3 2>&1')
-REGRESSION_TEST(`f-3gy-nhl', `$NCAL -3 2008 2>&1')
-REGRESSION_TEST(`f-3AB-nhl', `$NCAL -3 -A 3 -B 3 2>&1')
-REGRESSION_TEST(`f-mgm-nhl', `$NCAL -m 3 2 2008 2>&1')
-REGRESSION_TEST(`f-ym-nhl',  `$NCAL -y -m 2 2>&1')
-REGRESSION_TEST(`f-ygm-nhl', `$NCAL -y 2 2008 2>&1')
-REGRESSION_TEST(`f-yA-nhl',  `$NCAL -y -A 3 2>&1')
-REGRESSION_TEST(`f-yB-nhl',  `$NCAL -y -B 3 2>&1')
-REGRESSION_TEST(`f-yAB-nhl', `$NCAL -y -A 3 -B 3 2>&1')
-
-# These should be successful
-
-REGRESSION_TEST(`s-b-3-nhl',    `$CAL -d 2008.03 -3')
-REGRESSION_TEST(`s-b-A-nhl',    `$CAL -d 2008.03 -A 1')
-REGRESSION_TEST(`s-b-B-nhl',    `$CAL -d 2008.03 -B 1')
-REGRESSION_TEST(`s-b-AB-nhl',   `$CAL -d 2008.03 -A 1 -B 1')
-REGRESSION_TEST(`s-b-m-nhl',    `$CAL -d 2008.03 -m 1')
-REGRESSION_TEST(`s-b-mgy-nhl',  `$CAL -d 2008.03 -m 1 2007')
-REGRESSION_TEST(`s-b-gmgy-nhl', `$CAL -d 2008.03 1 2007')
-REGRESSION_TEST(`s-r-3-nhl',    `$NCAL -d 2008.03 -3')
-REGRESSION_TEST(`s-r-A-nhl',    `$NCAL -d 2008.03 -A 1')
-REGRESSION_TEST(`s-r-B-nhl',    `$NCAL -d 2008.03 -B 1')
-REGRESSION_TEST(`s-r-AB-nhl',   `$NCAL -d 2008.03 -A 1 -B 1')
-REGRESSION_TEST(`s-r-m-nhl',    `$NCAL -d 2008.03 -m 1')
-REGRESSION_TEST(`s-r-mgy-nhl',  `$NCAL -d 2008.03 -m 1 2007')
-REGRESSION_TEST(`s-r-gmgy-nhl', `$NCAL -d 2008.03 1 2007')
-
-REGRESSION_END()