Skip to content

Use NSTemporaryDirectory helper function instead of hard coding /tmp #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TestFoundation/TestNSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ class TestNSArray : XCTestCase {
}

private func createTestFile(_ path: String, _contents: Data) -> String? {
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"
do {
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
if FileManager.default.createFile(atPath: tempDir + "/" + path, contents: _contents, attributes: nil) {
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestNSBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class TestNSBundle : XCTestCase {

private func _setupPlayground() -> String? {
// Make sure the directory is uniquely named
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"

do {
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
Expand Down Expand Up @@ -179,7 +179,7 @@ class TestNSBundle : XCTestCase {
}

func test_bundleWithInvalidPath(){
let bundleInvalid = Bundle(path: "/tmp/test.playground")
let bundleInvalid = Bundle(path: NSTemporaryDirectory() + "test.playground")
XCTAssertNil(bundleInvalid)
}

Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class TestNSDictionary : XCTestCase {
}

private func createTestFile(_ path: String, _contents: Data) -> String? {
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"
do {
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
if FileManager.default.createFile(atPath: tempDir + "/" + path, contents: _contents,
Expand Down
44 changes: 22 additions & 22 deletions TestFoundation/TestNSFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestNSFileManager : XCTestCase {

func test_createDirectory() {
let fm = FileManager.default
let path = "/tmp/testdir\(NSUUID().uuidString)"
let path = NSTemporaryDirectory() + "testdir\(NSUUID().uuidString)"

ignoreError { try fm.removeItem(atPath: path) }

Expand All @@ -63,7 +63,7 @@ class TestNSFileManager : XCTestCase {

func test_createFile() {
let fm = FileManager.default
let path = "/tmp/testfile\(NSUUID().uuidString)"
let path = NSTemporaryDirectory() + "testfile\(NSUUID().uuidString)"

ignoreError { try fm.removeItem(atPath: path) }

Expand All @@ -83,8 +83,8 @@ class TestNSFileManager : XCTestCase {

func test_moveFile() {
let fm = FileManager.default
let path = "/tmp/testfile\(NSUUID().uuidString)"
let path2 = "/tmp/testfile2\(NSUUID().uuidString)"
let path = NSTemporaryDirectory() + "testfile\(NSUUID().uuidString)"
let path2 = NSTemporaryDirectory() + "testfile2\(NSUUID().uuidString)"

func cleanup() {
ignoreError { try fm.removeItem(atPath: path) }
Expand Down Expand Up @@ -114,7 +114,7 @@ class TestNSFileManager : XCTestCase {

func test_fileAttributes() {
let fm = FileManager.default
let path = "/tmp/test_fileAttributes\(NSUUID().uuidString)"
let path = NSTemporaryDirectory() + "test_fileAttributes\(NSUUID().uuidString)"

ignoreError { try fm.removeItem(atPath: path) }

Expand Down Expand Up @@ -161,7 +161,7 @@ class TestNSFileManager : XCTestCase {
}

func test_setFileAttributes() {
let path = "/tmp/test_setFileAttributes\(NSUUID().uuidString)"
let path = NSTemporaryDirectory() + "test_setFileAttributes\(NSUUID().uuidString)"
let fm = FileManager.default

ignoreError { try fm.removeItem(atPath: path) }
Expand Down Expand Up @@ -189,10 +189,10 @@ class TestNSFileManager : XCTestCase {
func test_pathEnumerator() {
let fm = FileManager.default
let testDirName = "testdir\(NSUUID().uuidString)"
let basePath = "/tmp/\(testDirName)"
let itemPath = "/tmp/\(testDirName)/item"
let basePath2 = "/tmp/\(testDirName)/path2"
let itemPath2 = "/tmp/\(testDirName)/path2/item"
let basePath = NSTemporaryDirectory() + "\(testDirName)"
let itemPath = NSTemporaryDirectory() + "\(testDirName)/item"
let basePath2 = NSTemporaryDirectory() + "\(testDirName)/path2"
let itemPath2 = NSTemporaryDirectory() + "\(testDirName)/path2/item"

ignoreError { try fm.removeItem(atPath: basePath) }

Expand Down Expand Up @@ -222,8 +222,8 @@ class TestNSFileManager : XCTestCase {
func test_directoryEnumerator() {
let fm = FileManager.default
let testDirName = "testdir\(NSUUID().uuidString)"
let path = "/tmp/\(testDirName)"
let itemPath = "/tmp/\(testDirName)/item"
let path = NSTemporaryDirectory() + "\(testDirName)"
let itemPath = NSTemporaryDirectory() + "\(testDirName)/item"

ignoreError { try fm.removeItem(atPath: path) }

Expand All @@ -244,8 +244,8 @@ class TestNSFileManager : XCTestCase {
XCTFail()
}

let subDirPath = "/tmp/\(testDirName)/testdir2"
let subDirItemPath = "/tmp/\(testDirName)/testdir2/item"
let subDirPath = NSTemporaryDirectory() + "\(testDirName)/testdir2"
let subDirItemPath = NSTemporaryDirectory() + "\(testDirName)/testdir2/item"
do {
try fm.createDirectory(atPath: subDirPath, withIntermediateDirectories: false, attributes: nil)
let _ = fm.createFile(atPath: subDirItemPath, contents: Data(), attributes: nil)
Expand Down Expand Up @@ -320,9 +320,9 @@ class TestNSFileManager : XCTestCase {
func test_contentsOfDirectoryAtPath() {
let fm = FileManager.default
let testDirName = "testdir\(NSUUID().uuidString)"
let path = "/tmp/\(testDirName)"
let itemPath1 = "/tmp/\(testDirName)/item"
let itemPath2 = "/tmp/\(testDirName)/item2"
let path = NSTemporaryDirectory() + "\(testDirName)"
let itemPath1 = NSTemporaryDirectory() + "\(testDirName)/item"
let itemPath2 = NSTemporaryDirectory() + "\(testDirName)/item2"

ignoreError { try fm.removeItem(atPath: path) }

Expand Down Expand Up @@ -363,11 +363,11 @@ class TestNSFileManager : XCTestCase {

func test_subpathsOfDirectoryAtPath() {
let fm = FileManager.default
let path = "/tmp/testdir"
let path2 = "/tmp/testdir/sub"
let itemPath1 = "/tmp/testdir/item"
let itemPath2 = "/tmp/testdir/item2"
let itemPath3 = "/tmp/testdir/sub/item3"
let path = NSTemporaryDirectory() + "testdir"
let path2 = NSTemporaryDirectory() + "testdir/sub"
let itemPath1 = NSTemporaryDirectory() + "testdir/item"
let itemPath2 = NSTemporaryDirectory() + "testdir/item2"
let itemPath3 = NSTemporaryDirectory() + "testdir/sub/item3"

ignoreError { try fm.removeItem(atPath: path) }

Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSJSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ extension TestNSJSONSerialization {
}

private func createTestFile(_ path: String,_contents: Data) -> String? {
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"
do {
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
if FileManager.default.createFile(atPath: tempDir + "/" + path, contents: _contents,
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestNSStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TestNSStream : XCTestCase {
}

func test_InputStreamInvalidPath() {
let fileStream: InputStream = InputStream(fileAtPath: "/tmp/file.txt")!
let fileStream: InputStream = InputStream(fileAtPath: NSTemporaryDirectory() + "file.txt")!
XCTAssertEqual(Stream.Status.notOpen, fileStream.streamStatus)
fileStream.open()
XCTAssertEqual(Stream.Status.error, fileStream.streamStatus)
Expand Down Expand Up @@ -217,7 +217,7 @@ class TestNSStream : XCTestCase {
}

private func createTestFile(_ path: String, _contents: Data) -> String? {
let tempDir = "/tmp/TestFoundation_Playground_" + NSUUID().uuidString + "/"
let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/"
do {
try FileManager.default.createDirectory(atPath: tempDir, withIntermediateDirectories: false, attributes: nil)
if FileManager.default.createFile(atPath: tempDir + "/" + path, contents: _contents,
Expand Down
20 changes: 10 additions & 10 deletions TestFoundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ class TestNSString : XCTestCase {

func test_completePathIntoString() {
let fileNames = [
"/tmp/Test_completePathIntoString_01",
"/tmp/test_completePathIntoString_02",
"/tmp/test_completePathIntoString_01.txt",
"/tmp/test_completePathIntoString_01.dat",
"/tmp/test_completePathIntoString_03.DAT"
NSTemporaryDirectory() + "Test_completePathIntoString_01",
NSTemporaryDirectory() + "test_completePathIntoString_02",
NSTemporaryDirectory() + "test_completePathIntoString_01.txt",
NSTemporaryDirectory() + "test_completePathIntoString_01.dat",
NSTemporaryDirectory() + "test_completePathIntoString_03.DAT"
]

guard ensureFiles(fileNames) else {
Expand All @@ -432,7 +432,7 @@ class TestNSString : XCTestCase {
}

let tmpPath = { (path: String) -> String in
return "/tmp/\(path)"
return NSTemporaryDirectory() + "\(path)"
}

do {
Expand Down Expand Up @@ -463,9 +463,9 @@ class TestNSString : XCTestCase {
}

let fileNames2 = [
"/tmp/ABC/",
"/tmp/ABCD/",
"/tmp/abcde"
NSTemporaryDirectory() + "ABC/",
NSTemporaryDirectory() + "ABCD/",
NSTemporaryDirectory() + "abcde"
]

guard ensureFiles(fileNames2) else {
Expand Down Expand Up @@ -571,7 +571,7 @@ class TestNSString : XCTestCase {

// Next check has no sense on Linux due to case sensitive file system.
#if os(OSX)
guard ensureFiles(["/tmp/ABC/temp.txt"]) else {
guard ensureFiles([NSTemporaryDirectory() + "ABC/temp.txt"]) else {
XCTAssert(false, "Could not create temp files for testing.")
return
}
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class TestNSURL : XCTestCase {

func test_URLByResolvingSymlinksInPath() {
let files = [
"/tmp/ABC/test_URLByResolvingSymlinksInPath"
NSTemporaryDirectory() + "ABC/test_URLByResolvingSymlinksInPath"
]

guard ensureFiles(files) else {
Expand Down