Skip to content

Commit

Permalink
Merge pull request #507 from nazoking/fix/windows-test-appveyor
Browse files Browse the repository at this point in the history
fix appveyor test
  • Loading branch information
muuki88 committed Feb 25, 2015
2 parents 161f879 + 0bd8d8a commit 4467d31
Showing 1 changed file with 53 additions and 25 deletions.
78 changes: 53 additions & 25 deletions src/sbt-test/windows/test-bat-template/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ TaskKey[Unit]("check-script") <<= (stagingDirectory in Universal, name, streams)
val detailScript:File = {
val d = dir / "bin" / "detail.bat"
val out = new java.io.PrintWriter( d , "UTF-8")
out.print( scala.io.Source.fromFile(script).mkString.replaceAll("@echo off","@echo on & prompt \\$g ") )
out.print( scala.io.Source.fromFile(script).mkString.replaceAll("@echo off","echo on & prompt \\$g ") )
out.close
d
}
def crlf2cr(txt:String) = txt.trim.replaceAll("\\\r\\\n", "\n")
def checkOutputEnv(env:Map[String,String], expectedRC: Int, expected:String, args:String*) = {
def checkOutput(testName:String, args:String, expected:String, env:Map[String,String]=Map.empty, expectedRC: Int=0) = {
val pr = new StringBuilder()
val logger = ProcessLogger((o: String) => pr.append(o+"\n"),(e: String) => pr.append("error < " + e+"\n"))
val cmd = Seq("cmd", "/c", script.getAbsolutePath) ++ args
val cmd = Seq("cmd", "/c", script.getAbsolutePath+" "+args)
val result = Process(cmd, None, env.toSeq:_*) ! logger
if ( result != expectedRC ) {
pr.append("error code: " + result+"\n")
}
val output = crlf2cr(pr.toString)
if(result != expectedRC || output != expected.trim){
fails.append("\n---------------------------------\n")
fails.append(testName)
fails.append("\n---------------------------------\n")
fails.append("Failed to correctly run the main script!.\n")
fails.append("\""+cmd.mkString("\" \"")+"\"\n")
Expand All @@ -70,34 +72,60 @@ TaskKey[Unit]("check-script") <<= (stagingDirectory in Universal, name, streams)
fails.append(crlf2cr(pr.toString)+"\n")
fails.append("\n--detail-------------------------------\n")
pr.clear
Process(Seq("cmd", "/c", detailScript.getAbsolutePath) ++ args, None, env.toSeq:_*) ! logger
Process(Seq("cmd", "/c", detailScript.getAbsolutePath+" "+args), None, env.toSeq:_*) ! logger
fails.append(crlf2cr(pr.toString)+"\n")
}
if(debugOutFile.exists){
debugOutFile.delete()
}
}
def checkOutput(expectedRC: Int, expected:String, args:String*) = checkOutputEnv(Map.empty, expectedRC, expected, args:_*)
checkOutput(0, "arg #0 is [OK]\nSUCCESS!", "OK")
checkOutput(0, "arg #0 is [OK]\nproperty(test.hoge) is [huga]\nSUCCESS!", "-Dtest.hoge=\"huga\"", "OK")
checkOutputEnv(Map("show-vmargs"->"true"), 0, "arg #0 is [OK]\nvmarg #0 is [-Xms6m]\nSUCCESS!","-J-Xms6m", "OK")
checkOutputEnv(Map("show-vmargs"->"true"), 0, "arg #0 is [first]\narg #1 is [-XX]\narg #2 is [last]\nproperty(test.hoge) is [huga]\nvmarg #0 is [-Dtest.hoge=huga]\nvmarg #1 is [-Xms6m]\nSUCCESS!",
"first", "-Dtest.hoge=\"huga\"", "-J-Xms6m", "-XX", "last")
// include space
checkOutput(0, "arg #0 is [C:\\Program Files\\Java]\nproperty(test.hoge) is [C:\\Program Files\\Java]\nSUCCESS!",
"-Dtest.hoge=C:\\Program Files\\Java", "C:\\Program Files\\Java")
// split "include symbols"
checkOutput(0, "property(test.hoge) is [\\[]!< >%]\nSUCCESS!", "\"-Dtest.hoge=\\[]!< >%\"")
checkOutput(0, "arg #0 is [\\[]!< >%]\nSUCCESS!", "\\[]!< >%")
checkOutput(0, "property(test.huga) is [\\[]!<>%]\nSUCCESS!", "-Dtest.huga=\"\\[]!<>%\"")
// include symbols
checkOutput(0, "arg #0 is [\\[]!< >%]\nproperty(test.hoge) is [\\[]!< >%]\nproperty(test.huga) is [\\[]!<>%]\nSUCCESS!",
"\"-Dtest.hoge=\\[]!< >%\"", "\\[]!< >%", "-Dtest.huga=\"\\[]!<>%\"")
// include space and double-quote is failed...
checkOutput("normal argmument",
"OK",
"arg #0 is [OK]\nSUCCESS!")
checkOutput("with -D",
"-Dtest.hoge=\"huga\" OK",
"arg #0 is [OK]\nproperty(test.hoge) is [huga]\nSUCCESS!")
checkOutput("with -J java-opt",
"-J-Xms6m OK",
"arg #0 is [OK]\nvmarg #0 is [-Xms6m]\nSUCCESS!",
Map("show-vmargs"->"true"))
checkOutput("complex",
"first -Dtest.hoge=\"huga\" -J-Xms6m -XX last",
"arg #0 is [first]\narg #1 is [-XX]\narg #2 is [last]\nproperty(test.hoge) is [huga]\nvmarg #0 is [-Dtest.hoge=huga]\nvmarg #1 is [-Xms6m]\nSUCCESS!",
Map("show-vmargs"->"true"))
checkOutput("include space",
"""-Dtest.hoge="C:\Program Files\Java" "C:\Program Files\Java" """,
"arg #0 is [C:\\Program Files\\Java]\nproperty(test.hoge) is [C:\\Program Files\\Java]\nSUCCESS!")
checkOutput("include symbols on -D",
"\"-Dtest.hoge=\\[]!< >%\"",
"property(test.hoge) is [\\[]!< >%]\nSUCCESS!")
checkOutput("include symbols on normal args",
""" "\[]!< >%" """,
"arg #0 is [\\[]!< >%]\nSUCCESS!")
checkOutput("include symbols with double quote",
"-Dtest.huga=\"[]!<>%\"",
"property(test.huga) is [[]!<>%]\nSUCCESS!")
checkOutput("include symbols with double quote2",
""" "-Dtest.hoge=\[]!< >%" "\[]!< >%" -Dtest.huga="\[]!<>%" """,
"arg #0 is [\\[]!< >%]\nproperty(test.hoge) is [\\[]!< >%]\nproperty(test.huga) is [\\[]!<>%]\nSUCCESS!")
// can't success include double-quote. arguments pass from Process(Seq("-Da=xx\"yy", "aa\"bb")) is parsed (%1="-Da", %2="xx\"yy aa\"bb") by cmd.exe ...
//checkOutput(0, "arg #0 is [xx\"yy]\nproperty(test.hoge) is [aa\"bb]\nvmarg #0 is [-Dtest.hoge=aa\"bb]\nSUCCESS!", "-Dtest.hoge=aa\"bb", "xx\"yy")
checkOutputEnv(Map("return-code"->"1"), 1, "arg #0 is [RC1]\nFAILURE!", "RC1")
checkOutputEnv(Map("return-code"->"2"), 2, "arg #0 is [RC2]\nFAILURE!", "RC2")
checkOutputEnv(Map("return-code"->"-1"), -1, "arg #0 is [RC-1]\nFAILURE!", "RC-1")
//checkOutput("include space and double-quote",
// "-Dtest.hoge=aa\"bb xx\"yy",
// "arg #0 is [xx\"yy]\nproperty(test.hoge) is [aa\"bb]\nvmarg #0 is [-Dtest.hoge=aa\"bb]\nSUCCESS!")
checkOutput("return-cord not 0",
"RC1",
"arg #0 is [RC1]\nFAILURE!",
Map("return-code"->"1"),
1)
checkOutput("return-cord not 0 and 1",
"RC2",
"arg #0 is [RC2]\nFAILURE!",
Map("return-code"->"2"),
2)
checkOutput("return-code negative",
"RC-1",
"arg #0 is [RC-1]\nFAILURE!",
Map("return-code"->"-1"),
-1)
assert(fails.toString == "", fails.toString)
}

0 comments on commit 4467d31

Please sign in to comment.