Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Trying to figure out span tests
  • Loading branch information
TIHan committed Apr 5, 2019
commit a4839019c26b4c3f23272334e6c984cbc1cc51f3
46 changes: 16 additions & 30 deletions tests/fsharp/Compiler/CompilerAssert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace FSharp.Compiler.UnitTests
open System
open System.IO
open System.Text
open System.Diagnostics
open FSharp.Compiler.Text
open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.Interactive.Shell
Expand All @@ -16,6 +17,8 @@ module CompilerAssert =

let checker = FSharpChecker.Create()

let private config = TestFramework.initializeSuite ()

let private defaultProjectOptions =
{
ProjectFileName = "Z:\\test.fsproj"
Expand All @@ -32,20 +35,13 @@ module CompilerAssert =
Stamp = None
}

let private createFsiSession () =
// Intialize output and input streams
let sbOut = new StringBuilder()
let sbErr = new StringBuilder()
let inStream = new StringReader("")
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)

// Bmand line arguments & start FSI session
let argv = [| "C:\\fsi.exe" |]
let allArgs = Array.append argv [|"--noninteractive"|]

let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream)
let private exec exe args =
let startInfo = ProcessStartInfo(exe, String.concat " " args)
startInfo.RedirectStandardError <- true
startInfo.UseShellExecute <- false
use p = Process.Start(startInfo)
p.WaitForExit()
p.StandardOutput.ReadToEnd(), p.StandardError.ReadToEnd(), p.ExitCode

let Pass (source: string) =
let parseResults, fileAnswer = checker.ParseAndCheckFileInProject("test.fs", 0, SourceText.ofString source, defaultProjectOptions) |> Async.RunSynchronously
Expand Down Expand Up @@ -76,29 +72,19 @@ module CompilerAssert =
Assert.AreEqual(expectedErrorMsg, info.Message, "expectedErrorMsg")
)

let RunScript (source: string) (expectedOutput: 'T option) =
let RunScript (source: string) (expectedOutput: string) =
let tmp = Path.GetTempFileName()
let tmpFsx = Path.ChangeExtension(tmp, ".fsx")

try
File.WriteAllText(tmpFsx, source)
let output, errors, exitCode = exec config.FSI [tmpFsx]

use fsiSession = createFsiSession ()

let _, errors = fsiSession.EvalScriptNonThrowing(tmpFsx)

if errors.Length > 0 then
if errors.Length > 0 || exitCode <> 0 then
Assert.Fail(sprintf "Exit Code: %i" exitCode)
Assert.Fail(sprintf "%A" errors)

//match fsiSession.EvalExpressionNonThrowing(source) with
//| _, errors when errors.Length > 0 -> Assert.Fail(errors |> List.ofArray |> string)
//| Choice.Choice1Of2(result), _ ->
// match result, expectedOutput with
// | Some fsiValue, Some expectedOutput -> Assert.AreEqual(fsiValue.ReflectionValue, expectedOutput)
// | Some fsiValue, None -> Assert.AreEqual(null, fsiValue.ReflectionValue)
// | None, Some expectedOutput -> Assert.AreEqual(expectedOutput, null)
// | _ -> ()
//| _ -> ()

Assert.AreEqual(expectedOutput, output)

finally
try File.Delete(tmp) with | _ -> ()
Expand Down
13 changes: 7 additions & 6 deletions tests/fsharp/Compiler/Language/SpanTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ open NUnit.Framework
[<TestFixture>]
module SpanTests =

let x = 1

#if NET472
#else
[<Test>]
let Script_SpanForInDo() =
let references =
ILChecker.getPackageDlls "System.Memory" "4.5.0" "netstandard2.0" [ "System.Memory.dll" ]
|> List.fold (fun references dll -> references + "#r " + "\"\"\"" + dll + "\"\"\"\n") String.Empty
let script =
references +
"""
open System

Expand All @@ -25,7 +25,8 @@ let test () =
result.Add(item)
result.ToArray()

//test ()
test ()
"""

CompilerAssert.RunScript script (Some [|1;2;3;4|])
CompilerAssert.RunScript script ""
#endif