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
2525import { ContextKeys } from "../contextKeys" ;
2626import { SwiftLogger } from "../logging/SwiftLogger" ;
2727import { showMissingToolchainDialog } from "../ui/ToolchainSelection" ;
28+ import { touch } from "../utilities/filesystem" ;
2829import { findBinaryPath } from "../utilities/shell" ;
2930import { ExecFileError , execFile , execFileStreamOutput } from "../utilities/utilities" ;
3031import { Version } from "../utilities/version" ;
@@ -339,6 +340,7 @@ export class Swiftly {
339340 const options : ExecFileOptions = { } ;
340341 if ( cwd ) {
341342 options . cwd = cwd ;
343+ await touch ( path . join ( cwd , ".swift-version" ) ) ;
342344 } else {
343345 useArgs . push ( "--global-default" ) ;
344346 }
Original file line number Diff line number Diff line change @@ -48,6 +48,18 @@ export async function fileExists(...pathComponents: string[]): Promise<boolean>
4848 }
4949}
5050
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+
5163/**
5264 * Return whether a file/folder is inside a folder.
5365 * @param subpath child file/folder
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ suite("Swiftly Unit Tests", () => {
8585 } ) ;
8686
8787 test ( "sets the toolchain in cwd if it is provided" , async ( ) => {
88+ // CWD exists
89+ mockFS ( { "/home/user/project" : mockFS . directory ( ) } ) ;
8890 // Mock version check to return 1.0.1
8991 mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
9092 stdout : "1.1.0\n" ,
@@ -100,6 +102,8 @@ suite("Swiftly Unit Tests", () => {
100102 [ "use" , "-y" , "6.1.0" ] ,
101103 match . has ( "cwd" , "/home/user/project" )
102104 ) ;
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 ;
103107 } ) ;
104108 } ) ;
105109
You can’t perform that action at this time.
0 commit comments