regex-tests: skip UTF-8 test on mingw
[gnulib.git] / tests / test-regex.c
index 6829035..5a94c14 100644 (file)
@@ -26,6 +26,8 @@
 # include <signal.h>
 #endif
 
+#include "localcharset.h"
+
 int
 main (void)
 {
@@ -65,25 +67,30 @@ main (void)
           result |= 1;
       }
 
-      {
-        /* This test is from glibc bug 15078.
-           The test case is from Andreas Schwab in
-           <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>.
-           */
-        static char const pat[] = "[^x]x";
-        static char const data[] =
-          "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80"
-          "\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax";
-        re_set_syntax (0);
-        memset (&regex, 0, sizeof regex);
-        s = re_compile_pattern (pat, sizeof pat - 1, &regex);
-        if (s)
-          result |= 1;
-        else if (re_search (&regex, data, sizeof data - 1,
-                            0, sizeof data - 1, 0)
-                 != 21)
-          result |= 1;
-      }
+      /* Check whether it's really a UTF-8 locale.
+         On mingw, the setlocale call succeeds but returns
+         "English_United States.1252", with locale_charset() returning
+         "CP1252".  */
+      if (strcmp (locale_charset (), "UTF-8") == 0)
+        {
+          /* This test is from glibc bug 15078.
+             The test case is from Andreas Schwab in
+             <http://www.sourceware.org/ml/libc-alpha/2013-01/msg00967.html>.
+          */
+          static char const pat[] = "[^x]x";
+          static char const data[] =
+            "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80"
+            "\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax";
+          re_set_syntax (0);
+          memset (&regex, 0, sizeof regex);
+          s = re_compile_pattern (pat, sizeof pat - 1, &regex);
+          if (s)
+            result |= 1;
+          else if (re_search (&regex, data, sizeof data - 1,
+                              0, sizeof data - 1, 0)
+                   != 21)
+            result |= 1;
+        }
 
       if (! setlocale (LC_ALL, "C"))
         return 1;