submodule--helper: move "resolve-relative-url-test" to a test-tool

As its name suggests the "resolve-relative-url-test" has never been used outside of the test suite, see 63e95beb085 (submodule: port resolve_relative_url from shell to C, 2016-04-15) for its original addition. Perhaps it would make sense to drop this code entirely, as we feel that we've got enough indirect test coverage, but let's leave that question to a possible follow-up change. For now let's keep the test coverage this gives us. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 1, 2022 at 01:17 UTC 96a28a9bc655e1804a516de864d5aada13260f50
3 files changed +43 -24
builtin/submodule--helper.c
-23
@@ -96,28 +96,6 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int
96 return resolved_url;
97 }
98
99 -static int resolve_relative_url_test(int argc, const char **argv, const char *prefix)
100 -{
101 - char *remoteurl, *res;
102 - const char *up_path, *url;
103 -
104 - if (argc != 4)
105 - die("resolve-relative-url-test only accepts three arguments: <up_path> <remoteurl> <url>");
106 -
107 - up_path = argv[1];
108 - remoteurl = xstrdup(argv[2]);
109 - url = argv[3];
110 -
111 - if (!strcmp(up_path, "(null)"))
112 - up_path = NULL;
113 -
114 - res = relative_url(remoteurl, url, up_path);
115 - puts(res);
116 - free(res);
117 - free(remoteurl);
118 - return 0;
119 -}
120 -
99 /* the result should be freed by the caller. */
100 static char *get_submodule_displaypath(const char *path, const char *prefix)
101 {
@@ -3273,7 +3251,6 @@ static struct cmd_struct commands[] = {
3251 {"clone", module_clone, SUPPORT_SUPER_PREFIX},
3252 {"add", module_add, 0},
3253 {"update", module_update, SUPPORT_SUPER_PREFIX},
3276 - {"resolve-relative-url-test", resolve_relative_url_test, 0},
3254 {"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
3255 {"init", module_init, 0},
3256 {"status", module_status, SUPPORT_SUPER_PREFIX},
t/helper/test-submodule.c
+42
@@ -2,6 +2,7 @@
2 #include "test-tool-utils.h"
3 #include "cache.h"
4 #include "parse-options.h"
5 +#include "remote.h"
6 #include "submodule-config.h"
7 #include "submodule.h"
8
@@ -19,9 +20,17 @@ static const char *submodule_is_active_usage[] = {
20 NULL
21 };
22
23 +#define TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE \
24 + "test-tool submodule resolve-relative-url <up_path> <remoteurl> <url>"
25 +static const char *submodule_resolve_relative_url_usage[] = {
26 + TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE,
27 + NULL,
28 +};
29 +
30 static const char *submodule_usage[] = {
31 TEST_TOOL_CHECK_NAME_USAGE,
32 TEST_TOOL_IS_ACTIVE_USAGE,
33 + TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE,
34 NULL
35 };
36
@@ -76,9 +85,42 @@ static int cmd__submodule_is_active(int argc, const char **argv)
85 return !is_submodule_active(the_repository, argv[0]);
86 }
87
88 +static int resolve_relative_url(int argc, const char **argv)
89 +{
90 + char *remoteurl, *res;
91 + const char *up_path, *url;
92 +
93 + up_path = argv[0];
94 + remoteurl = xstrdup(argv[1]);
95 + url = argv[2];
96 +
97 + if (!strcmp(up_path, "(null)"))
98 + up_path = NULL;
99 +
100 + res = relative_url(remoteurl, url, up_path);
101 + puts(res);
102 + free(res);
103 + free(remoteurl);
104 + return 0;
105 +}
106 +
107 +static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
108 +{
109 + struct option options[] = {
110 + OPT_END()
111 + };
112 + argc = parse_options(argc, argv, "test-tools", options,
113 + submodule_resolve_relative_url_usage, 0);
114 + if (argc != 3)
115 + usage_with_options(submodule_resolve_relative_url_usage, options);
116 +
117 + return resolve_relative_url(argc, argv);
118 +}
119 +
120 static struct test_cmd cmds[] = {
121 { "check-name", cmd__submodule_check_name },
122 { "is-active", cmd__submodule_is_active },
123 + { "resolve-relative-url", cmd__submodule_resolve_relative_url},
124 };
125
126 int cmd__submodule(int argc, const char **argv)
t/t0060-path-utils.sh
+1 -1
@@ -22,7 +22,7 @@ relative_path() {
22
23 test_submodule_relative_url() {
24 test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
25 - actual=\$(git submodule--helper resolve-relative-url-test '$1' '$2' '$3') &&
25 + actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') &&
26 test \"\$actual\" = '$4'
27 "
28 }