diff options
author | Reuben Thomas <rrt@sc3d.org> | 2021-11-16 13:45:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 13:45:28 +0000 |
commit | 8e5c2e285e1cb6dcb9dcda45e3bef567e8bb758c (patch) | |
tree | 83a9e192f0472b08ec7c0fc815e8a26449578444 | |
parent | e0d44f3d0e2ec9b40c7662fda7a6e10465028e4f (diff) | |
parent | 7c0fa4a1bc00a14db03a88e3d8d47bd41e2781d5 (diff) | |
download | enchant-8e5c2e285e1cb6dcb9dcda45e3bef567e8bb758c.tar.gz |
Merge pull request #293 from rrthomas/master
Improve reporting of errors by `enchant-lsmod -lang`
-rw-r--r-- | providers/enchant_aspell.c | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/debug.h | 34 | ||||
-rw-r--r-- | src/enchant-lsmod.c | 6 | ||||
-rw-r--r-- | src/lib.c | 1 | ||||
-rw-r--r-- | tests/enchant_providers/Provider/provider_list_dicts.cpp | 18 | ||||
-rw-r--r-- | tests/enchant_providers/Provider/provider_request_dict.cpp | 23 | ||||
-rw-r--r-- | tests/enchant_providers/providers.test.cpp | 2 | ||||
-rw-r--r-- | tests/enchant_providers/unittest_enchant_providers.h | 15 |
9 files changed, 59 insertions, 42 deletions
diff --git a/providers/enchant_aspell.c b/providers/enchant_aspell.c index d79891c..3bef4ef 100644 --- a/providers/enchant_aspell.c +++ b/providers/enchant_aspell.c @@ -143,6 +143,7 @@ aspell_provider_request_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, const c if (aspell_error_number (spell_error) != 0) { + enchant_provider_set_error (me, aspell_error_message (spell_error)); delete_aspell_can_have_error(spell_error); return NULL; } diff --git a/src/Makefile.am b/src/Makefile.am index 35ff7ea..7c89b1c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ endif libenchant_includedir = $(pkgincludedir)-@ENCHANT_MAJOR_VERSION@ libenchant_include_HEADERS = enchant.h enchant-provider.h enchant++.h +noinst_HEADERS = debug.h pkgdata_DATA = enchant.ordering diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 0000000..321fb89 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,34 @@ +/* enchant + * Copyright (C) 2021 Reuben Thomas <rrt@sc3d.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders + * give permission to link the code of this program with + * non-LGPL Spelling Provider libraries (eg: a MSFT Office + * spell checker backend) and distribute linked combinations including + * the two. You must obey the GNU Lesser General Public License in all + * respects for all of the code used other than said providers. If you modify + * this file, you may extend this exception to your version of the + * file, but you are not obligated to do so. If you do not wish to + * do so, delete this exception statement from your version. + */ + +#ifdef DEBUG +#define debug(...) fprintf(stderr, __VA_ARGS__) +#else +#define debug(...) +#endif diff --git a/src/enchant-lsmod.c b/src/enchant-lsmod.c index e8159c8..22c5560 100644 --- a/src/enchant-lsmod.c +++ b/src/enchant-lsmod.c @@ -103,7 +103,11 @@ main (int argc, char **argv) } else { EnchantDict *dict = enchant_broker_request_dict (broker, lang_tag); if (!dict) { - fprintf (stderr, "No dictionary available for '%s'\n", lang_tag); + fprintf (stderr, "No dictionary available for '%s'", lang_tag); + const char *errmsg = enchant_broker_get_error (broker); + if (errmsg != NULL) + fprintf (stderr, ": %s", errmsg); + putc('\n', stderr); retcode = 1; } else { enchant_dict_describe (dict, @@ -46,6 +46,7 @@ #include "enchant.h" #include "enchant-provider.h" +#include "debug.h" #include "pwl.h" #include "unused-parameter.h" #include "relocatable.h" diff --git a/tests/enchant_providers/Provider/provider_list_dicts.cpp b/tests/enchant_providers/Provider/provider_list_dicts.cpp index 5b66413..0317abd 100644 --- a/tests/enchant_providers/Provider/provider_list_dicts.cpp +++ b/tests/enchant_providers/Provider/provider_list_dicts.cpp @@ -62,19 +62,17 @@ TEST_FIXTURE(ProviderListDicts_TestFixture, TEST_FIXTURE(ProviderListDicts_TestFixture,
ProviderListDicts_ForEachReturned_RequestDictSucceeds)
{
- if(_provider->list_dicts && _provider->request_dict)
+ if(_provider->list_dicts)
{
- size_t n_dicts;
+ size_t n_dicts;
- _dicts = (*_provider->list_dicts) (_provider, &n_dicts);
- for (size_t i = 0; i < n_dicts; i++)
- {
- EnchantDict* dict = (*_provider->request_dict) (_provider, _dicts[i]);
- CHECK(dict != NULL);
- if (dict && _provider->dispose_dict)
- {
+ _dicts = (*_provider->list_dicts) (_provider, &n_dicts);
+ for (size_t i = 0; i < n_dicts; i++)
+ {
+ EnchantDict* dict = (*_provider->request_dict) (_provider, _dicts[i]);
+ CHECK(dict != NULL);
+ if (dict)
_provider->dispose_dict(_provider, dict);
- }
}
}
}
diff --git a/tests/enchant_providers/Provider/provider_request_dict.cpp b/tests/enchant_providers/Provider/provider_request_dict.cpp index 1cd2ed6..4ad4680 100644 --- a/tests/enchant_providers/Provider/provider_request_dict.cpp +++ b/tests/enchant_providers/Provider/provider_request_dict.cpp @@ -34,10 +34,8 @@ struct ProviderRequestDictionary_TestFixture : Provider_TestFixture //Teardown
~ProviderRequestDictionary_TestFixture()
{
- if (_dict && _provider->dispose_dict)
- {
- _provider->dispose_dict(_provider, _dict);
- }
+ if (_dict)
+ _provider->dispose_dict(_provider, _dict);
}
};
@@ -49,19 +47,6 @@ struct ProviderRequestDictionary_TestFixture : Provider_TestFixture TEST_FIXTURE(ProviderRequestDictionary_TestFixture,
ProviderRequestDictionary_ProviderDoesNotHave_ReturnsNull)
{
- if (_provider->request_dict)
- {
- _dict = (*_provider->request_dict) (_provider, "zxx"); /*zxx is no linguistic content*/
- CHECK_EQUAL((void*)NULL, _dict);
- }
-}
-
-TEST_FIXTURE(ProviderRequestDictionary_TestFixture,
- ProviderRequestDictionary_ProviderDoesNotHave_ProviderDoesNotSetError)
-{
- if (_provider->request_dict)
- {
- _dict = (*_provider->request_dict) (_provider, "zxx"); /*zxx is no linguistic content*/
- CHECK_EQUAL((void*)NULL, GetErrorMessage(_provider));
- }
+ _dict = (*_provider->request_dict) (_provider, "zxx"); /*zxx is no linguistic content*/
+ CHECK_EQUAL((void*)NULL, _dict);
}
diff --git a/tests/enchant_providers/providers.test.cpp b/tests/enchant_providers/providers.test.cpp index 7d72faf..7f5bcbc 100644 --- a/tests/enchant_providers/providers.test.cpp +++ b/tests/enchant_providers/providers.test.cpp @@ -26,6 +26,7 @@ #include <gmodule.h>
#include <assert.h>
#include <string.h>
+#include <stdlib.h>
#include "unittest_enchant_providers.h"
int Test(char* path);
@@ -167,6 +168,7 @@ int TestProvider(char* filename) g_provider->dispose(g_provider);
g_provider = NULL;
+ free(broker.error);
}
if(module){
diff --git a/tests/enchant_providers/unittest_enchant_providers.h b/tests/enchant_providers/unittest_enchant_providers.h index 5fd2416..62f50ad 100644 --- a/tests/enchant_providers/unittest_enchant_providers.h +++ b/tests/enchant_providers/unittest_enchant_providers.h @@ -69,14 +69,11 @@ struct Provider_TestFixture // Try getting dictionary for user's default language
char *lang = enchant_get_user_language();
- if (_provider->request_dict)
- {
- dict = (*_provider->request_dict) (_provider, lang);
- }
+ dict = (*_provider->request_dict) (_provider, lang);
g_free (lang);
// If not available, get the first dictionary listed as being available
- if (!dict && _provider->list_dicts && _provider->request_dict)
+ if (!dict && _provider->list_dicts)
{
size_t n_dicts;
@@ -90,18 +87,12 @@ struct Provider_TestFixture EnchantDict* GetDictionary(const char* language)
{
- if(_provider->request_dict)
- {
return (*_provider->request_dict) (_provider, language);
- }
- return NULL;
}
virtual void ReleaseDictionary(EnchantDict* dict)
{
- if (dict && _provider->dispose_dict)
- {
+ if (dict)
_provider->dispose_dict(_provider, dict);
- }
}
};
|