submodule--helper: move "is-active" to a test-tool
Create a new "test-tool submodule" and move the "is-active" subcommand over to it. It was added in5c2bd8b77a
(submodule--helper: add is-active subcommand, 2017-03-16), sincea452128a36
(submodule--helper: introduce add-config subcommand, 2021-08-06) it hasn't been used by git-submodule.sh. Since we're creating a command dispatch similar to test-tool.c itself let's split out the "struct test_cmd" into a new test-tool-utils.h, which both this new code and test-tool.c itself can use. 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>
This commit is contained in:

committed by
Junio C Hamano

parent
255a1ae5da
commit
9fb2a970e9
1
Makefile
1
Makefile
@ -785,6 +785,7 @@ TEST_BUILTINS_OBJS += test-strcmp-offset.o
|
|||||||
TEST_BUILTINS_OBJS += test-string-list.o
|
TEST_BUILTINS_OBJS += test-string-list.o
|
||||||
TEST_BUILTINS_OBJS += test-submodule-config.o
|
TEST_BUILTINS_OBJS += test-submodule-config.o
|
||||||
TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
|
TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
|
||||||
|
TEST_BUILTINS_OBJS += test-submodule.o
|
||||||
TEST_BUILTINS_OBJS += test-subprocess.o
|
TEST_BUILTINS_OBJS += test-subprocess.o
|
||||||
TEST_BUILTINS_OBJS += test-trace2.o
|
TEST_BUILTINS_OBJS += test-trace2.o
|
||||||
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
|
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
|
||||||
|
@ -2728,14 +2728,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_active(int argc, const char **argv, const char *prefix)
|
|
||||||
{
|
|
||||||
if (argc != 2)
|
|
||||||
die("submodule--helper is-active takes exactly 1 argument");
|
|
||||||
|
|
||||||
return !is_submodule_active(the_repository, argv[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exit non-zero if any of the submodule names given on the command line is
|
* Exit non-zero if any of the submodule names given on the command line is
|
||||||
* invalid. If no names are given, filter stdin to print only valid names
|
* invalid. If no names are given, filter stdin to print only valid names
|
||||||
@ -3313,7 +3305,6 @@ static struct cmd_struct commands[] = {
|
|||||||
{"summary", module_summary, 0},
|
{"summary", module_summary, 0},
|
||||||
{"push-check", push_check, 0},
|
{"push-check", push_check, 0},
|
||||||
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
||||||
{"is-active", is_active, 0},
|
|
||||||
{"check-name", check_name, 0},
|
{"check-name", check_name, 0},
|
||||||
{"config", module_config, 0},
|
{"config", module_config, 0},
|
||||||
{"set-url", module_set_url, 0},
|
{"set-url", module_set_url, 0},
|
||||||
|
58
t/helper/test-submodule.c
Normal file
58
t/helper/test-submodule.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "test-tool.h"
|
||||||
|
#include "test-tool-utils.h"
|
||||||
|
#include "cache.h"
|
||||||
|
#include "parse-options.h"
|
||||||
|
#include "submodule.h"
|
||||||
|
|
||||||
|
#define TEST_TOOL_IS_ACTIVE_USAGE \
|
||||||
|
"test-tool submodule is-active <name>"
|
||||||
|
static const char *submodule_is_active_usage[] = {
|
||||||
|
TEST_TOOL_IS_ACTIVE_USAGE,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *submodule_usage[] = {
|
||||||
|
TEST_TOOL_IS_ACTIVE_USAGE,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static int cmd__submodule_is_active(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
struct option options[] = {
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
argc = parse_options(argc, argv, "test-tools", options,
|
||||||
|
submodule_is_active_usage, 0);
|
||||||
|
if (argc != 1)
|
||||||
|
usage_with_options(submodule_is_active_usage, options);
|
||||||
|
|
||||||
|
setup_git_directory();
|
||||||
|
|
||||||
|
return !is_submodule_active(the_repository, argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct test_cmd cmds[] = {
|
||||||
|
{ "is-active", cmd__submodule_is_active },
|
||||||
|
};
|
||||||
|
|
||||||
|
int cmd__submodule(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
struct option options[] = {
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
argc = parse_options(argc, argv, "test-tools", options, submodule_usage,
|
||||||
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
||||||
|
if (argc < 1)
|
||||||
|
usage_with_options(submodule_usage, options);
|
||||||
|
|
||||||
|
for (i = 0; i < ARRAY_SIZE(cmds); i++)
|
||||||
|
if (!strcmp(cmds[i].name, argv[0]))
|
||||||
|
return cmds[i].fn(argc, argv);
|
||||||
|
|
||||||
|
usage_msg_optf("unknown subcommand '%s'", submodule_usage, options,
|
||||||
|
argv[0]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
9
t/helper/test-tool-utils.h
Normal file
9
t/helper/test-tool-utils.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef TEST_TOOL_UTILS_H
|
||||||
|
#define TEST_TOOL_UTILS_H
|
||||||
|
|
||||||
|
struct test_cmd {
|
||||||
|
const char *name;
|
||||||
|
int (*fn)(int argc, const char **argv);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,6 @@
|
|||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "test-tool.h"
|
#include "test-tool.h"
|
||||||
|
#include "test-tool-utils.h"
|
||||||
#include "trace2.h"
|
#include "trace2.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
|
||||||
@ -8,11 +9,6 @@ static const char * const test_tool_usage[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct test_cmd {
|
|
||||||
const char *name;
|
|
||||||
int (*fn)(int argc, const char **argv);
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct test_cmd cmds[] = {
|
static struct test_cmd cmds[] = {
|
||||||
{ "advise", cmd__advise_if_enabled },
|
{ "advise", cmd__advise_if_enabled },
|
||||||
{ "bitmap", cmd__bitmap },
|
{ "bitmap", cmd__bitmap },
|
||||||
@ -78,6 +74,7 @@ static struct test_cmd cmds[] = {
|
|||||||
{ "simple-ipc", cmd__simple_ipc },
|
{ "simple-ipc", cmd__simple_ipc },
|
||||||
{ "strcmp-offset", cmd__strcmp_offset },
|
{ "strcmp-offset", cmd__strcmp_offset },
|
||||||
{ "string-list", cmd__string_list },
|
{ "string-list", cmd__string_list },
|
||||||
|
{ "submodule", cmd__submodule },
|
||||||
{ "submodule-config", cmd__submodule_config },
|
{ "submodule-config", cmd__submodule_config },
|
||||||
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
|
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
|
||||||
{ "subprocess", cmd__subprocess },
|
{ "subprocess", cmd__subprocess },
|
||||||
|
@ -68,6 +68,7 @@ int cmd__sigchain(int argc, const char **argv);
|
|||||||
int cmd__simple_ipc(int argc, const char **argv);
|
int cmd__simple_ipc(int argc, const char **argv);
|
||||||
int cmd__strcmp_offset(int argc, const char **argv);
|
int cmd__strcmp_offset(int argc, const char **argv);
|
||||||
int cmd__string_list(int argc, const char **argv);
|
int cmd__string_list(int argc, const char **argv);
|
||||||
|
int cmd__submodule(int argc, const char **argv);
|
||||||
int cmd__submodule_config(int argc, const char **argv);
|
int cmd__submodule_config(int argc, const char **argv);
|
||||||
int cmd__submodule_nested_repo_config(int argc, const char **argv);
|
int cmd__submodule_nested_repo_config(int argc, const char **argv);
|
||||||
int cmd__subprocess(int argc, const char **argv);
|
int cmd__subprocess(int argc, const char **argv);
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
test_description='Test submodule--helper is-active
|
test_description='Test with test-tool submodule is-active
|
||||||
|
|
||||||
This test verifies that `git submodue--helper is-active` correctly identifies
|
This test verifies that `test-tool submodule is-active` correctly identifies
|
||||||
submodules which are "active" and interesting to the user.
|
submodules which are "active" and interesting to the user.
|
||||||
|
|
||||||
|
This is a unit test of the submodule.c is_submodule_active() function,
|
||||||
|
which is also indirectly tested elsewhere.
|
||||||
'
|
'
|
||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
@ -25,13 +28,13 @@ test_expect_success 'setup' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active works with urls' '
|
test_expect_success 'is-active works with urls' '
|
||||||
git -C super submodule--helper is-active sub1 &&
|
test-tool -C super submodule is-active sub1 &&
|
||||||
git -C super submodule--helper is-active sub2 &&
|
test-tool -C super submodule is-active sub2 &&
|
||||||
|
|
||||||
git -C super config --unset submodule.sub1.URL &&
|
git -C super config --unset submodule.sub1.URL &&
|
||||||
test_must_fail git -C super submodule--helper is-active sub1 &&
|
test_must_fail test-tool -C super submodule is-active sub1 &&
|
||||||
git -C super config submodule.sub1.URL ../sub &&
|
git -C super config submodule.sub1.URL ../sub &&
|
||||||
git -C super submodule--helper is-active sub1
|
test-tool -C super submodule is-active sub1
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active works with submodule.<name>.active config' '
|
test_expect_success 'is-active works with submodule.<name>.active config' '
|
||||||
@ -39,11 +42,11 @@ test_expect_success 'is-active works with submodule.<name>.active config' '
|
|||||||
test_when_finished "git -C super config submodule.sub1.URL ../sub" &&
|
test_when_finished "git -C super config submodule.sub1.URL ../sub" &&
|
||||||
|
|
||||||
git -C super config --bool submodule.sub1.active "false" &&
|
git -C super config --bool submodule.sub1.active "false" &&
|
||||||
test_must_fail git -C super submodule--helper is-active sub1 &&
|
test_must_fail test-tool -C super submodule is-active sub1 &&
|
||||||
|
|
||||||
git -C super config --bool submodule.sub1.active "true" &&
|
git -C super config --bool submodule.sub1.active "true" &&
|
||||||
git -C super config --unset submodule.sub1.URL &&
|
git -C super config --unset submodule.sub1.URL &&
|
||||||
git -C super submodule--helper is-active sub1
|
test-tool -C super submodule is-active sub1
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active works with basic submodule.active config' '
|
test_expect_success 'is-active works with basic submodule.active config' '
|
||||||
@ -53,17 +56,17 @@ test_expect_success 'is-active works with basic submodule.active config' '
|
|||||||
git -C super config --add submodule.active "." &&
|
git -C super config --add submodule.active "." &&
|
||||||
git -C super config --unset submodule.sub1.URL &&
|
git -C super config --unset submodule.sub1.URL &&
|
||||||
|
|
||||||
git -C super submodule--helper is-active sub1 &&
|
test-tool -C super submodule is-active sub1 &&
|
||||||
git -C super submodule--helper is-active sub2
|
test-tool -C super submodule is-active sub2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active correctly works with paths that are not submodules' '
|
test_expect_success 'is-active correctly works with paths that are not submodules' '
|
||||||
test_when_finished "git -C super config --unset-all submodule.active" &&
|
test_when_finished "git -C super config --unset-all submodule.active" &&
|
||||||
|
|
||||||
test_must_fail git -C super submodule--helper is-active not-a-submodule &&
|
test_must_fail test-tool -C super submodule is-active not-a-submodule &&
|
||||||
|
|
||||||
git -C super config --add submodule.active "." &&
|
git -C super config --add submodule.active "." &&
|
||||||
test_must_fail git -C super submodule--helper is-active not-a-submodule
|
test_must_fail test-tool -C super submodule is-active not-a-submodule
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active works with exclusions in submodule.active config' '
|
test_expect_success 'is-active works with exclusions in submodule.active config' '
|
||||||
@ -72,8 +75,8 @@ test_expect_success 'is-active works with exclusions in submodule.active config'
|
|||||||
git -C super config --add submodule.active "." &&
|
git -C super config --add submodule.active "." &&
|
||||||
git -C super config --add submodule.active ":(exclude)sub1" &&
|
git -C super config --add submodule.active ":(exclude)sub1" &&
|
||||||
|
|
||||||
test_must_fail git -C super submodule--helper is-active sub1 &&
|
test_must_fail test-tool -C super submodule is-active sub1 &&
|
||||||
git -C super submodule--helper is-active sub2
|
test-tool -C super submodule is-active sub2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active with submodule.active and submodule.<name>.active' '
|
test_expect_success 'is-active with submodule.active and submodule.<name>.active' '
|
||||||
@ -85,8 +88,8 @@ test_expect_success 'is-active with submodule.active and submodule.<name>.active
|
|||||||
git -C super config --bool submodule.sub1.active "false" &&
|
git -C super config --bool submodule.sub1.active "false" &&
|
||||||
git -C super config --bool submodule.sub2.active "true" &&
|
git -C super config --bool submodule.sub2.active "true" &&
|
||||||
|
|
||||||
test_must_fail git -C super submodule--helper is-active sub1 &&
|
test_must_fail test-tool -C super submodule is-active sub1 &&
|
||||||
git -C super submodule--helper is-active sub2
|
test-tool -C super submodule is-active sub2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'is-active, submodule.active and submodule add' '
|
test_expect_success 'is-active, submodule.active and submodule add' '
|
||||||
|
Reference in New Issue
Block a user