diff options
author | Max Bolingbroke <batterseapower@hotmail.com> | 2011-05-14 22:49:27 +0100 |
---|---|---|
committer | Max Bolingbroke <batterseapower@hotmail.com> | 2011-05-14 22:49:27 +0100 |
commit | 9b48454faf65a60071b7c53b13c32d9165033da1 (patch) | |
tree | a15da1cadd6f7caa2bfc5c582417d070f81605db /testsuite/tests/ghc-regress/lib | |
parent | d248787899fd5efb2f7085cd69b0354f5d6f23bf (diff) | |
download | haskell-9b48454faf65a60071b7c53b13c32d9165033da1.tar.gz |
Tests for the PEP383 functionality and bugs it fixes
Diffstat (limited to 'testsuite/tests/ghc-regress/lib')
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/3307.hs | 38 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/3307.stdout | 4 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/4855.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/4855.stderr | 1 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/Makefile | 26 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/all.T | 7 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/decodingerror001.stdout | 10 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/encoding002.hs | 67 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/encoding002.stdout | 61 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/encodingerror001.stdout | 36 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/environment001.hs | 16 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/IO/environment001.stdout | 6 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/should_run/4006.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/should_run/4006.stdout | 2 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/should_run/all.T | 4 | ||||
-rw-r--r-- | testsuite/tests/ghc-regress/lib/should_run/cstring001.hs | 18 |
16 files changed, 277 insertions, 30 deletions
diff --git a/testsuite/tests/ghc-regress/lib/IO/3307.hs b/testsuite/tests/ghc-regress/lib/IO/3307.hs new file mode 100644 index 0000000000..a39bfedf48 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/3307.hs @@ -0,0 +1,38 @@ +import Control.Exception + +import System.Directory +import System.Environment +import System.IO + +import Data.Char +import Data.List + +import GHC.IO.Encoding + +main = do + -- 1) A file name arriving via an argument + [file] <- getArgs + readFile file >>= putStr + + -- 2) A file name arriving via getDirectoryContents + [file] <- fmap (filter ("chinese-file-" `isPrefixOf`)) $ getDirectoryContents "." + readFile file >>= putStr + + -- 3) A file name occurring literally in the program + -- This will only work if we are in the UTF-8 locale since the file is created + -- on disk with a UTF-8 file name. + readFile "chinese-file-小说" >>= putStr + + -- 4) A file name arriving via another file. + -- In this case we have to override the default encoding + -- so we get surrogate bytes for non-decodable namse. + (readFileAs fileSystemEncoding "chinese-name" >>= (readFile . dropTrailingSpace)) >>= putStr + +readFileAs :: TextEncoding -> FilePath -> IO String +readFileAs enc fp = do + h <- openFile fp ReadMode + hSetEncoding h enc + hGetContents h + +dropTrailingSpace :: String -> String +dropTrailingSpace = reverse . dropWhile (not . isAlphaNum) . reverse diff --git a/testsuite/tests/ghc-regress/lib/IO/3307.stdout b/testsuite/tests/ghc-regress/lib/IO/3307.stdout new file mode 100644 index 0000000000..f807e104b7 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/3307.stdout @@ -0,0 +1,4 @@ +Ni hao +Ni hao +Ni hao +Ni hao diff --git a/testsuite/tests/ghc-regress/lib/IO/4855.hs b/testsuite/tests/ghc-regress/lib/IO/4855.hs new file mode 100644 index 0000000000..fa862aaf14 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/4855.hs @@ -0,0 +1,3 @@ +import Debug.Trace + +main = trace "我爱我的电脑" $ return ()
\ No newline at end of file diff --git a/testsuite/tests/ghc-regress/lib/IO/4855.stderr b/testsuite/tests/ghc-regress/lib/IO/4855.stderr new file mode 100644 index 0000000000..558550e229 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/4855.stderr @@ -0,0 +1 @@ +我爱我的电脑 diff --git a/testsuite/tests/ghc-regress/lib/IO/Makefile b/testsuite/tests/ghc-regress/lib/IO/Makefile index 0ad81226e1..e433ad73f8 100644 --- a/testsuite/tests/ghc-regress/lib/IO/Makefile +++ b/testsuite/tests/ghc-regress/lib/IO/Makefile @@ -12,25 +12,37 @@ test.concio001.thr: # NB. utf8-test should *not* have a final newline. The last char should be 'X'. utf16-test: utf8-test - iconv -f UTF8 -t UTF16 <utf8-test >utf16-test + iconv -f UTF-8 -t UTF-16 <utf8-test >utf16-test utf16le-test: utf8-test - iconv -f UTF8 -t UTF16LE <utf8-test >utf16le-test + iconv -f UTF-8 -t UTF-16LE <utf8-test >utf16le-test utf16be-test: utf8-test - iconv -f UTF8 -t UTF16BE <utf8-test >utf16be-test + iconv -f UTF-8 -t UTF-16BE <utf8-test >utf16be-test utf32-test: utf8-test - iconv -f UTF8 -t UTF32 <utf8-test >utf32-test + iconv -f UTF-8 -t UTF-32 <utf8-test >utf32-test utf32le-test: utf8-test - iconv -f UTF8 -t UTF32LE <utf8-test >utf32le-test + iconv -f UTF-8 -t UTF-32LE <utf8-test >utf32le-test utf32be-test: utf8-test - iconv -f UTF8 -t UTF32BE <utf8-test >utf32be-test + iconv -f UTF-8 -t UTF-32BE <utf8-test >utf32be-test utf8-bom-test: utf16-test - iconv -f UTF16LE -t UTF8 <utf16-test >utf8-bom-test + iconv -f UTF-16LE -t UTF-8 <utf16-test >utf8-bom-test hSetEncoding001.in : latin1 utf8-test utf16le-test utf16be-test utf16-test utf32le-test utf32be-test utf32-test utf8-bom-test cat >$@ latin1 utf8-test utf16le-test utf16be-test utf16-test utf32-test utf32le-test utf32be-test utf8-bom-test + +environment001-test: + @"$(TEST_HC)" --make -fforce-recomp -v0 environment001.hs -o environment001 + @(sleep 1; echo x) | GHC_TEST=马克斯 ./environment001 说 + +3307-test: + @"$(TEST_HC)" --make -fforce-recomp -v0 3307.hs -o 3307 + echo Ni hao > chinese-file-小说 + echo chinese-file-小说 > chinese-name + # Try a UTF-8 locale. I would test another one (like Big5) but GHC + # developers probably won't have it on their machines: + @(sleep 1; echo x) | LC_ALL=en_US.UTF-8 ./3307 chinese-file-小说 diff --git a/testsuite/tests/ghc-regress/lib/IO/all.T b/testsuite/tests/ghc-regress/lib/IO/all.T index 140bc2a48a..d60446fefb 100644 --- a/testsuite/tests/ghc-regress/lib/IO/all.T +++ b/testsuite/tests/ghc-regress/lib/IO/all.T @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- def expect_fail_if_windows(opts): f = if_platform('i386-unknown-mingw32', expect_fail); @@ -117,6 +118,8 @@ test('concio001.thr', skip, run_command, ['$MAKE -s --no-print-directory test.co test('concio002', reqlib('process'), compile_and_run, ['']) test('2122', extra_clean(['2122-test']), compile_and_run, ['']) +test('3307', extra_clean(['chinese-file-小说', 'chinese-name']), run_command, ['$MAKE -s --no-print-directory 3307-test']) +test('4855', normal, compile_and_run, ['']) test('hSetEncoding001',extra_run_opts('hSetEncoding001.in'), compile_and_run, ['']) test('decodingerror001',normal, compile_and_run, ['']) @@ -150,6 +153,10 @@ test('encoding001', 'encoding001.utf8.utf32le']), compile_and_run, ['']) +test('encoding002', normal, compile_and_run, ['']) + +test('environment001', extra_clean(['environment001']), run_command, ['$MAKE -s --no-print-directory environment001-test']) + test('newline001', extra_clean(['newline001.out']), compile_and_run, ['']) test('openTempFile001', normal, compile_and_run, ['']) diff --git a/testsuite/tests/ghc-regress/lib/IO/decodingerror001.stdout b/testsuite/tests/ghc-regress/lib/IO/decodingerror001.stdout index 887a8ba0b3..21e5208c79 100644 --- a/testsuite/tests/ghc-regress/lib/IO/decodingerror001.stdout +++ b/testsuite/tests/ghc-regress/lib/IO/decodingerror001.stdout @@ -1,8 +1,8 @@ -UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid UTF-8 byte sequence) -UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid UTF-8 byte sequence) -UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid UTF-8 byte sequence) -UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid UTF-8 byte sequence) -UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid UTF-8 byte sequence) +UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid byte sequence) +UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid byte sequence) +UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid byte sequence) +UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid byte sequence) +UTF8 error:Left decodingerror001.in1: hGetChar: invalid argument (invalid byte sequence) UTF8 incomplete sequence at end:Left decodingerror001.in2: hGetChar: invalid argument (invalid byte sequence for this encoding) UTF8 incomplete sequence at end:Left decodingerror001.in2: hGetChar: invalid argument (invalid byte sequence for this encoding) UTF8 incomplete sequence at end:Left decodingerror001.in2: hGetChar: invalid argument (invalid byte sequence for this encoding) diff --git a/testsuite/tests/ghc-regress/lib/IO/encoding002.hs b/testsuite/tests/ghc-regress/lib/IO/encoding002.hs new file mode 100644 index 0000000000..7c6f81a72a --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/encoding002.hs @@ -0,0 +1,67 @@ +import Control.Monad + +import System.IO +import Control.Exception + +import Foreign.Marshal.Array +import Foreign.Ptr + +import GHC.Foreign +import GHC.IO.Encoding (TextEncoding, mkTextEncoding) + +import Data.Char +import Data.Word + +import Prelude hiding (catch) + + +decode :: TextEncoding -> [Word8] -> IO String +decode enc xs = withArrayLen xs (\sz p -> peekCStringLen enc (castPtr p, sz)) `catch` \e -> return (show (e :: IOException)) + +encode :: TextEncoding -> String -> IO [Word8] +encode enc cs = withCStringLen enc cs (\(p, sz) -> peekArray sz (castPtr p)) `catch` \e -> return (const [] (e :: IOException)) + +asc :: Char -> Word8 +asc = fromIntegral . ord + +families = [ ([asc 'H', asc 'i', 0xED, 0xB2, 0x80, asc '!'], + ["UTF-8", "UTF-8//IGNORE", "UTF-8//TRANSLIT", "UTF-8//SURROGATE"]) + , ([asc 'H', 0, asc 'i', 0, 0xFF, 0xDF, 0xFF, 0xDF, asc '!', 0], + ["UTF-16LE", "UTF-16LE//IGNORE", "UTF-16LE//TRANSLIT", "UTF-16LE//SURROGATE"]) + , ([0, asc 'H', 0, asc 'i', 0xDF, 0xFF, 0xDF, 0xFF, 0, asc '!'], + ["UTF-16BE", "UTF-16BE//IGNORE", "UTF-16BE//TRANSLIT", "UTF-16BE//SURROGATE"]) + , ([asc 'H', 0, 0, 0, asc 'i', 0, 0, 0, 0xED, 0xB2, 0x80, 0, asc '!', 0, 0, 0], + ["UTF-32LE", "UTF-32LE//IGNORE", "UTF-32LE//TRANSLIT", "UTF-32LE//SURROGATE"]) + , ([0, 0, 0, asc 'H', 0, 0, 0, asc 'i', 0, 0x80, 0xB2, 0xED, 0, 0, 0, asc '!'], + ["UTF-32BE", "UTF-32BE//IGNORE", "UTF-32BE//TRANSLIT", "UTF-32BE//SURROGATE"]) + ] + +main = do + surrogate_enc <- mkTextEncoding "UTF-8//SURROGATE" + + -- Test that invalid input is correctly roundtripped as surrogates + -- This only works for the UTF-8 UTF since it is the only UTF which + -- is an ASCII superset. + putStrLn $ "== UTF-8: roundtripping" + let invalid_bytes = [asc 'H', asc 'i', 0xED, 0xB2, 0x80, asc '!'] + surrogates <- decode surrogate_enc invalid_bytes + invalid_bytes' <- encode surrogate_enc surrogates + print invalid_bytes + print surrogates + print invalid_bytes' + print (invalid_bytes == invalid_bytes') + putStrLn "" + + forM families $ \(invalid_bytes, enc_names) -> do + encs <- mapM mkTextEncoding enc_names + let name = head enc_names + + -- How we deal with decoding errors in the various modes: + putStrLn $ "== " ++ name ++ ": decoding" + forM encs $ \enc -> decode enc invalid_bytes >>= print + + -- How about encoding errors, particularly those from embedded surrogates? + putStrLn $ "== " ++ name ++ ": encoding" + forM encs $ \enc -> encode enc "Hi\xDC80!" >>= print + + putStrLn "" diff --git a/testsuite/tests/ghc-regress/lib/IO/encoding002.stdout b/testsuite/tests/ghc-regress/lib/IO/encoding002.stdout new file mode 100644 index 0000000000..0cc885baa0 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/encoding002.stdout @@ -0,0 +1,61 @@ +== UTF-8: roundtripping +[72,105,237,178,128,33] +"Hi\56557\56498\56448!" +[72,105,237,178,128,33] +True + +== UTF-8: decoding +"recoverDecode: invalid argument (invalid byte sequence)" +"Hi!" +"Hi\65533\65533\65533!" +"Hi\56557\56498\56448!" +== UTF-8: encoding +[] +[72,105,33] +[72,105,63,33] +[72,105,128,33] + +== UTF-16LE: decoding +"recoverDecode: invalid argument (invalid byte sequence)" +"Hi\65503\8671" +"Hi\65533\65503\8671\65533" +"Hi\56575\65503\8671\NUL" +== UTF-16LE: encoding +[] +[72,0,105,0,33,0] +[72,0,105,0,63,0,33,0] +[72,0,105,0,128,33,0] + +== UTF-16BE: decoding +"recoverDecode: invalid argument (invalid byte sequence)" +"Hi\65503\65280" +"Hi\65533\65503\65280\65533" +"Hi\56543\65503\65280!" +== UTF-16BE: encoding +[] +[0,72,0,105,0,33] +[0,72,0,105,0,63,0,33] +[0,72,0,105,128,0,33] + +== UTF-32LE: decoding +"recoverDecode: invalid argument (invalid byte sequence)" +"Hi\8448" +"Hi\65533\65533\65533\8448\65533" +"Hi\56557\56498\56448\8448\NUL" +== UTF-32LE: encoding +[] +[72,0,0,0,105,0,0,0,33,0,0,0] +[72,0,0,0,105,0,0,0,63,0,0,0,33,0,0,0] +[72,0,0,0,105,0,0,0,128,33,0,0,0] + +== UTF-32BE: decoding +"recoverDecode: invalid argument (invalid byte sequence)" +"Hi!" +"Hi\65533\65533\65533\65533!" +"Hi\NUL\56448\56498\56557!" +== UTF-32BE: encoding +[] +[0,0,0,72,0,0,0,105,0,0,0,33] +[0,0,0,72,0,0,0,105,0,0,0,63,0,0,0,33] +[0,0,0,72,0,0,0,105,128,0,0,0,33] + diff --git a/testsuite/tests/ghc-regress/lib/IO/encodingerror001.stdout b/testsuite/tests/ghc-regress/lib/IO/encodingerror001.stdout index 23718da4b2..7406cd9168 100644 --- a/testsuite/tests/ghc-regress/lib/IO/encodingerror001.stdout +++ b/testsuite/tests/ghc-regress/lib/IO/encodingerror001.stdout @@ -1,36 +1,36 @@ test 1 -Caught <stdout>: hPutChar: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: hPutChar: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: hPutChar: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: hPutChar: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: hPutChar: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: hPutChar: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" test 1 -Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" test 1 -Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" test 1 -Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" test 1 -Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" test 1 -Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "\283\n" +Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "\283\n" test 2 -HCaught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "H\941llo\n" +HCaught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "H\941llo\n" test 3 -Hello Caught <stdout>: commitBuffer: invalid argument (character is out of range for this encoding) while trying to write "Hello \945\946\947\n" +Hello Caught <stdout>: commitBuffer: invalid argument (invalid character) while trying to write "Hello \945\946\947\n" diff --git a/testsuite/tests/ghc-regress/lib/IO/environment001.hs b/testsuite/tests/ghc-regress/lib/IO/environment001.hs new file mode 100644 index 0000000000..dbdaa2306b --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/environment001.hs @@ -0,0 +1,16 @@ +import System.Environment + +main = do + var0 <- getEnv "GHC_TEST" + putStrLn var0 + -- The length proves that we actually decoded it properly, not just read it + -- in as latin1 or something (#3308, #3307) + print (length var0) + + [arg0] <- getArgs + putStrLn arg0 + print (length arg0) + + [arg1] <- withArgs ["你好!"] getArgs + putStrLn arg1 + print (length arg1) diff --git a/testsuite/tests/ghc-regress/lib/IO/environment001.stdout b/testsuite/tests/ghc-regress/lib/IO/environment001.stdout new file mode 100644 index 0000000000..16299db556 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/IO/environment001.stdout @@ -0,0 +1,6 @@ +马克斯 +3 +说 +1 +你好! +3 diff --git a/testsuite/tests/ghc-regress/lib/should_run/4006.hs b/testsuite/tests/ghc-regress/lib/should_run/4006.hs new file mode 100644 index 0000000000..ea5c1ac458 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/should_run/4006.hs @@ -0,0 +1,8 @@ +import System.Process + +testUnicode :: String -> IO String +testUnicode str = init `fmap` (readProcess "echo" [str] "") + +main = do + testUnicode "It works here" >>= putStrLn + testUnicode "А здесь сломалось" >>= putStrLn diff --git a/testsuite/tests/ghc-regress/lib/should_run/4006.stdout b/testsuite/tests/ghc-regress/lib/should_run/4006.stdout new file mode 100644 index 0000000000..9db8a8ced2 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/should_run/4006.stdout @@ -0,0 +1,2 @@ +It works here +А здесь сломалось diff --git a/testsuite/tests/ghc-regress/lib/should_run/all.T b/testsuite/tests/ghc-regress/lib/should_run/all.T index 874e034904..388ad043ed 100644 --- a/testsuite/tests/ghc-regress/lib/should_run/all.T +++ b/testsuite/tests/ghc-regress/lib/should_run/all.T @@ -3,6 +3,8 @@ test('array001', normal, compile_and_run, ['']) test('char001', normal, compile_and_run, ['']) test('char002', normal, compile_and_run, ['']) +test('cstring001', normal, compile_and_run, ['']) + test('length001', # This fails without -O, as it relies on a RULE being applied expect_fail_for(['normal', 'threaded1', 'llvm']), @@ -54,3 +56,5 @@ test('stableptr004', extra_run_opts('+RTS -K4m -RTS'), compile_and_run, ['']) test('stableptr005', normal, compile_and_run, ['']) test('weak001', normal, compile_and_run, ['']) + +test('4006', normal, compile_and_run, ['']) diff --git a/testsuite/tests/ghc-regress/lib/should_run/cstring001.hs b/testsuite/tests/ghc-regress/lib/should_run/cstring001.hs new file mode 100644 index 0000000000..38d0d25db2 --- /dev/null +++ b/testsuite/tests/ghc-regress/lib/should_run/cstring001.hs @@ -0,0 +1,18 @@ +import Control.Monad +import Foreign.C.String + +test_strings = ["Hello World", replicate 10000 'a'] + +assertEqual :: (Eq a, Show a) => a -> a -> IO () +assertEqual x y = if x == y then return () else error $ "assertEqual: " ++ show x ++ " /= " ++ show y + +main = do + -- Try roundtripping some ASCII strings through the locale encoding + forM test_strings $ \try_str -> do + got_str <- withCString try_str peekCString + got_str `assertEqual` try_str + + -- Try roundtripping some ASCII strings with lengths through the locale encoding + forM test_strings $ \try_str -> do + got_str <- withCStringLen try_str peekCStringLen + got_str `assertEqual` try_str |