]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
tests: Turn sentence test into a shell script
authorDaiki Ueno <ueno@gnu.org>
Tue, 31 May 2016 07:05:24 +0000 (16:05 +0900)
committerDaiki Ueno <ueno@gnu.org>
Tue, 31 May 2016 10:09:53 +0000 (19:09 +0900)
For consistency with other tests.  Also it fixes a test failure when
built with --disable-shared, since LOG_COMPILER set to $(SHELL) doesn't
recognize binary executable.
* gettext-tools/tests/Makefile.am (TESTS): Rename 'sentence' to
'sentence-1'.
(check_PROGRAMS): Rename 'sentence' to 'sentence-1-prg'.
(sentence_1_prg_SOURCES): Rename from 'sentence_SOURCES'.
(sentence_1_prg_CPPFLAGS): Rename from 'sentence_CPPFLAGS'.
(sentence_1_prg_LDADD): Rename from 'sentence_LDADD'.
* gettext-tools/tests/sentence-1: New file.
* gettext-tools/tests/sentence-1-prg.c: Rename from sentence.c, move the
test data to sentence-1.
* gettext-tools/tests/.gitignore: Ignore sentence-1-prg.

gettext-tools/tests/.gitignore
gettext-tools/tests/Makefile.am
gettext-tools/tests/sentence-1 [new file with mode: 0755]
gettext-tools/tests/sentence-1-prg.c [new file with mode: 0644]
gettext-tools/tests/sentence.c [deleted file]

index 9e9b3b6358363529d9d7bd9d4f85e9831d22fad3..47ffa894a7e7f14a572d3ec6455fb37420868614 100644 (file)
@@ -17,7 +17,7 @@
 /gettext-7-prg
 /gettext-8-prg
 /gettextpo-1-prg
-/sentence
+/sentence-1-prg
 /testlocale
 /tstgettext
 /tstngettext
index 96aa354a238d3cd01f63b3e778c254f00a1cb775..6c9b0bfb1408c62e19ff6cb8e5b4a65995fa534a 100644 (file)
@@ -142,7 +142,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
        format-lua-1 format-lua-2 \
        format-javascript-1 format-javascript-2 \
        plural-1 plural-2 \
-       gettextpo-1 sentence \
+       gettextpo-1 sentence-1 \
        lang-c lang-c++ lang-objc lang-sh lang-bash lang-python-1 \
        lang-python-2 lang-clisp lang-elisp lang-librep lang-guile \
        lang-smalltalk lang-java lang-csharp lang-gawk lang-pascal \
@@ -216,7 +216,7 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
 LDADD = $(LDADD_@USE_INCLUDED_LIBINTL@) @INTL_MACOSX_LIBS@
 LDADD_yes = ../intl/libintl.la @LTLIBTHREAD@
 LDADD_no = ../intl/libgnuintl.la @LTLIBTHREAD@ @LTLIBINTL@
-check_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg sentence
+check_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg sentence-1-prg
 tstgettext_SOURCES = tstgettext.c setlocale.c
 tstgettext_CFLAGS = -DINSTALLDIR=\".\"
 tstgettext_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD)
@@ -260,9 +260,9 @@ gettextpo_1_prg_CPPFLAGS = \
 # Don't add more libraries here. This test must check whether libgettextpo is
 # self contained.
 gettextpo_1_prg_LDADD = ../libgettextpo/libgettextpo.la $(LDADD)
-sentence_SOURCES = sentence.c
-sentence_CPPFLAGS = $(AM_CPPFLAGS) -I../src -I$(top_srcdir)/src
-sentence_LDADD = ../src/libgettextsrc.la $(LDADD)
+sentence_1_prg_SOURCES = sentence-1-prg.c
+sentence_1_prg_CPPFLAGS = $(AM_CPPFLAGS) -I../src -I$(top_srcdir)/src
+sentence_1_prg_LDADD = ../src/libgettextsrc.la $(LDADD)
 
 # Clean up after Solaris cc.
 clean-local:
diff --git a/gettext-tools/tests/sentence-1 b/gettext-tools/tests/sentence-1
new file mode 100755 (executable)
index 0000000..ac19afe
--- /dev/null
@@ -0,0 +1,120 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test of sentence handling.
+
+cat > s1.in <<\EOF
+1
+This is a primary sentence
+
+1
+This is a primary sentence.
+
+1
+This is a primary sentence.x
+
+2
+This is a primary sentence.  This is a secondary sentence
+
+1
+This is a primary sentence.  This is a secondary sentence
+
+1
+This is a primary sentence.'  This is a secondary sentence
+
+3
+This is a primary sentence.  This is a secondary sentence
+
+2
+This is a primary sentence.'  This is a secondary sentence
+
+2
+This is a primary sentence.'x  This is a secondary sentence
+
+2
+This is a primary sentence.''x  This is a secondary sentence
+
+2
+This is a primary sentence.
+This is a secondary sentence
+
+2
+This is a primary sentence. 
+This is a secondary sentence
+
+2
+This is a primary sentence. 
+This is a secondary sentence
+
+2
+This is a primary sentence.    This is a secondary sentence
+
+2
+This is a primary sentence.'   This is a secondary sentence
+
+2
+This is a primary sentence.'
+This is a secondary sentence
+
+EOF
+
+cat > s1.ok <<EOF
+FFFD
+
+
+2E
+.
+
+FFFD
+
+
+2E
+.  This is a secondary sentence
+
+2E
+.  This is a secondary sentence
+
+2E
+.'  This is a secondary sentence
+
+FFFD
+
+
+2E
+.'  This is a secondary sentence
+
+FFFD
+
+
+FFFD
+
+
+2E
+.
+This is a secondary sentence
+
+2E
+. 
+This is a secondary sentence
+
+FFFD
+
+
+2E
+.      This is a secondary sentence
+
+2E
+.'     This is a secondary sentence
+
+2E
+.'
+This is a secondary sentence
+
+EOF
+
+../sentence-1-prg < s1.in > s1.out || exit 1
+
+: ${DIFF=diff}
+${DIFF} s1.ok s1.out || exit 1
+
+exit 0
diff --git a/gettext-tools/tests/sentence-1-prg.c b/gettext-tools/tests/sentence-1-prg.c
new file mode 100644 (file)
index 0000000..e3d3360
--- /dev/null
@@ -0,0 +1,65 @@
+/* Test of sentence handling.
+   Copyright (C) 2015-2016 Free Software Foundation, Inc.
+   Written by Daiki Ueno <ueno@gnu.org>, 2015.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "sentence.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main (int argc, char **argv)
+{
+  char buffer[1024];
+
+  while (1)
+    {
+      const char *result;
+      ucs4_t ending_char;
+      char *p;
+
+      if (!fgets (buffer, sizeof buffer, stdin))
+        break;
+
+      sentence_end_required_spaces = atoi (buffer);
+
+      memset (buffer, 0, sizeof buffer);
+      p = buffer;
+      while (1)
+        {
+          p = fgets (p, sizeof buffer - (buffer - p), stdin);
+          if (p == NULL)
+            break;
+          if (*p == '\n')
+            break;
+          p = strchr (p, '\n') + 1;
+        }
+      if (p == NULL)
+        break;
+
+      *(p - 1) = '\0';
+
+      result = sentence_end (buffer, &ending_char);
+      printf ("%X\n%s\n\n", ending_char, result);
+    }
+
+  return 0;
+}
diff --git a/gettext-tools/tests/sentence.c b/gettext-tools/tests/sentence.c
deleted file mode 100644 (file)
index f262bd3..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Test of sentence handling.
-   Copyright (C) 2015-2016 Free Software Foundation, Inc.
-   Written by Daiki Ueno <ueno@gnu.org>, 2015.
-
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program 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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include "sentence.h"
-
-#include <assert.h>
-#include <string.h>
-
-#define PRIMARY "This is a primary sentence"
-#define SECONDARY "This is a secondary sentence"
-
-#define SIZEOF(x) (sizeof (x) / sizeof (*x))
-
-struct data
-{
-  int required_spaces;
-  const char *input;
-
-  const char *expected_prefix;
-  ucs4_t expected_ending_char;
-};
-
-const struct data data[] =
-  {
-    { 1, PRIMARY, PRIMARY, 0xfffd },
-    { 1, PRIMARY ".", PRIMARY, '.' },
-    { 1, PRIMARY ".x", PRIMARY ".x", 0xfffd },
-    { 2, PRIMARY ".  " SECONDARY, PRIMARY, '.' },
-    { 1, PRIMARY ".  " SECONDARY, PRIMARY, '.' },
-    { 1, PRIMARY ".' " SECONDARY, PRIMARY, '.' },
-    { 3, PRIMARY ".  " SECONDARY, PRIMARY ".  " SECONDARY, 0xfffd },
-    { 2, PRIMARY ".'  " SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ".'x  " SECONDARY, PRIMARY ".'x  " SECONDARY, 0xfffd },
-    { 2, PRIMARY ".''x  " SECONDARY, PRIMARY ".''x  " SECONDARY, 0xfffd },
-    { 2, PRIMARY ".\n" SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ". \n" SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ".\xc2\xa0\n" SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ".\t" SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ".'\t" SECONDARY, PRIMARY, '.' },
-    { 2, PRIMARY ".'\n" SECONDARY, PRIMARY, '.' }
-  };
-
-static void
-check_sentence_end (const struct data *d)
-{
-  int saved_required_spaces = sentence_end_required_spaces;
-  const char *result;
-  ucs4_t ending_char;
-
-  sentence_end_required_spaces = d->required_spaces;
-  result = sentence_end (d->input, &ending_char);
-  sentence_end_required_spaces = saved_required_spaces;
-
-  assert (result == d->input + strlen (d->expected_prefix));
-  assert (ending_char == d->expected_ending_char);
-}
-
-int
-main (int argc, char **argv)
-{
-  int i;
-
-  for (i = 0; i < SIZEOF (data); i++)
-    check_sentence_end (&data[i]);
-
-  return 0;
-}