git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] test: relocate test_expect_{success,failure}

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Mar 13, 2023, 05:01 UTC
Message-ID
<20230313050132.3464802-2-felipe.contreras@gmail.com>
In-Reply-To
<20230313050132.3464802-1-felipe.contreras@gmail.com>

Their proper place is in test-lib.sh since they aren't meant to be called in a subshell, except in t0000-basic.sh of course.

The rationale behind the move (12a29b1a50 (Move the user-facing test library to test-lib-functions.sh, 2012-02-17)) was that the tests in t/perf would need test-lib-functions.sh inside the subshells, for example:

        test_perf 'perf test' 'test_expect_success foo :'
But that doesn't actually happens in any of the perf tests.
So move these functions back where they belong.
Cc: Thomas Rast <tr@thomasrast.ch>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 t/test-lib-functions.sh | 42 -----------------------------------------
 t/test-lib.sh           | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 999d46fafe..49a850989a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -801,48 +801,6 @@ test_verify_prereq () {
 	BUG "'$test_prereq' does not look like a prereq"
 }
 
-test_expect_failure () {
-	test_start_ "$@"
-	test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
-	test "$#" = 2 ||
-	BUG "not 2 or 3 parameters to test-expect-failure"
-	test_verify_prereq
-	export test_prereq
-	if ! test_skip "$@"
-	then
-		test -n "$test_skip_test_preamble" ||
-		say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $2"
-		if test_run_ "$2" expecting_failure
-		then
-			test_known_broken_ok_ "$1"
-		else
-			test_known_broken_failure_ "$1"
-		fi
-	fi
-	test_finish_
-}
-
-test_expect_success () {
-	test_start_ "$@"
-	test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
-	test "$#" = 2 ||
-	BUG "not 2 or 3 parameters to test-expect-success"
-	test_verify_prereq
-	export test_prereq
-	if ! test_skip "$@"
-	then
-		test -n "$test_skip_test_preamble" ||
-		say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $2"
-		if test_run_ "$2"
-		then
-			test_ok_ "$1"
-		else
-			test_failure_ "$@"
-		fi
-	fi
-	test_finish_
-}
-
 # debugging-friendly alternatives to "test [-f|-d|-e]"
 # The commands test the existence or non-existence of $1
 test_path_is_file () {
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 62136caee5..388075a6c6 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1269,6 +1269,48 @@ check_test_results_san_file_ () {
 	fi
 }
 
+test_expect_failure () {
+	test_start_ "$@"
+	test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
+	test "$#" = 2 ||
+	BUG "not 2 or 3 parameters to test-expect-failure"
+	test_verify_prereq
+	export test_prereq
+	if ! test_skip "$@"
+	then
+		test -n "$test_skip_test_preamble" ||
+		say >&3 "checking known breakage of $TEST_NUMBER.$test_count '$1': $2"
+		if test_run_ "$2" expecting_failure
+		then
+			test_known_broken_ok_ "$1"
+		else
+			test_known_broken_failure_ "$1"
+		fi
+	fi
+	test_finish_
+}
+
+test_expect_success () {
+	test_start_ "$@"
+	test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
+	test "$#" = 2 ||
+	BUG "not 2 or 3 parameters to test-expect-success"
+	test_verify_prereq
+	export test_prereq
+	if ! test_skip "$@"
+	then
+		test -n "$test_skip_test_preamble" ||
+		say >&3 "expecting success of $TEST_NUMBER.$test_count '$1': $2"
+		if test_run_ "$2"
+		then
+			test_ok_ "$1"
+		else
+			test_failure_ "$@"
+		fi
+	fi
+	test_finish_
+}
+
 test_done () {
 	# Run the atexit commands _before_ the trash directory is
 	# removed, so the commands can access pidfiles and socket files.
-- 
2.39.2.13.g1fb56cf030
Previous: Felipe ContrerasNext: Felipe Contreras
Message 2 of 3 in “test: framework API cleanup”
  1. 0/2 test: framework API cleanupFelipe Contreras, Mar 13, 2023
  2. 1/2 test: relocate test_expect_{success,failure}Felipe Contreras, Mar 13, 2023
  3. 2/2 test: relocate yesFelipe Contreras, Mar 13, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.