File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
test/unit-tests/toolchain Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import { installSwiftlyToolchainWithProgress } from "../commands/installSwiftlyT
25
25
import { ContextKeys } from "../contextKeys" ;
26
26
import { SwiftLogger } from "../logging/SwiftLogger" ;
27
27
import { showMissingToolchainDialog } from "../ui/ToolchainSelection" ;
28
+ import { touch } from "../utilities/filesystem" ;
28
29
import { findBinaryPath } from "../utilities/shell" ;
29
30
import { ExecFileError , execFile , execFileStreamOutput } from "../utilities/utilities" ;
30
31
import { Version } from "../utilities/version" ;
@@ -339,6 +340,7 @@ export class Swiftly {
339
340
const options : ExecFileOptions = { } ;
340
341
if ( cwd ) {
341
342
options . cwd = cwd ;
343
+ await touch ( path . join ( cwd , ".swift-version" ) ) ;
342
344
} else {
343
345
useArgs . push ( "--global-default" ) ;
344
346
}
Original file line number Diff line number Diff line change @@ -48,6 +48,18 @@ export async function fileExists(...pathComponents: string[]): Promise<boolean>
48
48
}
49
49
}
50
50
51
+ /**
52
+ * Checks if a file exists on disk and, if it doesn't, creates it. If the file does exist
53
+ * then this function does nothing.
54
+ * @param path The path to the file.
55
+ */
56
+ export async function touch ( path : string ) : Promise < void > {
57
+ if ( ! ( await fileExists ( path ) ) ) {
58
+ const handle = await fs . open ( path , "a" ) ;
59
+ await handle . close ( ) ;
60
+ }
61
+ }
62
+
51
63
/**
52
64
* Return whether a file/folder is inside a folder.
53
65
* @param subpath child file/folder
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ suite("Swiftly Unit Tests", () => {
85
85
} ) ;
86
86
87
87
test ( "sets the toolchain in cwd if it is provided" , async ( ) => {
88
+ // CWD exists
89
+ mockFS ( { "/home/user/project" : mockFS . directory ( ) } ) ;
88
90
// Mock version check to return 1.0.1
89
91
mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
90
92
stdout : "1.1.0\n" ,
@@ -100,6 +102,8 @@ suite("Swiftly Unit Tests", () => {
100
102
[ "use" , "-y" , "6.1.0" ] ,
101
103
match . has ( "cwd" , "/home/user/project" )
102
104
) ;
105
+ const stats = await fs . stat ( "/home/user/project/.swift-version" ) ;
106
+ expect ( stats . isFile ( ) , "Expected .swift-version file to be created" ) . to . be . true ;
103
107
} ) ;
104
108
} ) ;
105
109
You can’t perform that action at this time.
0 commit comments