Skip to content

Commit

Permalink
add support for "<<OUTPUT" match
Browse files Browse the repository at this point in the history
  • Loading branch information
enricosada committed Jan 14, 2016
1 parent c74d920 commit fc0ac12
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 22 deletions.
54 changes: 46 additions & 8 deletions tests/fsharpqa/Source/run.fs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type ExpectedResults =
| CmdLine of string
| ExpectMatch of string * string
| ExpectNotMatch of string
| ExeOutputMatch of string list

// #############################################################
// # GetExpectedResults --
Expand Down Expand Up @@ -346,8 +347,19 @@ let GetExpectedResults cwd (srcListSepByBlank: string) =
let first,_ = src |> PlatformHelpers.splitAtFirst System.Char.IsWhiteSpace
src <- first //grab only the first source file

let srcPath = src |> getfullpath

//open SRC, $src or RunExit(TEST_FAIL, "GetExpectedResults::Can't open source file: $src: $!\n");
let SRC = System.IO.File.ReadLines (src |> getfullpath)
let SRC () = srcPath |> System.IO.File.ReadLines

// parse //<<Output
let Output =
SRC ()
|> Seq.skipWhile ((<>) "//<<Output")
|> List.ofSeq
|> function x :: xs -> xs | [] -> []
|> List.takeWhile ((<>) "//Output")
|> List.map (fun line -> line.TrimStart('/'))

//##########################################################

Expand All @@ -362,7 +374,7 @@ let GetExpectedResults cwd (srcListSepByBlank: string) =
Choice2Of2 e

//ITEM: while(<SRC>) {
SRC
SRC ()
|> Seq.map (fun line -> line.TrimStart()) //ignore whitespace before //
|> Seq.choose (fun line -> if line.StartsWith("//") then Some (line.TrimStart('/')) else None) //only comments `//`
|> Seq.choose (fun line ->
Expand Down Expand Up @@ -557,7 +569,12 @@ let GetExpectedResults cwd (srcListSepByBlank: string) =
|> List.choose (fun level -> seekHash |> Map.tryFind level)
|> List.fold max 0

succeed (levelMax, expects)
let expectExeOutput =
match Output with
| [] -> []
| l -> [ExeOutputMatch l]

succeed (levelMax, expects @ expectExeOutput)
| f :: fs ->
fs |> List.iter (log "test spec error: %s")
NUnitConf.genericError f
Expand Down Expand Up @@ -1059,8 +1076,6 @@ let runpl cwd initialEnvVars = attempt {
let! mType, dd = GetExpectedResults sources
let Type = mType

let Output = "" //TODO temp, need to check what is the real value

//#################################################################################
//# Compiling..........
//#
Expand Down Expand Up @@ -1276,7 +1291,7 @@ let runpl cwd initialEnvVars = attempt {
// # Running the EXE
// #
// # Now we scan the output of the EXE if we must
let checkRunningExe () = attempt {
let checkRunningExe expectedExeOutput () = attempt {

//my $status = TEST_PASS;
let status = TEST_PASS
Expand Down Expand Up @@ -1386,7 +1401,27 @@ let runpl cwd initialEnvVars = attempt {
// }
//}
//print("\n");
TODO "check output"
do! match expectedExeOutput with
| None ->
Success
| Some [] ->
Success
| Some (x :: xs) ->
let possible =
commandOutput.Split([| System.Environment.NewLine |], StringSplitOptions.RemoveEmptyEntries)
|> Array.skipWhile ((<>) x)
|> Array.truncate (x::xs |> List.length)
|> List.ofArray

if (x :: xs) = possible then
printfn "Output match: [passed]"
Success
else
printfn "Output match: [failed]"
printfn "Output:"
printfn "%s" commandOutput
NUnitConf.genericError "exe output doesnt match"


//RunExit(TEST_FAIL, "Generated Test EXE Failed \n") if ($ExitCode);
do! if (exitCode <> 0) then
Expand Down Expand Up @@ -1419,6 +1454,9 @@ let runpl cwd initialEnvVars = attempt {
}
//}

let expectedExeOutput =
dd |> List.tryPick (function ExeOutputMatch(l) -> Some l | _ -> None)

// # If this is a compile only run, call post command and exit
//if ($compileOnlyRun) {
return!
Expand All @@ -1427,7 +1465,7 @@ let runpl cwd initialEnvVars = attempt {
else attempt {
//if ($targetType == TARGET_EXE) {
do! if targetType = TARGET_EXE then
checkRunningExe ()
checkRunningExe expectedExeOutput ()
else
Success

Expand Down
70 changes: 56 additions & 14 deletions tests/fsharpqa/Source/test_simple.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ open NUnitConf
open PlatformHelpers
open FSharpTestSuiteTypes

let testContext = FSharpTestSuite.testContext
let envLstData = FSharpQATestSuite.envLstData

let runpl = attempt {

let { Directory = dir; Config = cfg } = testContext ()
let! vars = envLstData ()
let { Directory = dir; Config = cfg } = FSharpTestSuite.testContext ()
let! vars = FSharpQATestSuite.envLstData ()

printfn "Directory: %s" dir
printfn "%A" vars

let allVars =
Expand Down Expand Up @@ -64,22 +62,66 @@ module CompilerOptions_fsc_cliversion =
let cliversion () =
runpl |> check

//codepage
//crossoptimize
module CompilerOptions_fsc_codepage =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/codepage")>]
let codepage () =
runpl |> check

module CompilerOptions_fsc_crossoptimize =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/crossoptimize")>]
let crossoptimize () =
runpl |> check


module CompilerOptions_fsc_debug =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/debug")>]
let debug () =
runpl |> check

//dumpAllCommandLineOptions
//flaterrors
//gccerrors
//help
//highentropyva
//invalid
//lib
module CompilerOptions_fsc_dumpAllCommandLineOptions =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/dumpAllCommandLineOptions")>]
let dumpAllCommandLineOptions () =
runpl |> check

module CompilerOptions_fsc_flaterrors =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/flaterrors")>]
let flaterrors () =
runpl |> check

module CompilerOptions_fsc_gccerrors =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/gccerrors")>]
let gccerrors () =
runpl |> check

module CompilerOptions_fsc_help =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/help")>]
let help () =
runpl |> check

module CompilerOptions_fsc_highentropyva =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/highentropyva")>]
let highentropyva () =
runpl |> check

module CompilerOptions_fsc_invalid =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/invalid")>]
let invalid () =
runpl |> check

module CompilerOptions_fsc_lib =

[<Test; FSharpQASuiteTest("CompilerOptions/fsc/lib")>]
let lib () =
runpl |> check

module CompilerOptions_fsc_noframework =

Expand Down

0 comments on commit fc0ac12

Please sign in to comment.