diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-05-18 17:46:13 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-05-19 18:42:34 -0700 |
commit | 46be5ac468db923bd3d19c55638b723aa760cd4e (patch) | |
tree | 44726156923b2243b946e11101242e543656de76 /src/fish_tests.cpp | |
parent | 30ea7cc3f8a5d56ad30dc749ea374363c15f312a (diff) |
make fish buildable on OS X Snow Leopard
I noticed that the `test_convert()` function was randomly failing when
run on OS X Snow Leopard. I tracked it down to the `mbrtowc()` function on
that OS being broken. Explicitly testing for UTF-8 prefixes that identify
a sequence longer than four bytes (which the Unicode standard made illegal
long ago) keeps us from having encoding errors on those OS's.
This also makes the errors reported by the `test_convert()` function actually
useful and readable.
Lastly, it makes it possible to build fish on OS X Snow Leopard.
Diffstat (limited to 'src/fish_tests.cpp')
-rw-r--r-- | src/fish_tests.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 7f1c0a7d..2457cee4 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -258,6 +258,18 @@ static void test_format(void) { do_test(!strcmp(buff1, buff2)); } +/// Helper to convert a narrow string to a sequence of hex digits. +static char *str2hex(const char *input) { + char *output = (char *)malloc(5 * strlen(input) + 1); + char *p = output; + for (; *input; input++) { + sprintf(p, "0x%02X ", (int)*input & 0xFF); + p += 5; + } + *p = '\0'; + return output; +} + /// Test wide/narrow conversion by creating random strings and verifying that the original string /// comes back thorugh double conversion. static void test_convert() { @@ -318,8 +330,13 @@ static void test_convert() { } if (strcmp(o, n)) { - err(L"Line %d - %d: Conversion cycle of string %s produced different string %s", - __LINE__, i, o, n); + char *o2 = str2hex(o); + char *n2 = str2hex(n); + err(L"Line %d - %d: Conversion cycle of string:\n%4d chars: %s\n" + L"produced different string:\n%4d chars: %s", + __LINE__, i, strlen(o), o2, strlen(n), n2); + free(o2); + free(n2); } free((void *)n); } @@ -3882,8 +3899,7 @@ int main(int argc, char **argv) { } } - setlocale(LC_ALL, ""); - // srand(time(0)); + srand(time(0)); configure_thread_assertions_for_testing(); program_name = L"(ignore)"; |