libDtChat tests: no /tmp/opencode, and test_i18n finds its catalogs
Two defects in the test suite, both of the kind that fails on another
machine but not on the one it was written on.
1. Seven tests put their scratch directories below /tmp/opencode --
a directory of the environment they were written in, not of the
system. mkdtemp() returns NULL when the parent is missing, so on a
machine without /tmp/opencode every one of them failed with a "NULL"
check or perror("mkdtemp"), and nothing was wrong with the code under
test. dc_test_tmpdir() (dc_internal.h, instance.c) now uses $TMPDIR,
or /tmp when it is unset or not absolute.
Measured: after renaming /tmp/opencode away (sudo mv), make check in
lib/libDtChat is 24/24; before the change the same run failed on
test_identity, test_pair, test_store, test_instance, test_filexfer,
test_local and test_i18n.
2. test_i18n takes <de.msg> <en.msg> but TESTS runs it without arguments
(f46a914c added it to TESTS without a runner), so `make check' always
reported "FAIL: test_i18n" with the usage line -- measured 2026-11-22
on the merge build, and identically on build/mcde-host, so not a
regression of that merge. tools/mcde-tests.sh names the files and
passes; the test now falls back to $srcdir (which automake's test
driver exports) and finds them itself, the arguments still winning.
Test: make check in lib/libDtChat -> 24/24 PASS (was 23/24). Both call
forms of test_i18n give "test_i18n: all ok": with the two arguments and
without them. With /tmp/opencode renamed away the full check is green as
well, and the seven scratch directories appear under $TMPDIR when set.
This commit is contained in:
1 parent
8677a22d84
commit
4fead8a3dc
9 files changed
+79
-27
No files matched your search
@@ -731,4 +731,14 @@ void dc_instance_close(DcInstance *instance);
|
|||||||
/* Connect to a running primary and send {"cmd":"open","conv":...}. */
|
/* Connect to a running primary and send {"cmd":"open","conv":...}. */
|
||||||
int dc_instance_notify(const char *dir, const char *conv);
|
int dc_instance_notify(const char *dir, const char *conv);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The tests' scratch directories. They used to name /tmp/opencode/<x>-XXXXXX
|
||||||
|
* -- a directory of the environment they were written in, not of the system:
|
||||||
|
* mkdtemp() returns NULL when its parent is missing, so every test that needs
|
||||||
|
* a directory failed on a machine that has no /tmp/opencode (measured
|
||||||
|
* 2026-11-22). This fills "template" with $TMPDIR (or /tmp) and a name
|
||||||
|
* unique enough for a test run and makes the directory; 0 on success.
|
||||||
|
*/
|
||||||
|
int dc_test_tmpdir(char *template, size_t len, const char *name);
|
||||||
|
|
||||||
#endif /* _DtChat_dc_internal_h */
|
#endif /* _DtChat_dc_internal_h */
|
||||||
@@ -446,3 +446,25 @@ fail:
|
|||||||
free(sock_path);
|
free(sock_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ tests */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A scratch directory for the tests: $TMPDIR (or /tmp) plus "name-XXXXXX".
|
||||||
|
* The tests used to write /tmp/opencode/<x>-XXXXXX, and mkdtemp() returns
|
||||||
|
* NULL when that parent does not exist -- every test that needs a directory
|
||||||
|
* then failed on a machine without /tmp/opencode (measured 2026-11-22).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dc_test_tmpdir(char *template, size_t len, const char *name)
|
||||||
|
{
|
||||||
|
const char *base = getenv("TMPDIR");
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (base == NULL || base[0] != '/')
|
||||||
|
base = "/tmp";
|
||||||
|
n = snprintf(template, len, "%s/dtchat-%s-XXXXXX", base, name);
|
||||||
|
if (n < 0 || (size_t)n >= len)
|
||||||
|
return -1;
|
||||||
|
return mkdtemp(template) != NULL ? 0 : -1;
|
||||||
|
}
|
||||||
@@ -197,14 +197,14 @@ test_names(void)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char tmp[] = "/tmp/opencode/dtchat-xfer-XXXXXX";
|
char tmp[64];
|
||||||
char dir[512];
|
char dir[512];
|
||||||
char src[600];
|
char src[600];
|
||||||
char src2[600];
|
char src2[600];
|
||||||
char sha_src[65];
|
char sha_src[65];
|
||||||
char sha_recv[65];
|
char sha_recv[65];
|
||||||
char base1[] = "/tmp/opencode/dtchat-xfer-a-XXXXXX";
|
char base1[64];
|
||||||
char base2[] = "/tmp/opencode/dtchat-xfer-b-XXXXXX";
|
char base2[64];
|
||||||
char id1[600], id2[600];
|
char id1[600], id2[600];
|
||||||
DcIdentity *a;
|
DcIdentity *a;
|
||||||
DcIdentity *b;
|
DcIdentity *b;
|
||||||
@@ -215,7 +215,7 @@ main(void)
|
|||||||
int steps = 0;
|
int steps = 0;
|
||||||
|
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
CHECK(mkdtemp(tmp) != NULL);
|
CHECK(dc_test_tmpdir(tmp, sizeof tmp, "xfer") == 0);
|
||||||
snprintf(dir, sizeof(dir), "%s/dl", tmp);
|
snprintf(dir, sizeof(dir), "%s/dl", tmp);
|
||||||
snprintf(t.dir, sizeof(t.dir), "%s", dir);
|
snprintf(t.dir, sizeof(t.dir), "%s", dir);
|
||||||
snprintf(src, sizeof(src), "%s/source.bin", tmp);
|
snprintf(src, sizeof(src), "%s/source.bin", tmp);
|
||||||
@@ -224,8 +224,8 @@ main(void)
|
|||||||
CHECK(dc_file_safe_name("../../escape.bin") != NULL);
|
CHECK(dc_file_safe_name("../../escape.bin") != NULL);
|
||||||
free(dc_file_safe_name("../../escape.bin"));
|
free(dc_file_safe_name("../../escape.bin"));
|
||||||
|
|
||||||
CHECK(mkdtemp(base1) != NULL);
|
CHECK(dc_test_tmpdir(base1, sizeof base1, "xfer-a") == 0);
|
||||||
CHECK(mkdtemp(base2) != NULL);
|
CHECK(dc_test_tmpdir(base2, sizeof base2, "xfer-b") == 0);
|
||||||
snprintf(id1, sizeof(id1), "%s/state", base1);
|
snprintf(id1, sizeof(id1), "%s/state", base1);
|
||||||
snprintf(id2, sizeof(id2), "%s/state", base2);
|
snprintf(id2, sizeof(id2), "%s/state", base2);
|
||||||
a = dc_identity_load_or_create(id1);
|
a = dc_identity_load_or_create(id1);
|
||||||
|
|||||||
@@ -64,18 +64,39 @@ use_catalog(const char *dir)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char tmp[] = "/tmp/opencode/dtchat-i18n-XXXXXX";
|
char tmp[64];
|
||||||
char de[1024], en[1024], cat[1200];
|
char de[1024], en[1024], cat[1200];
|
||||||
char *msg_de;
|
char *msg_de;
|
||||||
char *msg_en;
|
char *msg_en;
|
||||||
|
|
||||||
if (argc < 3) {
|
/* make check gives no arguments ($srcdir is exported by automake's
|
||||||
fprintf(stderr, "usage: %s <de.msg> <en.msg>\n", argv[0]);
|
* test driver); tools/mcde-tests.sh names the two files. Both the
|
||||||
return 2;
|
* in-tree build and a VPATH build find them this way. */
|
||||||
|
if (argc >= 3) {
|
||||||
|
msg_de = argv[1];
|
||||||
|
msg_en = argv[2];
|
||||||
|
} else {
|
||||||
|
const char *srcdir = getenv("srcdir");
|
||||||
|
static char bde[1024], ben[1024];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (srcdir == NULL || srcdir[0] == '\0')
|
||||||
|
srcdir = ".";
|
||||||
|
n = snprintf(bde, sizeof(bde), "%s/../../programs/"
|
||||||
|
"localized/de_DE.UTF-8/msg/dtchat.msg", srcdir);
|
||||||
|
if (n > 0 && (size_t)n < sizeof(bde) &&
|
||||||
|
access(bde, R_OK) == 0) {
|
||||||
|
msg_de = bde;
|
||||||
|
snprintf(ben, sizeof(ben), "%s/../../programs/"
|
||||||
|
"dtchat/dtchat.msg", srcdir);
|
||||||
|
msg_en = ben;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "usage: %s <de.msg> <en.msg>\n",
|
||||||
|
argv[0]);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msg_de = argv[1];
|
CHECK(dc_test_tmpdir(tmp, sizeof tmp, "i18n") == 0);
|
||||||
msg_en = argv[2];
|
|
||||||
CHECK(mkdtemp(tmp) != NULL);
|
|
||||||
snprintf(de, sizeof(de), "%s/de", tmp);
|
snprintf(de, sizeof(de), "%s/de", tmp);
|
||||||
snprintf(en, sizeof(en), "%s/en", tmp);
|
snprintf(en, sizeof(en), "%s/en", tmp);
|
||||||
CHECK(mkdir(de, 0700) == 0 || 1);
|
CHECK(mkdir(de, 0700) == 0 || 1);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ mode_is(const char *path, mode_t want)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char base[] = "/tmp/opencode/dtchat-id-XXXXXX";
|
char base[64];
|
||||||
char dir[512];
|
char dir[512];
|
||||||
char other[512];
|
char other[512];
|
||||||
char path[600];
|
char path[600];
|
||||||
@@ -44,7 +44,7 @@ main(void)
|
|||||||
char pin[128];
|
char pin[128];
|
||||||
char pub[128];
|
char pub[128];
|
||||||
|
|
||||||
CHECK(mkdtemp(base) != NULL);
|
CHECK(dc_test_tmpdir(base, sizeof base, "id") == 0);
|
||||||
snprintf(dir, sizeof(dir), "%s/state", base);
|
snprintf(dir, sizeof(dir), "%s/state", base);
|
||||||
snprintf(other, sizeof(other), "%s/other", base);
|
snprintf(other, sizeof(other), "%s/other", base);
|
||||||
snprintf(path, sizeof(path), "%s/identity.json", dir);
|
snprintf(path, sizeof(path), "%s/identity.json", dir);
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ raw_connect(const char *path)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char tmpdir[] = "/tmp/opencode/dtchat-inst-XXXXXX";
|
char tmpdir[64];
|
||||||
char dir[256];
|
char dir[256];
|
||||||
char run[512];
|
char run[512];
|
||||||
char lock[1024];
|
char lock[1024];
|
||||||
@@ -92,7 +92,7 @@ main(void)
|
|||||||
struct Opened opened;
|
struct Opened opened;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (mkdtemp(tmpdir) == NULL) {
|
if (dc_test_tmpdir(tmpdir, sizeof tmpdir, "inst") != 0) {
|
||||||
perror("mkdtemp");
|
perror("mkdtemp");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ static int
|
|||||||
mkidentity(char *base, size_t baselen, char *dir, size_t dirlen,
|
mkidentity(char *base, size_t baselen, char *dir, size_t dirlen,
|
||||||
DcIdentity **out)
|
DcIdentity **out)
|
||||||
{
|
{
|
||||||
snprintf(base, baselen, "/tmp/opencode/dtchat-local-XXXXXX");
|
if (dc_test_tmpdir(base, baselen, "local") != 0)
|
||||||
if (mkdtemp(base) == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
snprintf(dir, dirlen, "%s/state", base);
|
snprintf(dir, dirlen, "%s/state", base);
|
||||||
*out = dc_identity_load_or_create(dir);
|
*out = dc_identity_load_or_create(dir);
|
||||||
@@ -495,15 +494,15 @@ test_reconnect(void)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char base_c[] = "/tmp/opencode/dtchat-local-c-XXXXXX";
|
char base_c[64];
|
||||||
char base_o[] = "/tmp/opencode/dtchat-local-o-XXXXXX";
|
char base_o[64];
|
||||||
char dir_c[512], dir_o[512];
|
char dir_c[512], dir_o[512];
|
||||||
DcIdentity *client;
|
DcIdentity *client;
|
||||||
DcIdentity *other;
|
DcIdentity *other;
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
CHECK(mkdtemp(base_c) != NULL);
|
CHECK(dc_test_tmpdir(base_c, sizeof base_c, "local-c") == 0);
|
||||||
CHECK(mkdtemp(base_o) != NULL);
|
CHECK(dc_test_tmpdir(base_o, sizeof base_o, "local-o") == 0);
|
||||||
snprintf(dir_c, sizeof(dir_c), "%s/state", base_c);
|
snprintf(dir_c, sizeof(dir_c), "%s/state", base_c);
|
||||||
snprintf(dir_o, sizeof(dir_o), "%s/state", base_o);
|
snprintf(dir_o, sizeof(dir_o), "%s/state", base_o);
|
||||||
client = dc_identity_load_or_create(dir_c);
|
client = dc_identity_load_or_create(dir_c);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ static int fails;
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char tmp[] = "/tmp/opencode/dtchat-pair-XXXXXX";
|
char tmp[64];
|
||||||
char dir[512];
|
char dir[512];
|
||||||
DcPins *pins;
|
DcPins *pins;
|
||||||
DcPins *again;
|
DcPins *again;
|
||||||
@@ -56,7 +56,7 @@ main(void)
|
|||||||
CHECK(dc_pair_sas("nonsense", PIN_B) == NULL);
|
CHECK(dc_pair_sas("nonsense", PIN_B) == NULL);
|
||||||
CHECK(dc_pair_sas(PIN_A, NULL) == NULL);
|
CHECK(dc_pair_sas(PIN_A, NULL) == NULL);
|
||||||
|
|
||||||
CHECK(mkdtemp(tmp) != NULL);
|
CHECK(dc_test_tmpdir(tmp, sizeof tmp, "pair") == 0);
|
||||||
snprintf(dir, sizeof(dir), "%s/state", tmp);
|
snprintf(dir, sizeof(dir), "%s/state", tmp);
|
||||||
pins = dc_pins_load(dir);
|
pins = dc_pins_load(dir);
|
||||||
CHECK(pins != NULL);
|
CHECK(pins != NULL);
|
||||||
|
|||||||
@@ -273,12 +273,12 @@ test_default_dir(const char *tmpdir)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char tmpdir[] = "/tmp/opencode/dtchat-store-XXXXXX";
|
char tmpdir[64];
|
||||||
char dir[512];
|
char dir[512];
|
||||||
char path[512];
|
char path[512];
|
||||||
DcStore *store;
|
DcStore *store;
|
||||||
|
|
||||||
if (mkdtemp(tmpdir) == NULL) {
|
if (dc_test_tmpdir(tmpdir, sizeof tmpdir, "store") != 0) {
|
||||||
perror("mkdtemp");
|
perror("mkdtemp");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user