summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 16:01:27 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 16:01:28 +0900
commita43ffe7b214336b5ff551c8965d6fd16c63b13ed (patch)
treeb50d6960573c049b1bae74b6fdc2c53c2fdedf2f /test
parent2fb41ec277dc25c2a3988fc0b3fc8dde07d36062 (diff)
downloaddos2unix-a43ffe7b214336b5ff551c8965d6fd16c63b13ed.tar.gz
dos2unix-a43ffe7b214336b5ff551c8965d6fd16c63b13ed.tar.bz2
dos2unix-a43ffe7b214336b5ff551c8965d6fd16c63b13ed.zip
Imported Upstream version 7.3.5upstream/7.3.5
Change-Id: If401ea1da0876f720539b64ea208bc4e47e084fa Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile56
-rwxr-xr-xtest/bom.t (renamed from test/utf8.t)20
-rwxr-xr-xtest/chk_loc.sh8
-rw-r--r--test/dos 'txt.txt6
-rwxr-xr-xtest/gb18030.t20
-rw-r--r--test/info0.txt5
-rwxr-xr-xtest/misc.t15
-rwxr-xr-xtest/utf16.t15
-rwxr-xr-xtest/utf16_gb.t33
9 files changed, 124 insertions, 54 deletions
diff --git a/test/Makefile b/test/Makefile
index e2a55e9..6b262f2 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,4 +1,4 @@
-TESTS = ascii.t iso.t utf8.t misc.t
+TESTS = ascii.t iso.t misc.t bom.t
d2u_os=$(shell uname -s)
UCS = 1
@@ -6,14 +6,14 @@ UCS = 1
# Checking WIN32 version in MSYS shell.
ifeq ($(findstring MINGW,$(d2u_os)),MINGW)
TESTS += gb18030.t
-endif
-
+else
ifneq ($(findstring FreeBSD,$(d2u_os)),FreeBSD)
# Unix/Linux/Cygwin. Check if zh_CN.gb18030 locale is supported.
ifeq ($(shell ./chk_loc.sh zh_CN.gb18030),yes)
TESTS += gb18030.t
endif
endif
+endif
# DOS and Windows version do not support symlinks like the Unix version.
ifeq ($(DJGPP),)
@@ -23,43 +23,71 @@ endif
endif
ifeq ($(UCS),1)
-TESTS +=utf16.t
+
+# Check for UTF-8 locale. Try C.UTF-8 and en_US.UTF-8.
+ifeq ($(shell ./chk_loc.sh X.UTF-8),yes)
+TESTS += utf16.t
+export D2U_UTF8_LOCALE = C.UTF-8
+else
+ifeq ($(shell ./chk_loc.sh en_US.UTF-8),yes)
+TESTS += utf16.t
+export D2U_UTF8_LOCALE = en_US.UTF-8
+endif
endif
+# Checking WIN32 version in MSYS shell.
+ifeq ($(findstring MINGW,$(d2u_os)),MINGW)
+TESTS += utf16_gb.t
+else
+ifneq ($(findstring FreeBSD,$(d2u_os)),FreeBSD)
+# Unix/Linux/Cygwin. Check if zh_CN.gb18030 locale is supported.
+ifeq ($(shell ./chk_loc.sh zh_CN.gb18030),yes)
+TESTS += utf16_gb.t
+endif
+endif
+endif
+
+endif
+
+PROVE_OPT ?= --nocolor
all: test
check: test
test:
- prove -v $(TESTS)
+ prove -v $(PROVE_OPT) $(TESTS)
ascii:
- prove -v $@.t
+ prove -v $(PROVE_OPT) $@.t
iso:
- prove -v $@.t
+ prove -v $(PROVE_OPT) $@.t
misc:
- prove -v $@.t
+ prove -v $(PROVE_OPT) $@.t
-utf8:
- prove -v $@.t
+bom:
+ prove -v $(PROVE_OPT) $@.t
utf16:
- prove -v $@.t
+ @echo "D2U_UTF8_LOCALE=$(D2U_UTF8_LOCALE)"
+ prove -v $(PROVE_OPT) $@.t
gb18030:
- prove -v $@.t
+ prove -v $(PROVE_OPT) $@.t
+
+utf16_gb:
+ prove -v $(PROVE_OPT) $@.t
symlink:
- prove -v $@.t
+ prove -v $(PROVE_OPT) $@.t
wcstombs:
$(CC) -Wall -Wextra wcstombs_test.c -o wcstombs_test
@echo "====> test wcstombs() UTF-8"
- LC_ALL=en_US.UTF-8 ./wcstombs_test
+ LC_ALL=.UTF-8 ./wcstombs_test
@echo "====> test wcstombs() GB18030"
LC_ALL=zh_CN.GB18030 ./wcstombs_test
diff --git a/test/utf8.t b/test/bom.t
index e7afd84..0361971 100755
--- a/test/utf8.t
+++ b/test/bom.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Requires perl-Test-Simple installation.
-use Test::Simple tests => 6;
+use Test::Simple tests => 8;
$suffix = "";
if (-e "../dos2unix.exe") {
@@ -12,24 +12,28 @@ $MAC2UNIX = "../mac2unix" . $suffix;
$UNIX2DOS = "../unix2dos" . $suffix;
$UNIX2MAC = "../unix2mac" . $suffix;
-$ENV{'LC_ALL'} = 'en_US.UTF-8';
+$ENV{'LC_ALL'} = 'C';
system("$DOS2UNIX -v -n dos_bom.txt out_unix.txt; cmp out_unix.txt unix.txt");
-ok( $? == 0, 'dos2unix removes BOM' );
+ok( $? == 0, 'dos2unix removes UTF-8 BOM' );
system("$DOS2UNIX -v -b -n dos_bom.txt out_unix.txt; cmp out_unix.txt unix_bom.txt");
-ok( $? == 0, 'dos2unix -b keeps BOM' );
+ok( $? == 0, 'dos2unix -b keeps UTF-8 BOM' );
system("$DOS2UNIX -v -m -n dos.txt out_unix.txt; cmp out_unix.txt unix_bom.txt");
-ok( $? == 0, 'dos2unix -m adds BOM' );
+ok( $? == 0, 'dos2unix -m adds UTF-8 BOM' );
system("$UNIX2DOS -v -n unix_bom.txt out_dos.txt; cmp out_dos.txt dos_bom.txt");
-ok( $? == 0, 'unix2dos keeps BOM' );
+ok( $? == 0, 'unix2dos keeps UTF-8 BOM' );
system("$UNIX2DOS -v -r -n unix_bom.txt out_dos.txt; cmp out_dos.txt dos.txt");
-ok( $? == 0, 'unix2dos -r removes BOM' );
+ok( $? == 0, 'unix2dos -r removes UTF-8 BOM' );
system("$UNIX2DOS -v -m -n unix.txt out_dos.txt; cmp out_dos.txt dos_bom.txt");
-ok( $? == 0, 'unix2dos -m adds BOM' );
+ok( $? == 0, 'unix2dos -m adds UTF-8 BOM' );
+system("$DOS2UNIX -v -b -n dos_gb.txt out_unix.txt; cmp out_unix.txt unix_gb.txt");
+ok( $? == 0, 'dos2unix -b keeps GB18030 BOM in none-GB18030 locale' );
+system("$UNIX2DOS -v -n unix_gb.txt out_dos.txt; cmp out_dos.txt dos_gb.txt");
+ok( $? == 0, 'unix2dos keeps GB18030 BOM in none-GB18030 locale' );
diff --git a/test/chk_loc.sh b/test/chk_loc.sh
index 68b82b3..a210d7d 100755
--- a/test/chk_loc.sh
+++ b/test/chk_loc.sh
@@ -1,8 +1,14 @@
#!/bin/sh
+if [ ! "$1" ]; then
+ echo "ERROR argument missing." >&2
+ echo "Usage: chk_loc.sh <locale name>" >&2
+ exit 1
+fi
+
LOC=`echo $1 | sed 's/-//g'`
-locale -a | sed 's/-//g' | grep -i "${LOC}" 2>&1 > /dev/null
+locale -a | sed 's/-//g' | grep -i "^${LOC}$" 2>&1 > /dev/null
if [ "$?" = "0" ]
then
diff --git a/test/dos 'txt.txt b/test/dos 'txt.txt
new file mode 100644
index 0000000..fc8b4db
--- /dev/null
+++ b/test/dos 'txt.txt
@@ -0,0 +1,6 @@
+hello
+world
+
+take
+a
+break
diff --git a/test/gb18030.t b/test/gb18030.t
index 078e7df..0c6ee94 100755
--- a/test/gb18030.t
+++ b/test/gb18030.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Requires perl-Test-Simple installation.
-use Test::Simple tests => 12;
+use Test::Simple tests => 7;
$suffix = "";
if (-e "../dos2unix.exe") {
@@ -41,23 +41,5 @@ ok( $? == 0, 'unix2dos -r removes GB18030 BOM' );
system("$UNIX2DOS $GB_OPT -v -m -n unix.txt out_dos.txt; cmp out_dos.txt dos_gb.txt");
ok( $? == 0, 'unix2dos -m adds GB18030 BOM' );
-system("$DOS2UNIX $GB_OPT -v -n utf16le.txt out_unix.txt; cmp out_unix.txt gb18030u.txt");
-ok( $? == 0, 'dos2unix convert DOS UTF-16LE to Unix GB18030' );
-
-system("$DOS2UNIX $GB_OPT -b -v -n utf16le.txt out_unix.txt; cmp out_unix.txt gb18030b.txt");
-ok( $? == 0, 'dos2unix convert DOS UTF-16LE to Unix GB18030, keep BOM' );
-
-system("$UNIX2DOS $GB_OPT -v -n utf16be.txt out_dos.txt; cmp out_dos.txt gb18030.txt");
-ok( $? == 0, 'unix2dos convert DOS UTF-16BE to DOS GB18030, keep BOM' );
-
system("$DOS2UNIX $GB_OPT -u -v -m -n dos.txt out_unix.txt; cmp out_unix.txt unix_gb.txt");
ok( $? == 0, 'dos2unix with option -u adds GB18030 BOM to non UTF-16 file' );
-
-$ENV{'LC_ALL'} = 'en_US.UTF-8';
-
-system("$DOS2UNIX -v -b -n dos_gb.txt out_unix.txt; cmp out_unix.txt unix_gb.txt");
-ok( $? == 0, 'dos2unix -b keeps GB18030 BOM in UTF-8 locale' );
-
-system("$UNIX2DOS -v -n unix_gb.txt out_dos.txt; cmp out_dos.txt dos_gb.txt");
-ok( $? == 0, 'unix2dos keeps GB18030 BOM in UTF-8 locale' );
-
diff --git a/test/info0.txt b/test/info0.txt
new file mode 100644
index 0000000..49b6b72
--- /dev/null
+++ b/test/info0.txt
@@ -0,0 +1,5 @@
+dos 'txt.txt
+dos.txt
+dos_bom.txt
+dos_dbl.txt
+dos_gb.txt
diff --git a/test/misc.t b/test/misc.t
index 0888e07..d0163d4 100755
--- a/test/misc.t
+++ b/test/misc.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Requires perl-Test-Simple installation.
-use Test::Simple tests => 13;
+use Test::Simple tests => 15;
$suffix = "";
if (-e "../dos2unix.exe") {
@@ -12,11 +12,17 @@ $MAC2UNIX = "../mac2unix" . $suffix;
$UNIX2DOS = "../unix2dos" . $suffix;
$UNIX2MAC = "../unix2mac" . $suffix;
-$ENV{'LC_ALL'} = 'en_US.UTF-8';
+$ENV{'LC_ALL'} = 'C';
system("$DOS2UNIX -v -7 -n chardos.txt out_unix.txt; cmp out_unix.txt charu7.txt");
ok( $? == 0, '7bit');
+system("$UNIX2DOS -v -7 -n utf8unxb.txt out_dos.txt charunix.txt out_d7.txt; cmp out_dos.txt utf8dos.txt");
+ok( $? == 0, '7bit disabled for utf8 with BOM');
+
+system("cmp out_d7.txt chard7.txt");
+ok( $? == 0, '7bit enabled again, unix2dos');
+
system("$DOS2UNIX -v < dos.txt > out_unix.txt; cmp out_unix.txt unix.txt");
ok( $? == 0, 'DOS to Unix conversion, stdin/out' );
@@ -79,5 +85,6 @@ system("$DOS2UNIX -i dos.txt unix.txt mac.txt mixed.txt utf16len.txt utf8unix.tx
system("$DOS2UNIX outinfo.txt; diff info.txt outinfo.txt");
ok( $? == 0, 'Option -i, --info');
-system("$DOS2UNIX -v -n gb18030.txt out_unix.txt; cmp out_unix.txt gb18030u.txt");
-ok( $? == 0, 'Remove GB18030 BOM');
+system("$DOS2UNIX -ic0 dos*.txt | xargs -0 ls 2> err.txt > outinfo0.txt");
+system("$DOS2UNIX outinfo0.txt; diff info0.txt outinfo0.txt");
+ok( $? == 0, 'Option -ic0');
diff --git a/test/utf16.t b/test/utf16.t
index aaaf6a6..34e997d 100755
--- a/test/utf16.t
+++ b/test/utf16.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# Requires perl-Test-Simple installation.
-use Test::Simple tests => 34;
+use Test::Simple tests => 32;
$suffix = "";
if (-e "../dos2unix.exe") {
@@ -21,7 +21,12 @@ $MAC2UNIX = "../mac2unix" . $suffix;
$UNIX2DOS = "../unix2dos" . $suffix;
$UNIX2MAC = "../unix2mac" . $suffix;
-$ENV{'LC_ALL'} = 'en_US.UTF-8';
+if (defined $ENV{'D2U_UTF8_LOCALE'}) {
+ $ENV{'LC_ALL'} = $ENV{'D2U_UTF8_LOCALE'};
+} else {
+ print "error: Environment variable D2U_UTF8_LOCALE is not set.";
+ exit 1;
+}
system("$DOS2UNIX -v -n utf16le.txt out_unix.txt; cmp out_unix.txt utf8unix.txt");
ok( $? == 0, 'DOS UTF-16LE to Unix UTF-8' );
@@ -99,12 +104,6 @@ ok( $? == 0, '7bit disabled for utf16');
system("cmp out_u7.txt charu7.txt");
ok( $? == 0, '7bit enabled again, dos2unix');
-system("$UNIX2DOS -v -7 -n utf8unxb.txt out_dos.txt charunix.txt out_d7.txt; cmp out_dos.txt utf8dos.txt");
-ok( $? == 0, '7bit disabled for utf8 with BOM');
-
-system("cmp out_d7.txt chard7.txt");
-ok( $? == 0, '7bit enabled again, unix2dos');
-
system("$DOS2UNIX -i dos.txt unix.txt mac.txt mixed.txt utf16le.txt utf16be.txt utf16len.txt utf8unix.txt utf8dos.txt gb18030.txt > outinfo.txt");
system("$DOS2UNIX outinfo.txt; diff info_ucs.txt outinfo.txt");
ok( $? == 0, 'Option -i, --info');
diff --git a/test/utf16_gb.t b/test/utf16_gb.t
new file mode 100755
index 0000000..6887172
--- /dev/null
+++ b/test/utf16_gb.t
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+# Requires perl-Test-Simple installation.
+use Test::Simple tests => 3;
+
+$suffix = "";
+if (-e "../dos2unix.exe") {
+ $suffix = ".exe";
+}
+$DOS2UNIX = "../dos2unix" . $suffix;
+$MAC2UNIX = "../mac2unix" . $suffix;
+$UNIX2DOS = "../unix2dos" . $suffix;
+$UNIX2MAC = "../unix2mac" . $suffix;
+
+if ($ENV{'MSYSTEM'} =~ /^MINGW/)
+{
+ $GB_OPT = '-gb';
+}
+else
+{
+ $GB_OPT = '';
+ $ENV{'LC_ALL'} = 'zh_CN.GB18030';
+}
+
+
+system("$DOS2UNIX $GB_OPT -v -n utf16le.txt out_unix.txt; cmp out_unix.txt gb18030u.txt");
+ok( $? == 0, 'dos2unix convert DOS UTF-16LE to Unix GB18030' );
+
+system("$DOS2UNIX $GB_OPT -b -v -n utf16le.txt out_unix.txt; cmp out_unix.txt gb18030b.txt");
+ok( $? == 0, 'dos2unix convert DOS UTF-16LE to Unix GB18030, keep BOM' );
+
+system("$UNIX2DOS $GB_OPT -v -n utf16be.txt out_dos.txt; cmp out_dos.txt gb18030.txt");
+ok( $? == 0, 'unix2dos convert DOS UTF-16BE to DOS GB18030, keep BOM' );