git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ignacio Encinas <ignacio@iencinas.com>
To: git@vger.kernel.org
Cc: Ignacio Encinas <ignacio@iencinas.com>
Subject: [PATCH v3 1/2] t: add a test helper for getting hostname
Date: Tue, 19 Mar 2024 19:37:21 +0100	[thread overview]
Message-ID: <20240319183722.211300-2-ignacio@iencinas.com> (raw)
In-Reply-To: <20240319183722.211300-1-ignacio@iencinas.com>

Avoid relying on whether the system running the test has "hostname"
installed or not, and expose the output of xgethostname through
test-tool.

Signed-off-by: Ignacio Encinas <ignacio@iencinas.com>
---
 Makefile                     |  1 +
 t/helper/test-tool.c         |  1 +
 t/helper/test-tool.h         |  1 +
 t/helper/test-xgethostname.c | 12 ++++++++++++
 t/t6500-gc.sh                |  3 +--
 5 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 t/helper/test-xgethostname.c

diff --git a/Makefile b/Makefile
index 4e255c81f223..561d7a1fa268 100644
--- a/Makefile
+++ b/Makefile
@@ -863,6 +863,7 @@ TEST_BUILTINS_OBJS += test-userdiff.o
 TEST_BUILTINS_OBJS += test-wildmatch.o
 TEST_BUILTINS_OBJS += test-windows-named-pipe.o
 TEST_BUILTINS_OBJS += test-write-cache.o
+TEST_BUILTINS_OBJS += test-xgethostname.o
 TEST_BUILTINS_OBJS += test-xml-encode.o
 
 # Do not add more tests here unless they have extra dependencies. Add
diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
index 482a1e58a4b6..9318900a2981 100644
--- a/t/helper/test-tool.c
+++ b/t/helper/test-tool.c
@@ -86,6 +86,7 @@ static struct test_cmd cmds[] = {
 	{ "truncate", cmd__truncate },
 	{ "userdiff", cmd__userdiff },
 	{ "urlmatch-normalization", cmd__urlmatch_normalization },
+	{ "xgethostname", cmd__xgethostname },
 	{ "xml-encode", cmd__xml_encode },
 	{ "wildmatch", cmd__wildmatch },
 #ifdef GIT_WINDOWS_NATIVE
diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
index b1be7cfcf593..075d34bd3c0a 100644
--- a/t/helper/test-tool.h
+++ b/t/helper/test-tool.h
@@ -79,6 +79,7 @@ int cmd__trace2(int argc, const char **argv);
 int cmd__truncate(int argc, const char **argv);
 int cmd__userdiff(int argc, const char **argv);
 int cmd__urlmatch_normalization(int argc, const char **argv);
+int cmd__xgethostname(int argc, const char **argv);
 int cmd__xml_encode(int argc, const char **argv);
 int cmd__wildmatch(int argc, const char **argv);
 #ifdef GIT_WINDOWS_NATIVE
diff --git a/t/helper/test-xgethostname.c b/t/helper/test-xgethostname.c
new file mode 100644
index 000000000000..285746aef54a
--- /dev/null
+++ b/t/helper/test-xgethostname.c
@@ -0,0 +1,12 @@
+#include "test-tool.h"
+
+int cmd__xgethostname(int argc, const char **argv)
+{
+	char hostname[HOST_NAME_MAX + 1];
+
+	if (xgethostname(hostname, sizeof(hostname)))
+		die("unable to get the host name");
+
+	puts(hostname);
+	return 0;
+}
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
index 18fe1c25e6a0..613c766e2bb4 100755
--- a/t/t6500-gc.sh
+++ b/t/t6500-gc.sh
@@ -395,7 +395,6 @@ test_expect_success 'background auto gc respects lock for all operations' '
 
 	# now fake a concurrent gc that holds the lock; we can use our
 	# shell pid so that it looks valid.
-	hostname=$(hostname || echo unknown) &&
 	shell_pid=$$ &&
 	if test_have_prereq MINGW && test -f /proc/$shell_pid/winpid
 	then
@@ -404,7 +403,7 @@ test_expect_success 'background auto gc respects lock for all operations' '
 		# the Windows PID in this case.
 		shell_pid=$(cat /proc/$shell_pid/winpid)
 	fi &&
-	printf "%d %s" "$shell_pid" "$hostname" >.git/gc.pid &&
+	printf "%d %s" "$shell_pid" "$(test-tool xgethostname)" >.git/gc.pid &&
 
 	# our gc should exit zero without doing anything
 	run_and_wait_for_auto_gc &&
-- 
2.44.0


  reply	other threads:[~2024-03-19 18:38 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 20:50 [RFC PATCH 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-07 20:50 ` [RFC PATCH 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-07 21:40   ` Junio C Hamano
2024-03-09 10:47     ` Ignacio Encinas Rubio
2024-03-09 17:38       ` Junio C Hamano
2024-03-09 18:18 ` [PATCH v2 0/1] Add hostname condition to includeIf Ignacio Encinas
2024-03-09 18:18   ` [PATCH v2 1/1] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-10 16:59     ` Junio C Hamano
2024-03-10 18:46       ` Ignacio Encinas Rubio
2024-03-11 17:39         ` Junio C Hamano
2024-03-13 21:53           ` Ignacio Encinas Rubio
2024-03-16  6:57     ` Jeff King
2024-03-16 11:19       ` Ignacio Encinas Rubio
2024-03-16 16:00         ` Taylor Blau
2024-03-16 16:46           ` Ignacio Encinas Rubio
2024-03-16 17:02       ` Junio C Hamano
2024-03-16 17:41         ` rsbecker
2024-03-16 18:05           ` Ignacio Encinas Rubio
2024-03-16 18:49             ` rsbecker
2024-03-18  8:17         ` Jeff King
2024-03-16 16:01     ` Taylor Blau
2024-03-16 16:50       ` Ignacio Encinas Rubio
2024-03-19 18:37   ` [PATCH v3 0/2] Add hostname condition to includeIf Ignacio Encinas
2024-03-19 18:37     ` Ignacio Encinas [this message]
2024-03-19 20:31       ` [PATCH v3 1/2] t: add a test helper for getting hostname Junio C Hamano
2024-03-19 20:57         ` Jeff King
2024-03-19 21:00           ` Junio C Hamano
2024-03-19 21:11             ` Jeff King
2024-03-19 21:44               ` Junio C Hamano
2024-03-21  0:11                 ` Chris Torek
2024-03-19 20:56       ` Jeff King
2024-03-19 18:37     ` [PATCH v3 2/2] config: learn the "hostname:" includeIf condition Ignacio Encinas
2024-03-19 20:53       ` Junio C Hamano
2024-03-19 21:04       ` Jeff King
2024-03-19 21:32         ` Ignacio Encinas Rubio
2024-03-19 20:55     ` [PATCH v3 0/2] Add hostname condition to includeIf Eric Sunshine
2024-03-19 21:12       ` Junio C Hamano
2024-03-19 21:13         ` Eric Sunshine
2024-03-20  0:19           ` Jeff King
2024-03-20  2:49             ` Eric Sunshine
2024-03-20  3:07               ` Eric Sunshine
2024-03-20 14:34                 ` Chris Torek
2024-03-20 16:37                   ` Eric Sunshine
2024-03-20 20:51                     ` Jeff King
2024-03-20 16:49                   ` Junio C Hamano
2024-03-19 21:36         ` Dirk Gouders
2024-03-19 22:03           ` rsbecker
2024-03-19 22:26             ` Dirk Gouders
2024-03-19 22:31               ` rsbecker
2024-03-19 22:59                 ` Junio C Hamano
2024-03-19 21:22       ` Ignacio Encinas Rubio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240319183722.211300-2-ignacio@iencinas.com \
    --to=ignacio@iencinas.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).