[commit: packages/directory] master: Modify testctl to also update the other-modules section of .cabal (4de4e8b)

git at git.haskell.org git at git.haskell.org
Sat Apr 16 19:13:18 UTC 2016


Repository : ssh://git@git.haskell.org/directory

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/4de4e8ba0226e95714fc8ff606ca3a8dd0fae545/directory

>---------------------------------------------------------------

commit 4de4e8ba0226e95714fc8ff606ca3a8dd0fae545
Author: Phil Ruffwind <rf at rufflewind.com>
Date:   Sat Mar 19 03:55:39 2016 -0400

    Modify testctl to also update the other-modules section of .cabal


>---------------------------------------------------------------

4de4e8ba0226e95714fc8ff606ca3a8dd0fae545
 directory.cabal | 24 ++++++++++++++++++++++++
 tools/testctl   | 39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/directory.cabal b/directory.cabal
index 05c91c5..acc57cf 100644
--- a/directory.cabal
+++ b/directory.cabal
@@ -81,3 +81,27 @@ test-suite test
         build-depends: Win32
     else
         build-depends: unix
+    other-modules:
+        TestUtils
+        Util
+        -- test-modules-begin
+        CanonicalizePath
+        CopyFile001
+        CopyFile002
+        CreateDirectory001
+        CreateDirectoryIfMissing001
+        CurrentDirectory001
+        Directory001
+        DoesDirectoryExist001
+        FileTime
+        FindFile001
+        GetDirContents001
+        GetDirContents002
+        GetHomeDirectory001
+        GetPermissions001
+        RemoveDirectoryRecursive001
+        RenameFile001
+        Safe
+        T8482
+        WithCurrentDirectory
+        -- test-modules-end
diff --git a/tools/testctl b/tools/testctl
index d0a36c1..18c3d82 100755
--- a/tools/testctl
+++ b/tools/testctl
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-import os, re, sys
+import glob, os, re, sys
 
 USAGE = """
 Usage:
@@ -41,8 +41,34 @@ MAIN_IMPORT_TEMPLATE = "import qualified {name}\n"
 MAIN_RUN_TEMPLATE = '  T.isolatedRun _t "{name}" {name}.main\n'
 BLACKLIST = "^(Main|.*Util.*)$"
 
+CABAL_FILE = glob.glob("*.cabal")[0]
+CABAL_SECTION_PATTERN = """(?s)
+( *)-- test-modules-begin
+.*?-- test-modules-end
+"""
+CABAL_SECTION_TEMPLATE = """
+{0}-- test-modules-begin
+{1}{0}-- test-modules-end
+"""
+
 program = os.path.basename(sys.argv[0])
 
+def rename(src, dest):
+    '''Rename a file (allows overwrites on Windows).'''
+    import os
+    if os.name == "nt":
+        import ctypes, ctypes.wintypes
+        MoveFileExW = ctypes.windll.kernel32.MoveFileExW
+        MoveFileExW.restype = ctypes.wintypes.BOOL
+        MOVEFILE_REPLACE_EXISTING = ctypes.wintypes.DWORD(0x1)
+        success = MoveFileExW(ctypes.wintypes.LPCWSTR(src),
+                              ctypes.wintypes.LPCWSTR(dest),
+                              MOVEFILE_REPLACE_EXISTING)
+        if not success:
+            raise ctypes.WinError()
+    else:
+        os.rename(src, dest)
+
 def usage():
     sys.stderr.write(USAGE.format(program=program))
     sys.exit(2)
@@ -80,6 +106,17 @@ def update():
             runs="".join(MAIN_RUN_TEMPLATE.format(name=name)
                          for name in tests),
         ).encode("utf8"))
+    with open(CABAL_FILE, "rb") as file:
+        cabal_file = file.read().decode("utf8")
+    with open(CABAL_FILE + ".tmp", "wb") as file:
+        indent, = re.search(CABAL_SECTION_PATTERN, cabal_file).groups()
+        repl = CABAL_SECTION_TEMPLATE.format(
+            indent,
+            "".join("{0}{1}\n".format(indent, name) for name in tests)
+        )
+        file.write(re.sub(CABAL_SECTION_PATTERN, repl, cabal_file)
+                   .encode("utf8"))
+    rename(CABAL_FILE + ".tmp", CABAL_FILE)
 
 if len(sys.argv) < 2:
     usage()



More information about the ghc-commits mailing list