From a0cf13d331cfab73539e93bf1ca2de4e550b8d12 Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Thu, 23 Jan 2020 10:29:14 -0800 Subject: [PATCH] safely delete test files and directories --- .../tests/UnitTests/ProjectOptionsBuilder.fs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/vsintegration/tests/UnitTests/ProjectOptionsBuilder.fs b/vsintegration/tests/UnitTests/ProjectOptionsBuilder.fs index 1d3df25165..106b7602a5 100644 --- a/vsintegration/tests/UnitTests/ProjectOptionsBuilder.fs +++ b/vsintegration/tests/UnitTests/ProjectOptionsBuilder.fs @@ -5,6 +5,19 @@ open System.IO open System.Xml.Linq open FSharp.Compiler.SourceCodeServices +module FileSystemHelpers = + let safeDeleteFile (path: string) = + try + File.Delete(path) + with + | _ -> () + + let safeDeleteDirectory (path: string) = + try + Directory.Delete(path) + with + | _ -> () + type FSharpProject = { Directory: string @@ -29,9 +42,10 @@ type FSharpProject = member this.Dispose() = // delete each source file this.Files - |> List.iter (fun (path, _contents) -> File.Delete(path)) + |> List.map fst + |> List.iter FileSystemHelpers.safeDeleteFile // delete the directory - Directory.Delete(this.Directory) + FileSystemHelpers.safeDeleteDirectory (this.Directory) // project file doesn't really exist, nothing to delete ()