mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
Add option --only-data-dir (-x)
Only use the dictionaries in data-dir, do not search in user and system directories This makes testing much easier
This commit is contained in:
@@ -144,6 +144,7 @@ if (BUILD_TESTS)
|
|||||||
|
|
||||||
add_sdcv_shell_test(t_list)
|
add_sdcv_shell_test(t_list)
|
||||||
add_sdcv_shell_test(t_use)
|
add_sdcv_shell_test(t_use)
|
||||||
|
add_sdcv_shell_test(t_only_data_dir)
|
||||||
add_sdcv_shell_test(t_synonyms)
|
add_sdcv_shell_test(t_synonyms)
|
||||||
add_sdcv_shell_test(t_interactive)
|
add_sdcv_shell_test(t_interactive)
|
||||||
add_sdcv_shell_test(t_utf8output)
|
add_sdcv_shell_test(t_utf8output)
|
||||||
|
|||||||
14
src/sdcv.cpp
14
src/sdcv.cpp
@@ -78,6 +78,7 @@ int main(int argc, char *argv[]) try {
|
|||||||
gboolean utf8_output = FALSE;
|
gboolean utf8_output = FALSE;
|
||||||
gboolean utf8_input = FALSE;
|
gboolean utf8_input = FALSE;
|
||||||
glib::CharStr opt_data_dir;
|
glib::CharStr opt_data_dir;
|
||||||
|
gboolean only_data_dir = FALSE;
|
||||||
gboolean colorize = FALSE;
|
gboolean colorize = FALSE;
|
||||||
|
|
||||||
const GOptionEntry entries[] = {
|
const GOptionEntry entries[] = {
|
||||||
@@ -97,6 +98,8 @@ int main(int argc, char *argv[]) try {
|
|||||||
{ "data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir),
|
{ "data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir),
|
||||||
_("use this directory as path to stardict data directory"),
|
_("use this directory as path to stardict data directory"),
|
||||||
_("path/to/dir") },
|
_("path/to/dir") },
|
||||||
|
{ "only-data-dir", 'x', 0, G_OPTION_ARG_NONE, &only_data_dir,
|
||||||
|
_("only use the dictionaries in data-dir, do not search in user and system directories"), nullptr },
|
||||||
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
{ "color", 'c', 0, G_OPTION_ARG_NONE, &colorize,
|
||||||
_("colorize the output"), nullptr },
|
_("colorize the output"), nullptr },
|
||||||
{},
|
{},
|
||||||
@@ -122,10 +125,12 @@ int main(int argc, char *argv[]) try {
|
|||||||
const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR");
|
const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR");
|
||||||
std::string data_dir;
|
std::string data_dir;
|
||||||
if (!opt_data_dir) {
|
if (!opt_data_dir) {
|
||||||
|
if (!only_data_dir) {
|
||||||
if (stardict_data_dir)
|
if (stardict_data_dir)
|
||||||
data_dir = stardict_data_dir;
|
data_dir = stardict_data_dir;
|
||||||
else
|
else
|
||||||
data_dir = "/usr/share/stardict/dic";
|
data_dir = "/usr/share/stardict/dic";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data_dir = get_impl(opt_data_dir);
|
data_dir = get_impl(opt_data_dir);
|
||||||
}
|
}
|
||||||
@@ -134,11 +139,10 @@ int main(int argc, char *argv[]) try {
|
|||||||
if (!homedir)
|
if (!homedir)
|
||||||
homedir = g_get_home_dir();
|
homedir = g_get_home_dir();
|
||||||
|
|
||||||
const std::list<std::string> dicts_dir_list = {
|
std::list<std::string> dicts_dir_list;
|
||||||
std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic",
|
if(!only_data_dir)
|
||||||
data_dir
|
dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic");
|
||||||
};
|
dicts_dir_list.push_back(data_dir);
|
||||||
|
|
||||||
if (show_list_dicts) {
|
if (show_list_dicts) {
|
||||||
list_dicts(dicts_dir_list);
|
list_dicts(dicts_dir_list);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|||||||
19
tests/t_only_data_dir
Executable file
19
tests/t_only_data_dir
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SDCV="$1"
|
||||||
|
TEST_DIR="$2"
|
||||||
|
|
||||||
|
unset SDCV_PAGER
|
||||||
|
unset STARDICT_DATA_DIR
|
||||||
|
|
||||||
|
DICTS=$($SDCV -x -n -l --data-dir "$TEST_DIR" | tail -n +2 | wc -l)
|
||||||
|
# the expected result:
|
||||||
|
ACTUAL_DICTS=$(find "$TEST_DIR" -name "*.ifo" | wc -l)
|
||||||
|
if [ $DICTS -ne $ACTUAL_DICTS ]; then
|
||||||
|
echo "number of dictionaries in $TEST_DIR should be $ACTUAL_DICTS but was $DICTS according to sdcv"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user