From nobody Mon Oct 07 21:01:33 2024 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 4XMs5T606Zz5YSLj; Mon, 07 Oct 2024 21:01:33 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XMs5T5M0Cz5577; Mon, 7 Oct 2024 21:01:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728334893; 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=dpDc/yi+tlcuNllltkx0PE3A8WA1H9hDo2gp1DbanWI=; b=PIxsBEJ2FdRVBCC0lACvy1qalwpaRx4K+fF/K3QZLsP+AFr6kaGTCKk9kGoK43qT70DRvB 6broS6wHSCueiMms7YNYIZcUoxaqgyP8Gt1uWfZNoJhGe9TO1mDrcYljXrtxlrf5vNOJyr BP+kk8gzkiFZNs7wFcvlbplkhaFGiOhkGOThUqjA1IylIwPrzi8mR1EZpMoXtwCbXFs/C9 Mi46c6fExwLhN9cbrkgRYfa2aSycKdZtDesoaDU3B2rMEaZCsXagV9XmF+fdzFkYOUkpAJ SEQY+EPaXajuPzlK2CqikDesVzN9/h3LAA6UKfZKIW+IaNsbgXxyTfMvmgkM9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728334893; 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=dpDc/yi+tlcuNllltkx0PE3A8WA1H9hDo2gp1DbanWI=; b=ZvPWjKII4tzHXBKzsgw1wazukX0Ep8AysVI2WLYV8sDc5bBHm+7BSy1YTlR3/nW3ousMOM Nagr4rw66eqKM0BDOTNRsD7vIhXCZzGP27oC5LU+eNZkYhjbZChUvCVc9Y0pnD22QQCuOf 9ErhXwu1kshw4R7+ZP5OgD/3eG2708lfR1jt/lNYc1ZncShIigj1F7YS9rXxQiuFgfZ8f1 XkZAh2nPJUYp4gwLOdD6DUp6agBQsuwXBMMczVpJ46NexJy2CHnkLCJhL6UxgOFTXaXwvM lJ9V0zyCYUEX+zmk4qBXFMxfXg4RjCoE/XRgAyXA/PSNLnWLusn3DNcbsxi/Mw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728334893; a=rsa-sha256; cv=none; b=Ht3DOPHmIwF5oROVRgx/OvwKBImeTLuWfZq34SgIjhnPoM4qKpkRjxk4zLLk+l80gRfwyH uCaggivRl9QwNqzEn+ZvjK/X6NM/29pK3ThIfD3DHopYFOI8zPm+y/FQa3k2Wrgd8POXWg l1JrZN6hnQyU9CClihm/tAgnR4XPbp4Lm/2GiyFce16t8rWpW44gsgOhidlCh424KiSwEI SGzkLnaA1B/9uXGoEOR1ue4BFXlsSg2KDC2RFQ4qPeBvLUydp3fJYRwn5GzylV1SZM7BPs lHYYAwfdidmf/Wrgm06bZ8BUxrgUA19htBzp+v2UbbVyyR6L9vqok5ude7P+/g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XMs5T4yqSz12jk; Mon, 7 Oct 2024 21:01:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 497L1XiM027042; Mon, 7 Oct 2024 21:01:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 497L1X28027039; Mon, 7 Oct 2024 21:01:33 GMT (envelope-from git) Date: Mon, 7 Oct 2024 21:01:33 GMT Message-Id: <202410072101.497L1X28027039@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 334af5e4131b - main - env: Add a handful of test cases. 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 334af5e4131b21c658203635bf713d6a59846585 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=334af5e4131b21c658203635bf713d6a59846585 commit 334af5e4131b21c658203635bf713d6a59846585 Author: Dag-Erling Smørgrav AuthorDate: 2024-10-07 21:00:17 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-10-07 21:01:09 +0000 env: Add a handful of test cases. MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D46996 --- etc/mtree/BSD.tests.dist | 2 + usr.bin/env/Makefile | 5 +++ usr.bin/env/tests/Makefile | 6 +++ usr.bin/env/tests/env_test.sh | 100 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 67dc71fbfda4..8cac5e8d55e2 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1097,6 +1097,8 @@ .. du .. + env + .. factor .. file diff --git a/usr.bin/env/Makefile b/usr.bin/env/Makefile index 81f18e58f80e..f284770af5bb 100644 --- a/usr.bin/env/Makefile +++ b/usr.bin/env/Makefile @@ -1,7 +1,12 @@ +.include + PACKAGE= runtime PROG= env SRCS= env.c envopts.c LIBADD= util +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests + .include diff --git a/usr.bin/env/tests/Makefile b/usr.bin/env/tests/Makefile new file mode 100644 index 000000000000..3d2f77b34b67 --- /dev/null +++ b/usr.bin/env/tests/Makefile @@ -0,0 +1,6 @@ +PACKAGE= tests + +ATF_TESTS_SH= env_test +BINDIR= ${TESTSDIR} + +.include diff --git a/usr.bin/env/tests/env_test.sh b/usr.bin/env/tests/env_test.sh new file mode 100644 index 000000000000..7568f81ab603 --- /dev/null +++ b/usr.bin/env/tests/env_test.sh @@ -0,0 +1,100 @@ +# +# Copyright (c) 2024 Klara, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause +# + +magic_words="Squeamish $$ Ossifrage" + +atf_test_case basic +basic_head() +{ + atf_set "descr" "Basic test case" +} +basic_body() +{ + atf_check -o match:"^magic_words=${magic_words}\$" \ + env magic_words="${magic_words}" + export MAGIC_WORDS="${magic_words}" + atf_check -o match:"^MAGIC_WORDS=${magic_words}\$" \ + env + unset MAGIC_WORDS +} + +atf_test_case unset +unset_head() +{ + atf_set "descr" "Unset a variable" +} +unset_body() +{ + export MAGIC_WORDS="${magic_words}" + atf_check -o not-match:"^MAGIC_WORDS=" \ + env -u MAGIC_WORDS + unset MAGIC_WORDS +} + +atf_test_case empty +empty_head() +{ + atf_set "descr" "Empty environment" +} +empty_body() +{ + atf_check env -i +} + +atf_test_case true +true_head() +{ + atf_set "descr" "Run true" +} +true_body() +{ + atf_check env true +} + +atf_test_case false +false_head() +{ + atf_set "descr" "Run false" +} +false_body() +{ + atf_check -s exit:1 env false +} + +atf_test_case false +false_head() +{ + atf_set "descr" "Run false" +} +false_body() +{ + atf_check -s exit:1 env false +} + +atf_test_case altpath +altpath_head() +{ + atf_set "descr" "Use alternate path" +} +altpath_body() +{ + echo "echo ${magic_words}" >magic_words + chmod 0755 magic_words + atf_check -s exit:127 -e match:"No such file" \ + env magic_words + atf_check -o inline:"${magic_words}\n" \ + env -P "${PWD}" magic_words +} + +atf_init_test_cases() +{ + atf_add_test_case basic + atf_add_test_case unset + atf_add_test_case empty + atf_add_test_case true + atf_add_test_case false + atf_add_test_case altpath +}