Skip to content

Commit

Permalink
Run more tests in temporary directory (#17683)
Browse files Browse the repository at this point in the history
* run tests in temp dirs

* rename

* update comment

* diff

* use single temp dir for compile

* unskip sdktest, naming

* refactor

* parametrize msbuild in SDKTests

* nicer
  • Loading branch information
majocha authored Sep 11, 2024
1 parent b494d1e commit c228ace
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let xmlFileContents signature = $"""<?xml version="1.0" encoding="utf-8"?>
[<InlineData("P:Microsoft.FSharp.Collections.FSharpList`1.Length")>]
[<InlineData("P:Microsoft.FSharp.Collections.FSharpList`1.Length'")>]
let ``Can extract XML docs from a file for a signature`` signature =
let xmlFileName = tryCreateTemporaryFileName () + ".xml"
let xmlFileName = getTemporaryFileName () + ".xml"

try
File.WriteAllText(xmlFileName, xmlFileContents signature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open TestFramework
let internal getProjectReferences (content: string, dllFiles, libDirs, otherFlags) =
let otherFlags = defaultArg otherFlags []
let libDirs = defaultArg libDirs []
let base1 = tryCreateTemporaryFileName ()
let base1 = getTemporaryFileName ()
let dllName = Path.ChangeExtension(base1, ".dll")
let fileName1 = Path.ChangeExtension(base1, ".fs")
let projFileName = Path.ChangeExtension(base1, ".fsproj")
Expand Down
8 changes: 4 additions & 4 deletions tests/FSharp.Compiler.Service.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Async with
let checker = FSharpChecker.Create(useTransparentCompiler=FSharp.Compiler.CompilerConfig.FSharpExperimentalFeaturesEnabledAutomatically)

type TempFile(ext, contents: string) =
let tmpFile = Path.ChangeExtension(tryCreateTemporaryFileName (), ext)
let tmpFile = Path.ChangeExtension(getTemporaryFileName (), ext)
do FileSystem.OpenFileForWriteShim(tmpFile).Write(contents)

interface IDisposable with
Expand Down Expand Up @@ -130,8 +130,8 @@ let mkProjectCommandLineArgsForScript (dllName, fileNames) =
#endif

let mkTestFileAndOptions source additionalArgs =
let fileName = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let project = tryCreateTemporaryFileName ()
let fileName = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let project = getTemporaryFileName ()
let dllName = Path.ChangeExtension(project, ".dll")
let projFileName = Path.ChangeExtension(project, ".fsproj")
let fileSource1 = "module M"
Expand Down Expand Up @@ -481,7 +481,7 @@ module TempDirUtils =
/// Returns the file name part of a temp file name created with tryCreateTemporaryFileName ()
/// and an added process id and thread id to ensure uniqueness between threads.
let getTempFileName() =
let tempFileName = tryCreateTemporaryFileName ()
let tempFileName = getTemporaryFileName ()
try
let tempFile, tempExt = Path.GetFileNameWithoutExtension tempFileName, Path.GetExtension tempFileName
let procId, threadId = Process.GetCurrentProcess().Id, Thread.CurrentThread.ManagedThreadId
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharp.Compiler.Service.Tests/ExprTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3155,7 +3155,7 @@ let ``Test expressions of declarations stress big expressions`` useTransparentCo
printDeclarations None (List.ofSeq file1.Declarations) |> Seq.toList |> ignore

#if !NETFRAMEWORK && DEBUG
[<Fact(Skip = "Test is known to fail in DEBUG when not using NetFramework. Use RELEASE configuration or NetFramework to run it.")>]
[<Theory(Skip = "Test is known to fail in DEBUG when not using NetFramework. Use RELEASE configuration or NetFramework to run it.")>]
#else
[<Theory>]
[<InlineData(false)>]
Expand Down
48 changes: 24 additions & 24 deletions tests/FSharp.Compiler.Service.Tests/MultiProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ let internal tups (m:range) = (m.StartLine, m.StartColumn), (m.EndLine, m.EndCol

module internal Project1A =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileSource1 = """
Expand Down Expand Up @@ -69,8 +69,8 @@ type U =
//-----------------------------------------------------------------------------------------
module internal Project1B =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileSource1 = """
Expand All @@ -96,8 +96,8 @@ let x =
// A project referencing two sub-projects
module internal MultiProject1 =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileSource1 = """
Expand Down Expand Up @@ -271,7 +271,7 @@ module internal ManyProjectsStressTest =
type Project = { ModuleName: string; FileName: string; Options: FSharpProjectOptions; DllName: string }
let projects =
[ for i in 1 .. numProjectsForStressTest do
let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let moduleName = "Project" + string i
let fileSource1 = "module " + moduleName + """
Expand All @@ -287,7 +287,7 @@ let p = C.Print()
"""
FileSystem.OpenFileForWriteShim(fileName1).Write(fileSource1)
let baseName = tryCreateTemporaryFileName ()
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileNames = [|fileName1|]
Expand All @@ -296,8 +296,8 @@ let p = C.Print()
yield { ModuleName = moduleName; FileName=fileName1; Options = options; DllName=dllName } ]

let jointProject =
let fileName = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let dllBase = tryCreateTemporaryFileName ()
let fileName = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let dllBase = getTemporaryFileName ()
let dllName = Path.ChangeExtension(dllBase, ".dll")
let projFileName = Path.ChangeExtension(dllBase, ".fsproj")
let fileSource =
Expand Down Expand Up @@ -396,8 +396,8 @@ let ``Test ManyProjectsStressTest all symbols`` useTransparentCompiler =

module internal MultiProjectDirty1 =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let content = """module Project1
Expand All @@ -418,8 +418,8 @@ let x = "F#"
module internal MultiProjectDirty2 =


let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")

Expand Down Expand Up @@ -609,10 +609,10 @@ let ``Test multi project symbols should pick up changes in dependent projects``

module internal Project2A =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName(), ".fs")
let baseName1 = tryCreateTemporaryFileName ()
let baseName2 = tryCreateTemporaryFileName ()
let baseName3 = tryCreateTemporaryFileName () // this one doesn't get InternalsVisibleTo rights
let fileName1 = Path.ChangeExtension(getTemporaryFileName(), ".fs")
let baseName1 = getTemporaryFileName ()
let baseName2 = getTemporaryFileName ()
let baseName3 = getTemporaryFileName () // this one doesn't get InternalsVisibleTo rights
let dllShortName = Path.GetFileNameWithoutExtension(baseName2)
let dllName = Path.ChangeExtension(baseName1, ".dll")
let projFileName = Path.ChangeExtension(baseName1, ".fsproj")
Expand All @@ -638,7 +638,7 @@ type C() =
// A project referencing Project2A
module internal Project2B =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let dllName = Path.ChangeExtension(Project2A.baseName2, ".dll")
let projFileName = Path.ChangeExtension(Project2A.baseName2, ".fsproj")
let fileSource1 = """
Expand All @@ -662,7 +662,7 @@ let v = Project2A.C().InternalMember // access an internal symbol
// A project referencing Project2A but without access to the internals of A
module internal Project2C =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let dllName = Path.ChangeExtension(Project2A.baseName3, ".dll")
let projFileName = Path.ChangeExtension(Project2A.baseName3, ".fsproj")
let fileSource1 = """
Expand Down Expand Up @@ -733,8 +733,8 @@ let ``Test multi project 2 all symbols`` useTransparentCompiler =

module internal Project3A =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileSource1 = """
Expand All @@ -756,8 +756,8 @@ let (|DivisibleBy|_|) by n =
// A project referencing a sub-project
module internal MultiProject3 =

let fileName1 = Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")
let baseName = tryCreateTemporaryFileName ()
let fileName1 = Path.ChangeExtension(getTemporaryFileName (), ".fs")
let baseName = getTemporaryFileName ()
let dllName = Path.ChangeExtension(baseName, ".dll")
let projFileName = Path.ChangeExtension(baseName, ".fsproj")
let fileSource1 = """
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Compiler.Service.Tests/PerfTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let internal checker = FSharpChecker.Create()

module internal Project1 =

let fileNamesI = [ for i in 1 .. 10 -> (i, Path.ChangeExtension(tryCreateTemporaryFileName (), ".fs")) ]
let base2 = tryCreateTemporaryFileName ()
let fileNamesI = [ for i in 1 .. 10 -> (i, Path.ChangeExtension(getTemporaryFileName (), ".fs")) ]
let base2 = getTemporaryFileName ()
let dllName = Path.ChangeExtension(base2, ".dll")
let projFileName = Path.ChangeExtension(base2, ".fsproj")
let fileSources = [ for i,f in fileNamesI -> (f, "module M" + string i) ]
Expand Down
Loading

0 comments on commit c228ace

Please sign in to comment.