From nobody Thu Feb 19 09:47:19 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fGpSl5FXQz6Sg5Z for ; Thu, 19 Feb 2026 09:47:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fGpSl4hjSz46FL for ; Thu, 19 Feb 2026 09:47:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771494439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S2BrD6yO6Yw4P4z2xpbuawWH/fIFVRaVKZDRISgLf/g=; b=xWPeKA/adsyJWZb7aHmUmsFeuJTAG/3zQIpy6qd6jKr2AO0YC/JYXp6xKn+bIJWcPJGF2j FHA1X1Fucdna+mgqcSsAic3Mf1U2ynEgtx5Lzbzy8nd9F8suR8UKqG7PLBv0iOL9gXNfDj DMxwPxwJLOL/s1CW3EefOaJkdpGWSxxW0Y/zp6Oi0PcewIpWRrA2aGUgzIdTjDmqiwFXCW VLz6beRH7hbhvHHkM4z1AGErR7lIJSgyt1QoxF3hPlpCtu4eZ3MLY9xzrG1XLMBOcwbFob TzFBmm8S00Q57Eo2OLspw7QJL2PF/YPDSpmKdqgbRk4Zh2iFj5JLBhwFoMvZ/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1771494439; a=rsa-sha256; cv=none; b=otOPVJglVPAKk5Cj4MtZLngvW741tA4aYRSBtsiI2kaZQZNkZnQajoKrK8CBq0oDqXYNEg b+lyW4ZtsbTvxf9vDYewlE3f7JAkrKVmpJHOkakb75CA9Orjq0YBjQ1mCj3Ha9FOg4ESZd DM7Zvj+zGlXhALTTY1IwJmHD2MR0QQGiZhbvrt8NGoxe7+G9LHpSZYdG+HcpXtd4IegEp8 oiYw6RD0Zjnzpx35IF/o4KGVMq2yPnv8Od6v/Pgt5VAxuQjnrD7ncYHMBdQHdtPLOMUro9 lrGMy855BcVzdfBCyVHuy+fc43FY5b6MFiZOV4hCzQXrzBYiHCkjVzYZwJa70A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771494439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S2BrD6yO6Yw4P4z2xpbuawWH/fIFVRaVKZDRISgLf/g=; b=dxu7CjCNRvQTbiwrPmEbUfziO1vShKP6zJdcd0X/AGx/wENK2lUCo/tHUlN85VS0rUhLBI rFGJc/SX4BXHK61kv7TVyU/SvZgVInm6wBjwzht7VOt5B/ZrgGaiApkVZpDx/iwh0Z+c2q 7HBu0x5XbI3U+KxL00wR0Bsp4+Rf/vXNSus4VvdBE8uHwjWyZE4vQYO9sagNxL7ksIILuz JnQqGOshHZOZ1NB9MKPFDjfLto1WU9MPq75elQpJlBdeP2FUO79q2Bea83nPtvqQZIpMZy bwLI7ovG8sXVHiEcnMPbckpuoa6t4oqE6spvUiYXweEoJT2uUGfp1sQ87RRz+w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fGpSl43KVzctk for ; Thu, 19 Feb 2026 09:47:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1dcfb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 19 Feb 2026 09:47:19 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: f015e48a4a04 - main - ed: convert test suite to ATF/kyua List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f015e48a4a0482787b46e972754619a75475439c Auto-Submitted: auto-generated Date: Thu, 19 Feb 2026 09:47:19 +0000 Message-Id: <6996dc27.1dcfb.62f2f492@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=f015e48a4a0482787b46e972754619a75475439c commit f015e48a4a0482787b46e972754619a75475439c Author: Baptiste Daroussin AuthorDate: 2026-02-17 16:14:09 +0000 Commit: Baptiste Daroussin CommitDate: 2026-02-19 09:46:42 +0000 ed: convert test suite to ATF/kyua MFC After: 1 week --- bin/ed/Makefile | 3 + bin/ed/tests/Makefile | 3 + bin/ed/tests/ed_test.sh | 1782 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1788 insertions(+) diff --git a/bin/ed/Makefile b/bin/ed/Makefile index cad48082f186..07fee7478261 100644 --- a/bin/ed/Makefile +++ b/bin/ed/Makefile @@ -6,4 +6,7 @@ SRCS= buf.c glbl.c io.c main.c re.c sub.c undo.c LINKS= ${BINDIR}/ed ${BINDIR}/red MLINKS= ed.1 red.1 +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/bin/ed/tests/Makefile b/bin/ed/tests/Makefile new file mode 100644 index 000000000000..b75f97bf4d63 --- /dev/null +++ b/bin/ed/tests/Makefile @@ -0,0 +1,3 @@ +ATF_TESTS_SH= ed_test + +.include diff --git a/bin/ed/tests/ed_test.sh b/bin/ed/tests/ed_test.sh new file mode 100755 index 000000000000..c67df8ae9f65 --- /dev/null +++ b/bin/ed/tests/ed_test.sh @@ -0,0 +1,1782 @@ +# SPDX-License-Identifier: BSD-2-Clause +# Copyright (c) 2025 Baptiste Daroussin + +# Helper: create standard 5-line data file +create_std_data() +{ + cat > "$1" <<'EOF' +line 1 +line 2 +line 3 +line 4 +line5 +EOF +} + +# --------------------------------------------------------------------------- +# Append (a) +# --------------------------------------------------------------------------- +atf_test_case append +append_head() +{ + atf_set "descr" "Test append command (a)" +} + +append_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +0a +hello world +. +2a +hello world! +. +$a +hello world!! +. +w output.txt +CMDS + cat > expected.txt <<'EOF' +hello world +line 1 +hello world! +line 2 +line 3 +line 4 +line5 +hello world!! +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Address parsing (addr) +# --------------------------------------------------------------------------- +atf_test_case address +address_head() +{ + atf_set "descr" "Test complex address parsing" +} +address_body() +{ + cat > input.txt <<'EOF' +line 1 +line 2 +line 3 +line 4 +line5 +1ine6 +line7 +line8 +line9 +EOF + ed -s - <<'CMDS' +H +r input.txt +1 d +1 1 d +1,2,d +1;+ + ,d +1,2;., + 2d +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 2 +line9 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Change (c) +# --------------------------------------------------------------------------- +atf_test_case change +change_head() +{ + atf_set "descr" "Test change command (c)" +} +change_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1c +at the top +. +4c +in the middle +. +$c +at the bottom +. +2,3c +between top/middle +. +w output.txt +CMDS + cat > expected.txt <<'EOF' +at the top +between top/middle +in the middle +at the bottom +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Delete (d) +# --------------------------------------------------------------------------- +atf_test_case delete +delete_head() +{ + atf_set "descr" "Test delete command (d)" +} +delete_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1d +2;+1d +$d +w output.txt +CMDS + printf 'line 2\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Insert (i) +# --------------------------------------------------------------------------- +atf_test_case insert +insert_head() +{ + atf_set "descr" "Test insert command (i)" +} +insert_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1i +hello world +. +2i +hello world! +. +$i +hello world!! +. +w output.txt +CMDS + cat > expected.txt <<'EOF' +hello world +hello world! +line 1 +line 2 +line 3 +line 4 +hello world!! +line5 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Join (j) +# --------------------------------------------------------------------------- +atf_test_case join +join_head() +{ + atf_set "descr" "Test join command (j)" +} +join_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1,1j +2,3j +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line 2line 3 +line 4 +line5 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Mark (k) +# --------------------------------------------------------------------------- +atf_test_case mark +mark_head() +{ + atf_set "descr" "Test mark and reference commands (k, ')" +} +mark_body() +{ + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +2ka +1d +'am$ +1ka +0a +hello world +. +'ad +u +'am0 +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 3 +hello world +line 4 +line5 +line 2 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Move (m) +# --------------------------------------------------------------------------- +atf_test_case move +move_head() +{ + atf_set "descr" "Test move command (m)"; +} +move_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1,2m$ +1,2m$ +1,2m$ +$m0 +$m0 +2,3m1 +2,3m3 +w output.txt +CMDS + cat > expected.txt <<'EOF' +line5 +line 1 +line 2 +line 3 +line 4 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Transfer / Copy (t) +# --------------------------------------------------------------------------- +atf_test_case transfer +transfer_head() +{ + atf_set "descr" "Test transfer/copy command (t)"; +} +transfer_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1t0 +2,3t2 +,t$ +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line 1 +line 1 +line 2 +line 2 +line 3 +line 4 +line5 +line 1 +line 1 +line 1 +line 2 +line 2 +line 3 +line 4 +line5 +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case transfer_search +transfer_search_head() +{ + atf_set "descr" "Test transfer with address search (t)"; +} +transfer_search_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +t0;/./ +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line5 +line 2 +line 3 +line 4 +line5 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Undo (u) +# --------------------------------------------------------------------------- +atf_test_case undo +undo_head() +{ + atf_set "descr" "Test undo command (u)"; +} +undo_body() +{ + + create_std_data input.txt + printf 'dummy\n' > readfile.txt + ed -s - <<'CMDS' +H +r input.txt +1;r readfile.txt +u +a +hello +world +. +g/./s//x/\ +a\ +hello\ +world +u +u +u +a +hello world! +. +u +1,$d +u +2,3d +u +c +hello world!! +. +u +u +-1;.,+1j +u +u +u +.,+1t$ +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +hello +hello world!! +line 2 +line 3 +line 4 +line5 +hello +hello world!! +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Global (g) +# --------------------------------------------------------------------------- +atf_test_case global_move +global_move_head() +{ + atf_set "descr" "Test global command with move (g)"; +} +global_move_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +g/./m0 +g/./s/$/\ +hello world +g/hello /s/lo/p!/\ +a\ +order +w output.txt +CMDS + cat > expected.txt <<'EOF' +line5 +help! world +order +line 4 +help! world +order +line 3 +help! world +order +line 2 +help! world +order +line 1 +help! world +order +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case global_change +global_change_head() +{ + atf_set "descr" "Test global command with change (g)"; +} +global_change_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +g/[2-4]/-1,+1c\ +hello world +w output.txt +CMDS + printf 'hello world\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +atf_test_case global_substitute +global_substitute_head() +{ + atf_set "descr" "Test global with substitute and move (g)"; +} +global_substitute_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +g/./s//x/\ +3m0 +g/./s/e/c/\ +2,3m1 +w output.txt +CMDS + cat > expected.txt <<'EOF' +linc 3 +xine 1 +xine 2 +xinc 4 +xinc5 +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case global_undo +global_undo_head() +{ + atf_set "descr" "Test global with undo (g)"; +} +global_undo_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +g/./s/./x/\ +u\ +s/./y/\ +u\ +s/./z/\ +u +u +0a +hello +. +$a +world +. +w output.txt +CMDS + cat > expected.txt <<'EOF' +hello +zine 1 +line 2 +line 3 +line 4 +line5 +world +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case global_copy +global_copy_head() +{ + atf_set "descr" "Test global with copy (g)"; +} +global_copy_body() +{ + + cat > input.txt <<'EOF' +line 1 +line 2 +line 3 +EOF + ed -s - <<'CMDS' +H +r input.txt +g/./1,3t$\ +1d +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line 2 +line 3 +line 2 +line 3 +line 1 +line 3 +line 1 +line 2 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Inverse global (v) +# --------------------------------------------------------------------------- +atf_test_case inverse_global +inverse_global_head() +{ + atf_set "descr" "Test inverse global command (v)"; +} +inverse_global_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +v/[ ]/m0 +v/[ ]/s/$/\ +hello world +v/hello /s/lo/p!/\ +a\ +order +w output.txt +CMDS + cat > expected.txt <<'EOF' +line5 +order +hello world +line 1 +order +line 2 +order +line 3 +order +line 4 +order +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Substitution (s) +# --------------------------------------------------------------------------- +atf_test_case subst_backreference +subst_backreference_head() +{ + atf_set "descr" "Test substitute with backreferences (s)"; +} +subst_backreference_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +s/\([^ ][^ ]*\)/(\1)/g +2s +/3/s +/\(4\)/sr +/\(.\)/srg +%s/i/&e/ +w output.txt +CMDS + cat > expected.txt <<'EOF' +liene 1 +(liene) (2) +(liene) (3) +liene (4) +(()liene5) +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case subst_range +subst_range_head() +{ + atf_set "descr" "Test substitute on range with count and repeat (s)"; +} +subst_range_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +,s/./(&)/3 +s/$/00 +2s//%/g +s/^l +w output.txt +CMDS + cat > expected.txt <<'EOF' +li(n)e 1 +i(n)e 200 +li(n)e 3 +li(n)e 4 +li(n)e500 +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case subst_charclass +subst_charclass_head() +{ + atf_set "descr" "Test substitute with character classes (s)"; +} +subst_charclass_body() +{ + + ed -s - <<'CMDS' +H +a +hello/[]world +. +s/[/]/ / +s/[[:digit:][]/ / +s/[]]/ / +w output.txt +CMDS + printf 'hello world\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Edit (e/E) +# --------------------------------------------------------------------------- +atf_test_case edit_file +edit_file_head() +{ + atf_set "descr" "Test edit file command (E)"; +} +edit_file_body() +{ + + printf 'hello world\n' > input.txt + printf 'E e1_data.txt\n' > e1_data.txt + ed -s - <<'CMDS' +H +r input.txt +E e1_data.txt +w output.txt +CMDS + printf 'E e1_data.txt\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +atf_test_case edit_command +edit_command_head() +{ + atf_set "descr" "Test edit with shell command (E !)"; +} +edit_command_body() +{ + + printf 'E !echo hello world-\n' > input.txt + ed -s - <<'CMDS' +H +r input.txt +E !echo hello world- +w output.txt +CMDS + printf 'hello world-\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +atf_test_case edit_reread +edit_reread_head() +{ + atf_set "descr" "Test edit re-read default file (E)"; +} +edit_reread_body() +{ + + printf 'E !echo hello world-\n' > input.txt + ed -s - <<'CMDS' +H +r input.txt +E +w output.txt +CMDS + printf 'E !echo hello world-\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +atf_test_case edit_lowercase +edit_lowercase_head() +{ + atf_set "descr" "Test lowercase edit re-read (e)"; +} +edit_lowercase_body() +{ + + printf 'E !echo hello world-\n' > input.txt + ed -s - <<'CMDS' +H +r input.txt +e +w output.txt +CMDS + printf 'E !echo hello world-\n' > expected.txt + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Read (r) +# --------------------------------------------------------------------------- +atf_test_case read_command +read_command_head() +{ + atf_set "descr" "Test read with shell command (r !)"; +} +read_command_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +1;r !echo hello world +1 +r !echo hello world +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +hello world +line 2 +line 3 +line 4 +line5 +hello world +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case read_default +read_default_head() +{ + atf_set "descr" "Test read with default filename (r)"; +} +read_default_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +r +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line 2 +line 3 +line 4 +line5 +line 1 +line 2 +line 3 +line 4 +line5 +EOF + atf_check cmp output.txt expected.txt +} + +atf_test_case read_file +read_file_head() +{ + atf_set "descr" "Test read from file (r)"; +} +read_file_body() +{ + + printf 'r r3_data.txt\n' > r3_data.txt + ed -s - <<'CMDS' +H +r r3_data.txt +r r3_data.txt +w output.txt +CMDS + cat > expected.txt <<'EOF' +r r3_data.txt +r r3_data.txt +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Write (w) +# --------------------------------------------------------------------------- +atf_test_case write_pipe +write_pipe_head() +{ + atf_set "descr" "Test write to shell command (w !)"; +} +write_pipe_body() +{ + + create_std_data input.txt + ed -s - <<'CMDS' +H +r input.txt +w !cat >\!.z +r \!.z +w output.txt +CMDS + cat > expected.txt <<'EOF' +line 1 +line 2 +line 3 +line 4 +line5 +line 1 +line 2 +line 3 +line 4 +line5 +EOF + atf_check cmp output.txt expected.txt +} + +# --------------------------------------------------------------------------- +# Quit (q) +# --------------------------------------------------------------------------- +atf_test_case quit +quit_head() +{ + atf_set "descr" "Test quit command (q)"; +} +quit_body() +{ + + ed -s - <<'CMDS' +H +w output.txt +a +hello +. +q +CMDS + atf_check -s exit:0 test ! -s output.txt +} + +# --------------------------------------------------------------------------- +# Shell command (!) +# --------------------------------------------------------------------------- +atf_test_case shell_command +shell_command_head() +{ + atf_set "descr" "Test shell command execution (!)"; +} +shell_command_body() +{ + + ed -s - <<'CMDS' +H +!read one +hello, world +a +okay +. *** 841 LINES SKIPPED ***