Skip to content

Commit 7c078bf

Browse files
committed
test: make the ParseableInterface.ModuleCache tests pass on Windows
Use a wrapper for invoking chmod a-r or icacls on Windows to make the files actually unreadable. This allows the tests to pass on Windows.
1 parent f85ca6c commit 7c078bf

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import platform
3+
import subprocess
4+
import sys
5+
6+
if platform.system() == 'Windows':
7+
import ctypes
8+
AdvAPI32 = ctypes.windll.Advapi32
9+
10+
from ctypes.wintypes import POINTER
11+
12+
UNLEN = 256
13+
14+
GetUserNameW = AdvAPI32.GetUserNameW
15+
GetUserNameW.argtypes = (
16+
ctypes.c_wchar_p, # _In_Out_ lpBuffer
17+
POINTER(ctypes.c_uint) # _In_out_ pcBuffer
18+
)
19+
GetUserNameW.restype = ctypes.c_uint
20+
21+
buffer = ctypes.create_unicode_buffer(UNLEN + 1)
22+
size = ctypes.c_uint(len(buffer))
23+
GetUserNameW(buffer, ctypes.byref(size))
24+
25+
for path in sys.argv[1:]:
26+
subprocess.call(['icacls', path, '/deny',
27+
'{}:(R)'.format(buffer.value)])
28+
else:
29+
for path in sys.argv[1:]:
30+
subprocess.call(['chmod', 'a-r', path])

test/ParseableInterface/ModuleCache/force-module-loading-mode-archs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
5757

5858
// 6. Both are present but the module can't be opened.
59-
// RUN: chmod a-r %t/Lib.swiftmodule/%target-swiftmodule-name
59+
// RUN: %{python} %S/../Inputs/make-unreadable.py %t/Lib.swiftmodule/%target-swiftmodule-name
6060
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
6161
// RUN: %empty-directory(%t/MCP)
6262
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s

test/ParseableInterface/ModuleCache/force-module-loading-mode-framework.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
// RUN: %empty-directory(%t/MCP)
5858

5959
// 6. Both are present but the module can't be opened.
60-
// RUN: chmod a-r %t/Lib.framework/Modules/Lib.swiftmodule/%target-swiftmodule-name
60+
// RUN: %{python} %S/../Inputs/make-unreadable.py %t/Lib.framework/Modules/Lib.swiftmodule/%target-swiftmodule-name
6161
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
6262
// RUN: %empty-directory(%t/MCP)
6363
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s

test/ParseableInterface/ModuleCache/force-module-loading-mode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
// RUN: %empty-directory(%t/MCP)
5555

5656
// 6. Both are present but the module can't be opened.
57-
// RUN: chmod a-r %t/Lib.swiftmodule
57+
// RUN: %{python} %S/../Inputs/make-unreadable.py %t/Lib.swiftmodule
5858
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
5959
// RUN: %empty-directory(%t/MCP)
6060
// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s

test/ParseableInterface/ModuleCache/prebuilt-module-cache-forwarding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// RUN: %empty-directory(%t/MCP)
3636
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1
3737
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
38-
// RUN: chmod a-r %t/MCP/Lib-*.swiftmodule
38+
// RUN: %{python} %S/../Inputs/make-unreadable.py %t/MCP/Lib-*.swiftmodule
3939
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-PREBUILT %s
4040
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
4141

0 commit comments

Comments
 (0)