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

[PATCH v3 1/2] t: add a test helper for getting hostname

From
IEIgnacio Encinas <ignacio@iencinas.com>
Date
Mar 19, 2024, 18:37 UTC
Message-ID
<20240319183722.211300-2-ignacio@iencinas.com>
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
Previous: Ignacio EncinasNext: Junio C Hamano
Message 24 of 51 in “Add hostname condition to includeIf”
  1. 0/1 Add hostname condition to includeIfIgnacio Encinas, Mar 7, 2024
  2. 1/1 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 7, 2024
  3. Junio C HamanoMar 7, 2024
  4. Ignacio Encinas RubioMar 9, 2024
  5. Junio C HamanoMar 9, 2024
  6. 0/1 Add hostname condition to includeIfIgnacio Encinas, Mar 9, 2024
  7. 1/1 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 9, 2024
  8. Junio C HamanoMar 10, 2024
  9. Ignacio Encinas RubioMar 10, 2024
  10. Junio C HamanoMar 11, 2024
  11. Ignacio Encinas RubioMar 13, 2024
  12. Jeff KingMar 16, 2024
  13. Ignacio Encinas RubioMar 16, 2024
  14. Taylor BlauMar 16, 2024
  15. Ignacio Encinas RubioMar 16, 2024
  16. Junio C HamanoMar 16, 2024
  17. rsbecker@nexbridge.comMar 16, 2024
  18. Ignacio Encinas RubioMar 16, 2024
  19. rsbecker@nexbridge.comMar 16, 2024
  20. Jeff KingMar 18, 2024
  21. Taylor BlauMar 16, 2024
  22. Ignacio Encinas RubioMar 16, 2024
  23. 0/2 Add hostname condition to includeIfIgnacio Encinas, Mar 19, 2024
  24. 1/2 t: add a test helper for getting hostnameIgnacio Encinas, Mar 19, 2024
  25. Junio C HamanoMar 19, 2024
  26. Jeff KingMar 19, 2024
  27. Junio C HamanoMar 19, 2024
  28. Jeff KingMar 19, 2024
  29. Junio C HamanoMar 19, 2024
  30. Chris TorekMar 21, 2024
  31. Jeff KingMar 19, 2024
  32. 2/2 config: learn the "hostname:" includeIf conditionIgnacio Encinas, Mar 19, 2024
  33. Junio C HamanoMar 19, 2024
  34. Jeff KingMar 19, 2024
  35. Ignacio Encinas RubioMar 19, 2024
  36. Eric SunshineMar 19, 2024
  37. Junio C HamanoMar 19, 2024
  38. Eric SunshineMar 19, 2024
  39. Jeff KingMar 20, 2024
  40. Eric SunshineMar 20, 2024
  41. Eric SunshineMar 20, 2024
  42. Chris TorekMar 20, 2024
  43. Eric SunshineMar 20, 2024
  44. Jeff KingMar 20, 2024
  45. Junio C HamanoMar 20, 2024
  46. Dirk GoudersMar 19, 2024
  47. rsbecker@nexbridge.comMar 19, 2024
  48. Dirk GoudersMar 19, 2024
  49. rsbecker@nexbridge.comMar 19, 2024
  50. Junio C HamanoMar 19, 2024
  51. Ignacio Encinas RubioMar 19, 2024

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.