summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hood <cgull@glup.org>2017-03-20 10:49:16 -0400
committerJohn Hood <cgull@glup.org>2017-04-24 22:38:47 -0400
commit654f26991736f38bc952a7dd8dccf846bf1a6de5 (patch)
tree930a5748111b51c386ac67f937ae8dc185f9a914
parent0f0301b746e501190fd7107c1d1ce2da6ae40346 (diff)
Make tests detect UTF-8 locale with a helper executable
This uses the same utility function that mosh-client/mosh-server do. This resolves portability issues with the 'locale' command. This fixes OpenBSD 6.0 and probably Haiku builds.
-rw-r--r--src/tests/.gitignore1
-rw-r--r--src/tests/Makefile.am6
-rwxr-xr-xsrc/tests/e2e-test17
-rw-r--r--src/tests/e2e-test-subrs6
-rw-r--r--src/tests/is-utf8-locale.cc45
5 files changed, 62 insertions, 13 deletions
diff --git a/src/tests/.gitignore b/src/tests/.gitignore
index e1d9f60..536918b 100644
--- a/src/tests/.gitignore
+++ b/src/tests/.gitignore
@@ -4,6 +4,7 @@
/encrypt-decrypt
/nonce-incr
/inpty
+/is-utf8-locale
/*.d/
*.log
*.trs
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 45446ac..54f5172 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -35,7 +35,7 @@ displaytests = \
unicode-later-combining.test \
window-resize.test
-check_PROGRAMS = ocb-aes encrypt-decrypt base64 nonce-incr inpty
+check_PROGRAMS = ocb-aes encrypt-decrypt base64 nonce-incr inpty is-utf8-locale
TESTS = ocb-aes encrypt-decrypt base64 nonce-incr local.test $(displaytests)
XFAIL_TESTS = \
e2e-failure.test \
@@ -65,6 +65,10 @@ inpty_SOURCES = inpty.cc
inpty_CPPFLAGS = -I$(srcdir)/../util
inpty_LDADD = ../util/libmoshutil.a $(LIBUTIL)
+is_utf8_locale_SOURCES = is-utf8-locale.cc
+is_utf8_locale_CPPFLAGS = -I$(srcdir)/../util
+is_utf8_locale_LDADD = ../util/libmoshutil.a $(LIBUTIL)
+
clean-local: clean-local-check
.PHONY: clean-local-check
clean-local-check:
diff --git a/src/tests/e2e-test b/src/tests/e2e-test
index 6e5a4b5..7a8e6b7 100755
--- a/src/tests/e2e-test
+++ b/src/tests/e2e-test
@@ -108,10 +108,6 @@ mosh_server()
}
# main
-if ! set_locale; then
- test_error "e2e-test: no usable locale\n"
-fi
-
# Set up environment
if [ -z "$srcdir" ]; then
export srcdir=$PWD
@@ -137,10 +133,6 @@ case "$(basename "$0")" in
;;
esac
-if ! tmux_check; then
- test_skipped "tmux unavailable\n"
-fi
-
if [ $# -lt 2 ]; then
test_error "not enough args\n"
fi
@@ -153,6 +145,15 @@ test_args=$@
test_dir=$(basename "${test_name}").d
test_script="${test_name}"
+tests_dir=$(dirname "${test_name}")
+if ! set_locale "${tests_dir}"; then
+ test_error "e2e-test: no usable locale\n"
+fi
+
+if ! tmux_check; then
+ test_skipped "tmux unavailable\n"
+fi
+
rm -rf "${test_dir}"
mkdir "${test_dir}"
diff --git a/src/tests/e2e-test-subrs b/src/tests/e2e-test-subrs
index b85938d..b6c39d1 100644
--- a/src/tests/e2e-test-subrs
+++ b/src/tests/e2e-test-subrs
@@ -60,14 +60,12 @@ chr()
set_locale()
{
# Test for a usable locale.
- map=$(locale charmap 2>/dev/null)
- if [ "$map" = "utf-8" ] || [ "$map" = "UTF-8" ]; then
+ if ./is-utf8-locale 2> /dev/null; then
return 0
fi
# Attempt to find/set a usable locale.
for i in en_US.UTF-8 en_US.utf8 C.UTF-8; do
- map="$(env LANG=$i locale charmap 2>/dev/null)"
- if [ "$map" = "utf-8" ] || [ "$map" = "UTF-8" ]; then
+ if env LANG=$i ./is-utf8-locale 2> /dev/null; then
export LANG=$i LC_ALL=''
return 0
fi
diff --git a/src/tests/is-utf8-locale.cc b/src/tests/is-utf8-locale.cc
new file mode 100644
index 0000000..e439952
--- /dev/null
+++ b/src/tests/is-utf8-locale.cc
@@ -0,0 +1,45 @@
+/*
+ Mosh: the mobile shell
+ Copyright 2012 Keith Winstein
+
+ 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/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations including
+ the two.
+
+ You must obey the GNU General Public License in all respects for all
+ of the code used other than OpenSSL. If you modify file(s) with this
+ exception, you may extend this exception to your version of the
+ file(s), but you are not obligated to do so. If you do not wish to do
+ so, delete this exception statement from your version. If you delete
+ this exception statement from all source files in the program, then
+ also delete it here.
+*/
+
+#include <stdio.h>
+
+#include "locale_utils.h"
+
+int main( int argc __attribute__(( unused )), char **argv __attribute__(( unused )))
+{
+ set_native_locale();
+ if ( !is_utf8_locale() ) {
+ fprintf( stderr, "not a UTF-8 locale\n" );
+ return 1;
+ }
+ return 0;
+}