| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Requires perl-Test-Simple installation. |
| 4 |
use Test::Simple tests => 17; |
| 5 |
|
| 6 |
$suffix = ""; |
| 7 |
if (-e "../dos2unix.exe") { |
| 8 |
$suffix = ".exe"; |
| 9 |
} |
| 10 |
$DOS2UNIX = "../dos2unix" . $suffix; |
| 11 |
$MAC2UNIX = "../mac2unix" . $suffix; |
| 12 |
$UNIX2DOS = "../unix2dos" . $suffix; |
| 13 |
$UNIX2MAC = "../unix2mac" . $suffix; |
| 14 |
|
| 15 |
$ENV{'LC_ALL'} = 'C'; |
| 16 |
|
| 17 |
system("$DOS2UNIX -v -7 -n chardos.txt out_unix.txt; cmp out_unix.txt charu7.txt"); |
| 18 |
ok( $? == 0, '7bit'); |
| 19 |
|
| 20 |
system("$UNIX2DOS -v -7 -n utf8unxb.txt out_dos.txt charunix.txt out_d7.txt; cmp out_dos.txt utf8dos.txt"); |
| 21 |
ok( $? == 0, '7bit disabled for utf8 with BOM'); |
| 22 |
|
| 23 |
system("cmp out_d7.txt chard7.txt"); |
| 24 |
ok( $? == 0, '7bit enabled again, unix2dos'); |
| 25 |
|
| 26 |
system("$DOS2UNIX -v -n utf16len.txt out_bin.txt"); |
| 27 |
# file out_bin.txt may not exist. |
| 28 |
if (-e "out_bin.txt") { |
| 29 |
$exists = "1"; |
| 30 |
} else { |
| 31 |
$exists = "0"; |
| 32 |
} |
| 33 |
ok( $exists == 0, 'dos2unix skip binary file.' ); |
| 34 |
|
| 35 |
system("$UNIX2DOS -v -n utf16len.txt out_bin.txt"); |
| 36 |
# file out_bin.txt may not exist. |
| 37 |
if (-e "out_bin.txt") { |
| 38 |
$exists = "1"; |
| 39 |
} else { |
| 40 |
$exists = "0"; |
| 41 |
} |
| 42 |
ok( $exists == 0, 'unix2dos skip binary file.' ); |
| 43 |
|
| 44 |
system("$DOS2UNIX -v -n utf16len.txt out.txt"); |
| 45 |
$result = ($? >> 8); |
| 46 |
ok( $result == 0, 'Dos2unix returns zero on skipping binary input.' ); |
| 47 |
|
| 48 |
system("$UNIX2DOS -v -n utf16len.txt out.txt"); |
| 49 |
$result = ($? >> 8); |
| 50 |
ok( $result == 0, 'Unix2dos returns zero on skipping binary input.' ); |
| 51 |
|
| 52 |
system("$DOS2UNIX -v -f -n utf16len.txt out.txt"); |
| 53 |
$result = ($? >> 8); |
| 54 |
ok( $result == 0, 'Dos2unix returns zero on forced binary file conversion.' ); |
| 55 |
|
| 56 |
system("$UNIX2DOS -v -f -n utf16len.txt out.txt"); |
| 57 |
$result = ($? >> 8); |
| 58 |
ok( $result == 0, 'Unix2dos returns zero on forced binary file conversion.' ); |
| 59 |
|
| 60 |
system("$DOS2UNIX -v < utf16len.txt > out.txt"); |
| 61 |
$result = ($? >> 8); |
| 62 |
ok( $result == 1, 'Dos2unix stdio returns error on binary input.' ); |
| 63 |
|
| 64 |
system("$UNIX2DOS -v < utf16len.txt > out.txt"); |
| 65 |
$result = ($? >> 8); |
| 66 |
ok( $result == 1, 'Unix2dos stdio returns error on binary input.' ); |
| 67 |
|
| 68 |
system("rm -f out_forc.txt"); |
| 69 |
system("$DOS2UNIX -f -v -n utf16len.txt out_forc.txt"); |
| 70 |
# file out_bin.txt may not exist. |
| 71 |
if (-e "out_forc.txt") { |
| 72 |
$exists = "1"; |
| 73 |
} else { |
| 74 |
$exists = "0"; |
| 75 |
} |
| 76 |
ok( $exists == 1, 'dos2unix force binary file.' ); |
| 77 |
|
| 78 |
system("rm -f out_forc.txt"); |
| 79 |
system("$UNIX2DOS -f -v -n utf16len.txt out_forc.txt"); |
| 80 |
# file out_bin.txt may not exist. |
| 81 |
if (-e "out_forc.txt") { |
| 82 |
$exists = "1"; |
| 83 |
} else { |
| 84 |
$exists = "0"; |
| 85 |
} |
| 86 |
ok( $exists == 1, 'unix2dos force binary file.' ); |
| 87 |
|
| 88 |
system("$DOS2UNIX -v -f -n dos_bin.txt out_unix.txt; cmp out_unix.txt unix_bin.txt"); |
| 89 |
ok( $? == 0, 'Dos2unix, force ASCII file with binary symbols' ); |
| 90 |
|
| 91 |
system("$UNIX2DOS -v -f -n unix_bin.txt out_dos.txt; cmp out_dos.txt dos_bin.txt"); |
| 92 |
ok( $? == 0, 'Unix2dos, force ASCII file with binary symbols' ); |
| 93 |
|
| 94 |
system("$DOS2UNIX -i dos.txt unix.txt mac.txt mixed.txt utf16len.txt utf8unix.txt utf8dos.txt gb18030.txt > outinfo.txt"); |
| 95 |
system("$DOS2UNIX outinfo.txt; diff info.txt outinfo.txt"); |
| 96 |
ok( $? == 0, 'Option -i, --info'); |
| 97 |
|
| 98 |
system("$DOS2UNIX -ic0 dos*.txt | xargs -0 ls 2> err.txt > outinfo0.txt"); |
| 99 |
system("$DOS2UNIX outinfo0.txt; diff info0.txt outinfo0.txt"); |
| 100 |
ok( $? == 0, 'Option -ic0'); |