@@ -41,21 +41,23 @@ TaskKey[Unit]("check-script") <<= (stagingDirectory in Universal, name, streams)
41
41
val detailScript : File = {
42
42
val d = dir / " bin" / " detail.bat"
43
43
val out = new java.io.PrintWriter ( d , " UTF-8" )
44
- out.print( scala.io.Source .fromFile(script).mkString.replaceAll(" @echo off" ," @ echo on & prompt \\ $g " ) )
44
+ out.print( scala.io.Source .fromFile(script).mkString.replaceAll(" @echo off" ," echo on & prompt \\ $g " ) )
45
45
out.close
46
46
d
47
47
}
48
48
def crlf2cr (txt: String ) = txt.trim.replaceAll(" \\\r\\\n " , " \n " )
49
- def checkOutputEnv (env : Map [ String ,String ], expectedRC : Int , expected: String , args : String * ) = {
49
+ def checkOutput (testName : String , args : String , expected: String , env : Map [ String , String ] = Map .empty, expectedRC : Int = 0 ) = {
50
50
val pr = new StringBuilder ()
51
51
val logger = ProcessLogger ((o : String ) => pr.append(o+ " \n " ),(e : String ) => pr.append(" error < " + e+ " \n " ))
52
- val cmd = Seq (" cmd" , " /c" , script.getAbsolutePath) ++ args
52
+ val cmd = Seq (" cmd" , " /c" , script.getAbsolutePath+ " " + args)
53
53
val result = Process (cmd, None , env.toSeq:_* ) ! logger
54
54
if ( result != expectedRC ) {
55
55
pr.append(" error code: " + result+ " \n " )
56
56
}
57
57
val output = crlf2cr(pr.toString)
58
58
if (result != expectedRC || output != expected.trim){
59
+ fails.append(" \n ---------------------------------\n " )
60
+ fails.append(testName)
59
61
fails.append(" \n ---------------------------------\n " )
60
62
fails.append(" Failed to correctly run the main script!.\n " )
61
63
fails.append(" \" " + cmd.mkString(" \" \" " )+ " \"\n " )
@@ -70,34 +72,60 @@ TaskKey[Unit]("check-script") <<= (stagingDirectory in Universal, name, streams)
70
72
fails.append(crlf2cr(pr.toString)+ " \n " )
71
73
fails.append(" \n --detail-------------------------------\n " )
72
74
pr.clear
73
- Process (Seq (" cmd" , " /c" , detailScript.getAbsolutePath) ++ args, None , env.toSeq:_* ) ! logger
75
+ Process (Seq (" cmd" , " /c" , detailScript.getAbsolutePath+ " " + args) , None , env.toSeq:_* ) ! logger
74
76
fails.append(crlf2cr(pr.toString)+ " \n " )
75
77
}
76
78
if (debugOutFile.exists){
77
79
debugOutFile.delete()
78
80
}
79
81
}
80
- def checkOutput (expectedRC : Int , expected: String , args: String * ) = checkOutputEnv(Map .empty, expectedRC, expected, args:_* )
81
- checkOutput(0 , " arg #0 is [OK]\n SUCCESS!" , " OK" )
82
- checkOutput(0 , " arg #0 is [OK]\n property(test.hoge) is [huga]\n SUCCESS!" , " -Dtest.hoge=\" huga\" " , " OK" )
83
- checkOutputEnv(Map (" show-vmargs" -> " true" ), 0 , " arg #0 is [OK]\n vmarg #0 is [-Xms6m]\n SUCCESS!" ," -J-Xms6m" , " OK" )
84
- checkOutputEnv(Map (" show-vmargs" -> " true" ), 0 , " arg #0 is [first]\n arg #1 is [-XX]\n arg #2 is [last]\n property(test.hoge) is [huga]\n vmarg #0 is [-Dtest.hoge=huga]\n vmarg #1 is [-Xms6m]\n SUCCESS!" ,
85
- " first" , " -Dtest.hoge=\" huga\" " , " -J-Xms6m" , " -XX" , " last" )
86
- // include space
87
- checkOutput(0 , " arg #0 is [C:\\ Program Files\\ Java]\n property(test.hoge) is [C:\\ Program Files\\ Java]\n SUCCESS!" ,
88
- " -Dtest.hoge=C:\\ Program Files\\ Java" , " C:\\ Program Files\\ Java" )
89
- // split "include symbols"
90
- checkOutput(0 , " property(test.hoge) is [\\ []!< >%]\n SUCCESS!" , " \" -Dtest.hoge=\\ []!< >%\" " )
91
- checkOutput(0 , " arg #0 is [\\ []!< >%]\n SUCCESS!" , " \\ []!< >%" )
92
- checkOutput(0 , " property(test.huga) is [\\ []!<>%]\n SUCCESS!" , " -Dtest.huga=\"\\ []!<>%\" " )
93
- // include symbols
94
- checkOutput(0 , " arg #0 is [\\ []!< >%]\n property(test.hoge) is [\\ []!< >%]\n property(test.huga) is [\\ []!<>%]\n SUCCESS!" ,
95
- " \" -Dtest.hoge=\\ []!< >%\" " , " \\ []!< >%" , " -Dtest.huga=\"\\ []!<>%\" " )
96
- // include space and double-quote is failed...
82
+ checkOutput(" normal argmument" ,
83
+ " OK" ,
84
+ " arg #0 is [OK]\n SUCCESS!" )
85
+ checkOutput(" with -D" ,
86
+ " -Dtest.hoge=\" huga\" OK" ,
87
+ " arg #0 is [OK]\n property(test.hoge) is [huga]\n SUCCESS!" )
88
+ checkOutput(" with -J java-opt" ,
89
+ " -J-Xms6m OK" ,
90
+ " arg #0 is [OK]\n vmarg #0 is [-Xms6m]\n SUCCESS!" ,
91
+ Map (" show-vmargs" -> " true" ))
92
+ checkOutput(" complex" ,
93
+ " first -Dtest.hoge=\" huga\" -J-Xms6m -XX last" ,
94
+ " arg #0 is [first]\n arg #1 is [-XX]\n arg #2 is [last]\n property(test.hoge) is [huga]\n vmarg #0 is [-Dtest.hoge=huga]\n vmarg #1 is [-Xms6m]\n SUCCESS!" ,
95
+ Map (" show-vmargs" -> " true" ))
96
+ checkOutput(" include space" ,
97
+ """ -Dtest.hoge="C:\Program Files\Java" "C:\Program Files\Java" """ ,
98
+ " arg #0 is [C:\\ Program Files\\ Java]\n property(test.hoge) is [C:\\ Program Files\\ Java]\n SUCCESS!" )
99
+ checkOutput(" include symbols on -D" ,
100
+ " \" -Dtest.hoge=\\ []!< >%\" " ,
101
+ " property(test.hoge) is [\\ []!< >%]\n SUCCESS!" )
102
+ checkOutput(" include symbols on normal args" ,
103
+ """ "\[]!< >%" """ ,
104
+ " arg #0 is [\\ []!< >%]\n SUCCESS!" )
105
+ checkOutput(" include symbols with double quote" ,
106
+ " -Dtest.huga=\" []!<>%\" " ,
107
+ " property(test.huga) is [[]!<>%]\n SUCCESS!" )
108
+ checkOutput(" include symbols with double quote2" ,
109
+ """ "-Dtest.hoge=\[]!< >%" "\[]!< >%" -Dtest.huga="\[]!<>%" """ ,
110
+ " arg #0 is [\\ []!< >%]\n property(test.hoge) is [\\ []!< >%]\n property(test.huga) is [\\ []!<>%]\n SUCCESS!" )
97
111
// 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 ...
98
- // 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")
99
- checkOutputEnv(Map (" return-code" -> " 1" ), 1 , " arg #0 is [RC1]\n FAILURE!" , " RC1" )
100
- checkOutputEnv(Map (" return-code" -> " 2" ), 2 , " arg #0 is [RC2]\n FAILURE!" , " RC2" )
101
- checkOutputEnv(Map (" return-code" -> " -1" ), - 1 , " arg #0 is [RC-1]\n FAILURE!" , " RC-1" )
112
+ // checkOutput("include space and double-quote",
113
+ // "-Dtest.hoge=aa\"bb xx\"yy",
114
+ // "arg #0 is [xx\"yy]\nproperty(test.hoge) is [aa\"bb]\nvmarg #0 is [-Dtest.hoge=aa\"bb]\nSUCCESS!")
115
+ checkOutput(" return-cord not 0" ,
116
+ " RC1" ,
117
+ " arg #0 is [RC1]\n FAILURE!" ,
118
+ Map (" return-code" -> " 1" ),
119
+ 1 )
120
+ checkOutput(" return-cord not 0 and 1" ,
121
+ " RC2" ,
122
+ " arg #0 is [RC2]\n FAILURE!" ,
123
+ Map (" return-code" -> " 2" ),
124
+ 2 )
125
+ checkOutput(" return-code negative" ,
126
+ " RC-1" ,
127
+ " arg #0 is [RC-1]\n FAILURE!" ,
128
+ Map (" return-code" -> " -1" ),
129
+ - 1 )
102
130
assert(fails.toString == " " , fails.toString)
103
131
}
0 commit comments