Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme committed Oct 18, 2016
1 parent f570f4c commit eb73655
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 67 deletions.
22 changes: 9 additions & 13 deletions tests/fsharp/core/quotes/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Core_quotes
#endif
#light

#if Portable
#else
#if !Portable
#r "cslib.dll"
#endif

Expand All @@ -24,8 +23,7 @@ let check s v1 v2 =
report_failure s


#if NetCore
#else
#if !NetCore
let argv = System.Environment.GetCommandLineArgs()
let SetCulture() =
if argv.Length > 2 && argv.[1] = "--culture" then
Expand Down Expand Up @@ -107,8 +105,7 @@ module TypedTest = begin
test "check ~UInt64" ((<@ "1" @> |> (function UInt64 _ -> false | _ -> true)))
test "check ~String" ((<@ 1 @> |> (function String "1" -> false | _ -> true)))

#if FSHARP_CORE_31
#else
#if !FSHARP_CORE_31
test "check Decimal" ((<@ 1M @> |> (function Decimal 1M -> true | _ -> false)))
test "check ~Decimal" ((<@ "1" @> |> (function Decimal _ -> false | _ -> true)))
test "check ~Decimal neither" ((<@ 1M + 1M @> |> (function Decimal _ -> false | _ -> true)))
Expand Down Expand Up @@ -531,7 +528,7 @@ module TypedTest = begin
| _ -> false
end

#if FSHARP_CORE_31
#if FSHARP_CORE_31 || Portable
#else
test "check accesses to readonly fields in ReflectedDefinitions"
begin
Expand Down Expand Up @@ -1906,8 +1903,7 @@ module TestQuotationOfCOnstructors =

| _ -> false)

#if NetCore
#else
#if !NetCore
// Also test getting the reflected definition for private members implied by "let f() = ..." bindings
let fMethod = (typeof<MyClassWithAsLetMethod>.GetMethod("f", Reflection.BindingFlags.Instance ||| Reflection.BindingFlags.Public ||| Reflection.BindingFlags.NonPublic))

Expand Down Expand Up @@ -2237,8 +2233,7 @@ module ReflectedDefinitionOnTypesWithImplicitCodeGen =
#endif
check "celnwer35" (Quotations.Expr.TryGetReflectedDefinition(m).IsNone) true

#if Portable
#else
#if !Portable
module BasicUsingTEsts =
let q1() =
let a = ResizeArray<_>()
Expand Down Expand Up @@ -2410,8 +2405,7 @@ module QuotationOfResizeArrayIteration =



#if FSHARP_CORE_31
#else
#if !FSHARP_CORE_31
module TestAutoQuoteAtStaticMethodCalls =
open Microsoft.FSharp.Quotations

Expand Down Expand Up @@ -2727,8 +2721,10 @@ module PartialApplicationLeadToInvalidCodeWhenOptimized =

f ()

#if !NetCore
module TestAssemblyAttributes =
let attributes = System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false)
#endif

let aa =
if not failures.IsEmpty then (printfn "Test Failed, failures = %A" failures; exit 1)
Expand Down
96 changes: 44 additions & 52 deletions tests/fsharp/core/tests_core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -783,20 +783,21 @@ let lift p = singleTestBuildAndRun p

module ``Load-Script`` =

let ``script > a 2>b`` cfg dir (stdout,stderr) = attempt {

let stdoutPath = stdout |> Commands.getfullpath cfg.Directory
let stderrPath = stderr |> Commands.getfullpath cfg.Directory
[<Test; FSharpSuiteTest("core/load-script")>]
let ``load-script`` () = check (attempt {
let cfg = FSharpTestSuite.testConfig ()

let execToOut cfg p = Command.exec cfg.Directory cfg.EnvironmentVariables { Output = OutputAndError(Append(stdoutPath), Append(stderrPath)); Input = None; } p >> alwaysSuccess
// script > out.txt 2>&1
let stdoutPath = "out.stdout.txt" |> getfullpath cfg
let stderrPath = "out.stderr.txt" |> getfullpath cfg
let stderrBaseline = "out.stderr.bsl" |> getfullpath cfg
let stdoutBaseline = "out.stdout.bsl" |> getfullpath cfg

let type_append_tofile from = Commands.type_append_tofile dir from stdoutPath
let echo text = Commands.echo_append_tofile dir text stdoutPath

let type_append_tofile from = Commands.type_append_tofile cfg.Directory from stdoutPath
let echo text = Commands.echo_append_tofile cfg.Directory text stdoutPath

let fileExists = Commands.fileExists cfg.Directory >> Option.isSome
let del = Commands.rm dir


File.WriteAllText(stdoutPath, "")
File.WriteAllText(stderrPath, "")
Expand All @@ -808,98 +809,90 @@ module ``Load-Script`` =
// echo Test 1=================================================
echo "Test 1================================================="
// "%FSC%" 3.fsx --nologo
do! fsc cfg "--nologo" ["3.fsx"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo" ["3.fsx"]
// 3.exe
do! execToOut cfg ("."/"3.exe") ""
do! execToOutAndIgnoreExitCode cfg stdoutPath stderrPath ("."/"3.exe") ""
// del 3.exe
del "3.exe"
rm cfg "3.exe"
// echo Test 2=================================================
echo "Test 2================================================="
// "%FSI%" 3.fsx
do! fsi cfg "" ["3.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["3.fsx"]
// echo Test 3=================================================
echo "Test 3================================================="
// "%FSI%" --nologo < pipescr
do! ``fsi < success`` cfg stdoutPath stderrPath "--nologo" "pipescr"
do! fsiFromInToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo" "pipescr"
// echo.
// echo Test 4=================================================
echo "Test 4================================================="
// "%FSI%" usesfsi.fsx
do! fsi cfg "" ["usesfsi.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["usesfsi.fsx"]
// echo Test 5=================================================
echo "Test 5================================================="
// "%FSC%" usesfsi.fsx --nologo
do! fsc cfg "--nologo" ["usesfsi.fsx"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo" ["usesfsi.fsx"]
// echo Test 6=================================================
echo "Test 6================================================="
// "%FSC%" usesfsi.fsx --nologo -r FSharp.Compiler.Interactive.Settings
do! fsc cfg "--nologo -r FSharp.Compiler.Interactive.Settings" ["usesfsi.fsx"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo -r FSharp.Compiler.Interactive.Settings" ["usesfsi.fsx"]
// echo Test 7=================================================
echo "Test 7================================================="
// "%FSI%" 1.fsx 2.fsx 3.fsx
do! fsi cfg "" ["1.fsx";"2.fsx";"3.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["1.fsx";"2.fsx";"3.fsx"]
// echo Test 8=================================================
echo "Test 8================================================="
// "%FSI%" 3.fsx 2.fsx 1.fsx
do! fsi cfg "" ["3.fsx";"2.fsx";"1.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["3.fsx";"2.fsx";"1.fsx"]
// echo Test 9=================================================
echo "Test 9================================================="
// "%FSI%" multiple-load-1.fsx
do! fsi cfg "" ["multiple-load-1.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["multiple-load-1.fsx"]
// echo Test 10=================================================
echo "Test 10================================================="
// "%FSI%" multiple-load-2.fsx
do! fsi cfg "" ["multiple-load-2.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["multiple-load-2.fsx"]
// echo Test 11=================================================
echo "Test 11================================================="
// "%FSC%" FlagCheck.fs --nologo
do! fsc cfg "--nologo" ["FlagCheck.fs"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo" ["FlagCheck.fs"]
// FlagCheck.exe
do! exec cfg ("."/"FlagCheck.exe") ""
// del FlagCheck.exe
del "FlagCheck.exe"
do! execToOutAndIgnoreExitCode cfg stdoutPath stderrPath ("."/"FlagCheck.exe") ""
// rm cfg FlagCheck.exe
rm cfg "FlagCheck.exe"
// echo Test 12=================================================
echo "Test 12================================================="
// "%FSC%" FlagCheck.fsx --nologo
do! fsc cfg "-o FlagCheckScript.exe --nologo" ["FlagCheck.fsx"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "-o FlagCheckScript.exe --nologo" ["FlagCheck.fsx"]
// FlagCheck.exe
do! exec cfg ("."/"FlagCheckScript.exe") ""
// del FlagCheck.exe
del "FlagCheckScript.exe"
do! execToOutAndIgnoreExitCode cfg stdoutPath stderrPath ("."/"FlagCheckScript.exe") ""
// rm cfg FlagCheck.exe
rm cfg "FlagCheckScript.exe"
// echo Test 13=================================================
echo "Test 13================================================="
// "%FSI%" load-FlagCheckFs.fsx
do! fsi cfg "" ["load-FlagCheckFs.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["load-FlagCheckFs.fsx"]
// echo Test 14=================================================
echo "Test 14================================================="
// "%FSI%" FlagCheck.fsx
do! fsi cfg "" ["FlagCheck.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["FlagCheck.fsx"]
// echo Test 15=================================================
echo "Test 15================================================="
// "%FSI%" ProjectDriver.fsx
do! fsi cfg "" ["ProjectDriver.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["ProjectDriver.fsx"]
// echo Test 16=================================================
echo "Test 16================================================="
// "%FSC%" ProjectDriver.fsx --nologo
do! fsc cfg "--nologo" ["ProjectDriver.fsx"]
do! fscToOutIgnoreExitCode cfg stdoutPath stderrPath "--nologo" ["ProjectDriver.fsx"]
// ProjectDriver.exe
do! exec cfg ("."/"ProjectDriver.exe") ""
// del ProjectDriver.exe
del "ProjectDriver.exe"
do! execToOutAndIgnoreExitCode cfg stdoutPath stderrPath ("."/"ProjectDriver.exe") ""
// rm cfg ProjectDriver.exe
rm cfg "ProjectDriver.exe"
// echo Test 17=================================================
echo "Test 17================================================="
// "%FSI%" load-IncludeNoWarn211.fsx
do! fsi cfg "" ["load-IncludeNoWarn211.fsx"]
do! fsiToOutIgnoreExitCode cfg stdoutPath stderrPath "" ["load-IncludeNoWarn211.fsx"]
// echo Done ==================================================
echo "Done =================================================="
}

[<Test; FSharpSuiteTest("core/load-script")>]
let ``load-script`` () = check (attempt {
let cfg = FSharpTestSuite.testConfig ()

// script > out.txt 2>&1
do! ``script > a 2>b`` cfg cfg.Directory ("out.stdout.txt", "out.stderr.txt")

// if NOT EXIST out.bsl COPY out.txt
ignore "useless, first run, same as use an empty file"
Expand All @@ -910,20 +903,20 @@ module ``Load-Script`` =
let contents = System.Text.RegularExpressions.Regex.Replace(text, System.Text.RegularExpressions.Regex.Escape(cfg.Directory), dummyPath)
File.WriteAllText(f, contents)

normalizePaths (getfullpath cfg "out.stdout.txt")
normalizePaths (getfullpath cfg "out.stderr.txt")
normalizePaths stdoutPath
normalizePaths stderrPath

let! diffs = fsdiff cfg (getfullpath cfg "out.stdout.txt") (getfullpath cfg "out.stdout.bsl")
let! diffs = fsdiff cfg stdoutPath stdoutBaseline

do! match diffs with
| [] -> Success
| _ -> NUnitConf.genericError (sprintf "'%s' and '%s' differ; %A" (getfullpath cfg "out.stdout.txt") (getfullpath cfg "out.stdout.bsl") diffs)
| _ -> NUnitConf.genericError (sprintf "'%s' and '%s' differ; %A" stdoutPath stdoutBaseline diffs)

let! diffs = fsdiff cfg (getfullpath cfg "out.stderr.txt") (getfullpath cfg "out.stderr.bsl")
let! diffs = fsdiff cfg stderrPath stderrBaseline

do! match diffs with
| [] -> Success
| _ -> NUnitConf.genericError (sprintf "'%s' and '%s' differ; %A" (getfullpath cfg "out.stderr.txt") (getfullpath cfg "out.stderr.bsl") diffs)
| _ -> NUnitConf.genericError (sprintf "'%s' and '%s' differ; %A" stderrPath stderrBaseline diffs)

})

Expand Down Expand Up @@ -1163,7 +1156,6 @@ let queriesNullableOperators () = check (attempt {
// echo TestC
log "TestC"

// if exist test.ok (del /f /q test.ok)
use testOkFile = fileguard cfg "test.ok"
// "%FSI%" %fsi_flags% test.fsx
do! fsi cfg "%s" cfg.fsi_flags ["test.fsx"]
Expand Down
8 changes: 6 additions & 2 deletions tests/fsharp/nunitConf.fs
Original file line number Diff line number Diff line change
Expand Up @@ -383,25 +383,29 @@ module Command =
{ RedirectOutput = None; RedirectError = None; RedirectInput = None }
|> (outF (inF exec))

let alwaysSuccess _ = Success ()

let execToOutAndIgnoreExitCode cfg stdoutPath stderrPath p = Command.exec cfg.Directory cfg.EnvironmentVariables { Output = OutputAndError(Append(stdoutPath), Append(stderrPath)); Input = None; } p >> alwaysSuccess
let exec cfg p = Command.exec cfg.Directory cfg.EnvironmentVariables { Output = Inherit; Input = None; } p >> checkResult
let execIn cfg workDir p = Command.exec workDir cfg.EnvironmentVariables { Output = Inherit; Input = None; } p >> checkResult

let alwaysSuccess _ = Success ()

let inline fsc cfg arg = Printf.ksprintf (Commands.fsc (exec cfg) cfg.FSC) arg
let inline fscIn cfg workDir arg = Printf.ksprintf (Commands.fsc (execIn cfg workDir) cfg.FSC) arg
let inline fscToOutIgnoreExitCode cfg stdoutPath stderrPath arg = Printf.ksprintf (Commands.fsc (execToOutAndIgnoreExitCode cfg stdoutPath stderrPath) cfg.FSC) arg
let inline csc cfg arg = Printf.ksprintf (Commands.csc (exec cfg) cfg.CSC) arg
let inline peverify cfg = Commands.peverify (exec cfg) cfg.PEVERIFY "/nologo"
let inline peverifyWithArgs cfg args = Commands.peverify (exec cfg) cfg.PEVERIFY args
let inline fsi cfg = Printf.ksprintf (Commands.fsi (exec cfg) cfg.FSI)
let inline fsiToOutIgnoreExitCode cfg stdoutPath stderrPath = Printf.ksprintf (Commands.fsi (execToOutAndIgnoreExitCode cfg stdoutPath stderrPath) cfg.FSI)
let inline fileguard cfg = (Commands.getfullpath cfg.Directory) >> FileGuard.create
let inline getfullpath cfg = Commands.getfullpath cfg.Directory
let inline resgen cfg = Printf.ksprintf (Commands.resgen (exec cfg) cfg.RESGEN)
let msbuild cfg = Printf.ksprintf (Commands.msbuild (exec cfg) (cfg.MSBUILD.Value))
let ``exec <`` cfg l p = Command.exec cfg.Directory cfg.EnvironmentVariables { Output = Inherit; Input = Some(RedirectInput(l)) } p >> checkResult
let ``fsi <`` cfg = Printf.ksprintf (fun flags l -> Commands.fsi (``exec <`` cfg l) cfg.FSI flags [])
let ``exec < success`` cfg stdoutPath stderrPath l p = Command.exec cfg.Directory cfg.EnvironmentVariables { Output = OutputAndError(Append(stdoutPath), Append(stderrPath)); Input = Some(RedirectInput(l)) } p >> alwaysSuccess
let ``fsi < success`` cfg stdoutPath stderrPath = Printf.ksprintf (fun flags l -> Commands.fsi (``exec < success`` cfg stdoutPath stderrPath l) cfg.FSI flags [])
let fsiFromInToOutIgnoreExitCode cfg stdoutPath stderrPath = Printf.ksprintf (fun flags l -> Commands.fsi (``exec < success`` cfg stdoutPath stderrPath l) cfg.FSI flags [])
let rm cfg x = Commands.rm cfg.Directory x
let mkdir cfg = Commands.mkdir_p cfg.Directory

Expand Down

0 comments on commit eb73655

Please sign in to comment.