Move tests from testsuite/tests/ghc-regress/lib/Directory
authorSimon Marlow <simonmar@microsoft.com>
Thu, 18 Oct 2007 12:01:15 +0000 (12:01 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Thu, 18 Oct 2007 12:01:15 +0000 (12:01 +0000)
19 files changed:
tests/Makefile [new file with mode: 0644]
tests/all.T [new file with mode: 0644]
tests/currentDirectory001.hs [new file with mode: 0644]
tests/currentDirectory001.hs~ [new file with mode: 0644]
tests/currentDirectory001.stdout [new file with mode: 0644]
tests/directory001.hs [new file with mode: 0644]
tests/directory001.stdout [new file with mode: 0644]
tests/doesDirectoryExist001.hs [new file with mode: 0644]
tests/doesDirectoryExist001.stdout [new file with mode: 0644]
tests/getDirContents001.hs [new file with mode: 0644]
tests/getDirContents001.stdout [new file with mode: 0644]
tests/getDirContents001.stdout-i386-unknown-mingw32 [new file with mode: 0644]
tests/getPermissions001.hs [new file with mode: 0644]
tests/getPermissions001.stdout [new file with mode: 0644]
tests/getPermissions001.stdout-alpha-dec-osf3 [new file with mode: 0644]
tests/getPermissions001.stdout-i386-unknown-freebsd [new file with mode: 0644]
tests/getPermissions001.stdout-i386-unknown-openbsd [new file with mode: 0644]
tests/getPermissions001.stdout-mingw [new file with mode: 0644]
tests/getPermissions001.stdout-x86_64-unknown-openbsd [new file with mode: 0644]

diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..6a0abcf
--- /dev/null
@@ -0,0 +1,7 @@
+# This Makefile runs the tests using GHC's testsuite framework.  It
+# assumes the package is part of a GHC build tree with the testsuite
+# installed in ../../../testsuite.
+
+TOP=../../../testsuite
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
diff --git a/tests/all.T b/tests/all.T
new file mode 100644 (file)
index 0000000..526e9ad
--- /dev/null
@@ -0,0 +1,9 @@
+test('currentDirectory001',     normal, compile_and_run, [''])
+test('directory001',            normal, compile_and_run, [''])
+test('doesDirectoryExist001',   normal, compile_and_run, [''])
+
+# This test is a bit bogus.  Disable for GHCi.
+test('getDirContents001', omit_ways(['ghci']), compile_and_run, ['-fno-gen-manifest'])
+
+# Depends on binary from previous run, which gets removed by the driver way=ghci
+test('getPermissions001', omit_ways(['ghci']), compile_and_run, ['-cpp'])
diff --git a/tests/currentDirectory001.hs b/tests/currentDirectory001.hs
new file mode 100644 (file)
index 0000000..bcf9b96
--- /dev/null
@@ -0,0 +1,20 @@
+import Directory (getCurrentDirectory, setCurrentDirectory, 
+                     createDirectory, removeDirectory, getDirectoryContents)
+
+main = do
+    oldpwd <- getCurrentDirectory
+    createDirectory "foo"
+    setCurrentDirectory "foo"
+    ~[n1, n2] <- getDirectoryContents "."
+    if dot n1 && dot n2 
+     then do
+        setCurrentDirectory oldpwd
+        removeDirectory "foo"
+        putStr "Okay\n"
+      else
+        ioError (userError "Oops")
+
+dot :: String -> Bool
+dot "." = True
+dot ".." = True
+dot _ = False
diff --git a/tests/currentDirectory001.hs~ b/tests/currentDirectory001.hs~
new file mode 100644 (file)
index 0000000..bcf9b96
--- /dev/null
@@ -0,0 +1,20 @@
+import Directory (getCurrentDirectory, setCurrentDirectory, 
+                     createDirectory, removeDirectory, getDirectoryContents)
+
+main = do
+    oldpwd <- getCurrentDirectory
+    createDirectory "foo"
+    setCurrentDirectory "foo"
+    ~[n1, n2] <- getDirectoryContents "."
+    if dot n1 && dot n2 
+     then do
+        setCurrentDirectory oldpwd
+        removeDirectory "foo"
+        putStr "Okay\n"
+      else
+        ioError (userError "Oops")
+
+dot :: String -> Bool
+dot "." = True
+dot ".." = True
+dot _ = False
diff --git a/tests/currentDirectory001.stdout b/tests/currentDirectory001.stdout
new file mode 100644 (file)
index 0000000..1ddd42b
--- /dev/null
@@ -0,0 +1 @@
+Okay
diff --git a/tests/directory001.hs b/tests/directory001.hs
new file mode 100644 (file)
index 0000000..c04a015
--- /dev/null
@@ -0,0 +1,17 @@
+import IO
+
+import Directory
+
+main = do
+    createDirectory "foo"
+    h <- openFile "foo/bar" WriteMode
+    hPutStr h "Okay\n"
+    hClose h
+    renameFile "foo/bar" "foo/baz"
+    renameDirectory "foo" "bar"
+    h <- openFile "bar/baz" ReadMode
+    stuff <- hGetContents h
+    putStr stuff
+--    hClose h  -- an error !
+    removeFile "bar/baz"
+    removeDirectory "bar"
diff --git a/tests/directory001.stdout b/tests/directory001.stdout
new file mode 100644 (file)
index 0000000..1ddd42b
--- /dev/null
@@ -0,0 +1 @@
+Okay
diff --git a/tests/doesDirectoryExist001.hs b/tests/doesDirectoryExist001.hs
new file mode 100644 (file)
index 0000000..be26ec0
--- /dev/null
@@ -0,0 +1,4 @@
+-- !!! "/" was not recognised as a directory in 6.0.x
+import System.Directory
+main = doesDirectoryExist "/" >>= print
+
diff --git a/tests/doesDirectoryExist001.stdout b/tests/doesDirectoryExist001.stdout
new file mode 100644 (file)
index 0000000..0ca9514
--- /dev/null
@@ -0,0 +1 @@
+True
diff --git a/tests/getDirContents001.hs b/tests/getDirContents001.hs
new file mode 100644 (file)
index 0000000..1c0e3f8
--- /dev/null
@@ -0,0 +1,13 @@
+import Directory (getDirectoryContents)
+import List (sort, isPrefixOf, isSuffixOf)
+
+main = do
+    names <- getDirectoryContents "."
+    putStrLn (unlines (sort (filter ok names)))
+
+ok name = "getDirContents" `isPrefixOf` name 
+         && not ("bak" `isSuffixOf` name)
+         && not ("prof" `isSuffixOf` name)
+         && not ("hp" `isSuffixOf` name)
+          && not ("ps" `isSuffixOf` name)
+          && not ("aux" `isSuffixOf` name)
diff --git a/tests/getDirContents001.stdout b/tests/getDirContents001.stdout
new file mode 100644 (file)
index 0000000..87a875c
--- /dev/null
@@ -0,0 +1,10 @@
+getDirContents001
+getDirContents001.comp.stderr
+getDirContents001.hi
+getDirContents001.hs
+getDirContents001.o
+getDirContents001.run.stderr
+getDirContents001.run.stdout
+getDirContents001.stdout
+getDirContents001.stdout-i386-unknown-mingw32
+
diff --git a/tests/getDirContents001.stdout-i386-unknown-mingw32 b/tests/getDirContents001.stdout-i386-unknown-mingw32
new file mode 100644 (file)
index 0000000..89deae1
--- /dev/null
@@ -0,0 +1,10 @@
+getDirContents001.comp.stderr\r
+getDirContents001.exe\r
+getDirContents001.hi\r
+getDirContents001.hs\r
+getDirContents001.o\r
+getDirContents001.run.stderr\r
+getDirContents001.run.stdout\r
+getDirContents001.stdout\r
+getDirContents001.stdout-i386-unknown-mingw32\r
+\r
diff --git a/tests/getPermissions001.hs b/tests/getPermissions001.hs
new file mode 100644 (file)
index 0000000..0c435df
--- /dev/null
@@ -0,0 +1,13 @@
+import Directory
+
+main = do
+  p <- getPermissions "."
+  print p
+  p <- getPermissions "getPermissions001.hs"
+  print p
+#ifndef i386_unknown_mingw32
+  p <- getPermissions "getPermissions001"
+#else
+  p <- getPermissions "getPermissions001.exe"
+#endif
+  print p
diff --git a/tests/getPermissions001.stdout b/tests/getPermissions001.stdout
new file mode 100644 (file)
index 0000000..1e18354
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = False, searchable = True}
+Permissions {readable = True, writable = True, executable = False, searchable = False}
+Permissions {readable = True, writable = True, executable = True, searchable = False}
diff --git a/tests/getPermissions001.stdout-alpha-dec-osf3 b/tests/getPermissions001.stdout-alpha-dec-osf3
new file mode 100644 (file)
index 0000000..8b030e2
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = False, searchable = True}
+Permissions {readable = True, writable = True, executable = False, searchable = False}
+Permissions {readable = True, writable = False, executable = True, searchable = False}
diff --git a/tests/getPermissions001.stdout-i386-unknown-freebsd b/tests/getPermissions001.stdout-i386-unknown-freebsd
new file mode 100644 (file)
index 0000000..8b030e2
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = False, searchable = True}
+Permissions {readable = True, writable = True, executable = False, searchable = False}
+Permissions {readable = True, writable = False, executable = True, searchable = False}
diff --git a/tests/getPermissions001.stdout-i386-unknown-openbsd b/tests/getPermissions001.stdout-i386-unknown-openbsd
new file mode 100644 (file)
index 0000000..8b030e2
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = False, searchable = True}
+Permissions {readable = True, writable = True, executable = False, searchable = False}
+Permissions {readable = True, writable = False, executable = True, searchable = False}
diff --git a/tests/getPermissions001.stdout-mingw b/tests/getPermissions001.stdout-mingw
new file mode 100644 (file)
index 0000000..4dcaba5
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = True, searchable = True}
+Permissions {readable = True, writable = True, executable = True, searchable = True}
+Permissions {readable = True, writable = True, executable = True, searchable = True}
diff --git a/tests/getPermissions001.stdout-x86_64-unknown-openbsd b/tests/getPermissions001.stdout-x86_64-unknown-openbsd
new file mode 100644 (file)
index 0000000..8b030e2
--- /dev/null
@@ -0,0 +1,3 @@
+Permissions {readable = True, writable = True, executable = False, searchable = True}
+Permissions {readable = True, writable = True, executable = False, searchable = False}
+Permissions {readable = True, writable = False, executable = True, searchable = False}