3 ' vbslib ver3.00 Sep.22, 2009
\r
4 ' Copyright (c) 2008-2009, T's-Neko at Sage Plaisir 21 (Japan)
\r
5 ' All rights reserved. Based on 3-clause BSD license.
\r
8 Dim g_TestScript_Path
\r
9 g_TestScript_Path = g_SrcPath
\r
13 Dim g_Test, g_echo_on
\r
15 Function InitializeModule
\r
17 Set g_Test = New TestScript : ErrCheck
\r
19 Dim g_InitializeModule
\r
20 Set g_InitializeModule = GetRef( "InitializeModule" )
\r
22 Const Err_TestPass = 21
\r
23 Const Err_TestSkip = 22
\r
24 Const Err_TestFail = 23
\r
27 '********************************************************************************
\r
28 ' <<< [call_vbs_t] >>>
\r
29 ' - The difference of call_vbs is not depend on vbslib.
\r
30 ' - path, func as string, param as variant
\r
31 '********************************************************************************
\r
32 Function call_vbs_t( ByVal path, ByVal func, param )
\r
33 Dim oldDir, f, funcX, in_interpret, en, ed, es
\r
35 in_interpret = False
\r
36 oldDir = g_sh.CurrentDirectory
\r
38 path = g_sh.ExpandEnvironmentStrings( path )
\r
39 path = g_fs.GetAbsolutePathName( path )
\r
41 '-----------------------------------------
\r
46 On Error Resume Next
\r
48 g_sh.CurrentDirectory = g_fs.GetParentFolderName( path )
\r
49 If Err=0 Then Set f = g_fs.OpenTextFile( g_fs.GetFileName( path ) )
\r
50 If Err=0 Then in_interpret = True : ExecuteGlobal f.ReadAll()
\r
51 If Err=&h411 Then in_interpret = False : Err.Clear ' Ignore symbol override error
\r
52 If Err=0 Then in_interpret = False
\r
53 If Err=0 Then Set funcX = GetRef( func )
\r
55 en = Err.Number : es = Err.Source : ed = Err.Description : On Error GoTo 0
\r
57 If in_interpret Then
\r
58 ed = ed + " Syntax Error in """ + g_fs.GetFileName( path ) _
\r
59 + """. Please double click """ _
\r
60 + g_fs.GetFileName( path ) + """."
\r
62 If en = &h35 Then ed = "Not found file '" + path
\r
63 If en = 5 Then ed = "Not found func name '" + func + "' in " + path
\r
68 '-----------------------------------------
\r
71 On Error Resume Next
\r
72 call_vbs_t = funcX( param )
\r
73 en = Err.Number : es = Err.Source : ed = Err.Description : On Error GoTo 0
\r
77 '-----------------------------------------
\r
79 g_sh.CurrentDirectory = oldDir
\r
82 If en <> 0 Then Err.Raise en, es, ed
\r
88 '********************************************************************************
\r
89 ' <<< [call_vbs_d] >>>
\r
90 '********************************************************************************
\r
91 Function call_vbs_d( ByVal path, ByVal func, param )
\r
92 Dim oldDir, f, funcX, in_call, in_interpret, en
\r
94 oldDir = g_sh.CurrentDirectory
\r
96 path = g_sh.ExpandEnvironmentStrings( path )
\r
97 path = g_fs.GetAbsolutePathName( path )
\r
100 g_sh.CurrentDirectory = g_fs.GetParentFolderName( path )
\r
102 Set f = g_fs.OpenTextFile( g_fs.GetFileName( path ) )
\r
103 ExecuteGlobal f.ReadAll()
\r
105 Set funcX = GetRef( func ) ' If error, Not found func symbol
\r
106 call_vbs_d = funcX( param )
\r
107 g_sh.CurrentDirectory = oldDir
\r
114 '*-------------------------------------------------------------------------*
\r
115 '*
\81\9f<<<< [TestScript] Class >>>> */
\r
116 '*-------------------------------------------------------------------------*
\r
119 Public m_nPass ' as integer
\r
120 Public m_nSkip ' as integer
\r
121 Public m_nFail ' as integer
\r
122 Public m_Log ' as Text File
\r
123 Public m_DefLogFName ' as string
\r
124 Public m_MemLog ' as string. Empty=disabled, (""or string)=enabled
\r
125 Public m_Path ' as string
\r
126 Public m_ManualTests() ' as string
\r
127 Public m_ManualTestsPath() ' as string
\r
128 Public m_Debug ' as boolean
\r
129 Public m_Pass ' as boolean
\r
131 '********************************************************************************
\r
132 ' <<< [TestScript::Class_Initialize] >>>
\r
133 '********************************************************************************
\r
134 Private Sub Class_Initialize
\r
135 m_DefLogFName = "Test_logs.txt"
\r
137 ReDim m_ManualTests(-1)
\r
138 ReDim m_ManualTestsPath(-1)
\r
143 '********************************************************************************
\r
144 ' <<< [TestScript::Class_Terminate] >>>
\r
145 '********************************************************************************
\r
146 Private Sub Class_Terminate
\r
147 If Not IsEmpty( m_Log ) Then Finish
\r
152 '********************************************************************************
\r
153 ' <<< [TestScript::Start] >>>
\r
154 '********************************************************************************
\r
156 Dim sub_test ' Boolean
\r
158 Set m_Log = g_fs.CreateTextFile( m_DefLogFName, True, (g_TextFileCreateFormat = F_Unicode) )
\r
160 ReDim m_ManualTests(-1)
\r
161 ReDim m_ManualTestsPath(-1)
\r
164 If WScript.Arguments.Count >= 1 Then
\r
165 If WScript.Arguments(0) = "-sub_test" Then sub_test = True
\r
168 If Not sub_test Then echo "Test Start : " & g_fs.GetFileName( Wscript.ScriptFullName )
\r
177 '********************************************************************************
\r
178 ' <<< [TestScript::Do_] >>>
\r
179 '********************************************************************************
\r
180 Public Sub Do_( ByVal vbs_path, ByVal func, ByVal param )
\r
181 Dim en,ed,es, def_log_fname, b_echo_err_func, b_echo_err_file
\r
183 If g_debug Then Debug vbs_path, func, param : Exit Sub
\r
188 '//=== Call Me.Start
\r
189 If IsEmpty( m_Log ) And func <> "test_current" Then
\r
190 def_log_fname = m_DefLogFName
\r
191 m_DefLogFName = g_fs.GetParentFolderName( vbs_path ) + "\" + def_log_fname
\r
196 '//=== Echo the Test title
\r
197 If func <> "test_current" Then
\r
198 echo "=========================================================="
\r
199 If g_fs.GetFileName( g_fs.GetParentFolderName( vbs_path ) ) = "" Then
\r
200 echo "((( [" & g_fs.GetFileName( vbs_path ) & "] - " & func & " )))"
\r
202 echo "((( [" & g_fs.GetFileName( g_fs.GetParentFolderName( vbs_path ) ) & "\" _
\r
203 & g_fs.GetFileName( vbs_path ) & "] - " & func & " )))"
\r
208 '//=== Call the Test function
\r
209 On Error Resume Next
\r
211 call_vbs_t vbs_path, func, param
\r
213 en = Err.Number : ed = Err.Description : es = Err.Source : On Error GoTo 0
\r
216 '//=== Echo the Test result
\r
218 If func <> "test_current" Then
\r
219 m_nFail = m_nFail + 1
\r
220 echo "[FAIL] Test is not Pass"
\r
221 b_echo_err_func = True
\r
223 ElseIf en = Err_TestPass Then
\r
224 If func <> "test_current" Then
\r
225 m_nPass = m_nPass + 1
\r
226 '// echo "Pass." is already done in Pass function
\r
228 ElseIf en = Err_TestSkip Then
\r
229 m_nSkip = m_nSkip + 1
\r
231 b_echo_err_func = True
\r
232 ElseIf en = Err_TestFail Then
\r
233 m_nFail = m_nFail + 1
\r
234 echo "[FAIL] " & ed
\r
235 b_echo_err_func = True
\r
237 m_nFail = m_nFail + 1
\r
238 If en >= 0 and en <= &h7FFF Then
\r
239 echo "[FAIL] [ERROR](" & en & ") " & ed
\r
241 echo "[FAIL] [ERROR](" & Hex(en) & ") " & ed
\r
243 If en >= 1000 and en <=4096 Then
\r
244 b_echo_err_file = True
\r
246 b_echo_err_func = True
\r
249 If b_echo_err_func Then
\r
250 echo " in """ & func & """ function in """ & vbs_path & """"
\r
251 ElseIf b_echo_err_file Then
\r
252 echo " in """ & vbs_path & """"
\r
256 '//=== Call Me.Finish
\r
257 If Not IsEmpty( def_log_fname ) Then
\r
259 m_DefLogFName = def_log_fname
\r
267 '********************************************************************************
\r
268 ' <<< [TestScript::Debug] >>>
\r
269 '********************************************************************************
\r
270 Public Sub Debug( ByVal vbs_path, ByVal func, ByVal param )
\r
271 echo "=========================================================="
\r
272 echo "<<< [" & g_fs.GetFileName( g_fs.GetParentFolderName( vbs_path ) ) & "\" _
\r
273 & g_fs.GetFileName( vbs_path ) & "] - " & func & " >>>"
\r
274 echo "Debug Mode ..."
\r
279 call_vbs_d vbs_path, func, param
\r
283 If func <> "test_current" Then
\r
284 m_nPass = m_nPass + 1
\r
294 '********************************************************************************
\r
295 ' <<< [TestScript::WriteLogLine] >>>
\r
296 '********************************************************************************
\r
297 Public Sub WriteLogLine( Message )
\r
298 If not IsEmpty( m_Log ) Then
\r
299 m_Log.WriteLine Message
\r
301 If not IsEmpty( m_MemLog ) Then
\r
302 m_MemLog = m_MemLog + Message + vbCRLF
\r
306 '********************************************************************************
\r
307 ' <<< [TestScript::AddManualTest] >>>
\r
308 '********************************************************************************
\r
309 Public Sub AddManualTest( TestSymbol )
\r
310 ReDim Preserve m_ManualTests( UBound( m_ManualTests ) + 1 )
\r
311 m_ManualTests( UBound( m_ManualTests ) ) = TestSymbol
\r
312 ReDim Preserve m_ManualTestsPath( UBound( m_ManualTestsPath ) + 1 )
\r
313 m_ManualTestsPath( UBound( m_ManualTestsPath ) ) = m_Path
\r
318 '********************************************************************************
\r
319 ' <<< [TestScript::Raise] >>>
\r
320 '********************************************************************************
\r
321 Public Sub Raise( en, ed )
\r
322 m_nFail = m_nFail + 1
\r
323 If en >= 0 and en <= &h7FFF Then
\r
324 echo "[FAIL] [ERROR](" & en & ") " & ed
\r
326 echo "[FAIL] [ERROR](" & Hex(en) & ") " & ed
\r
332 '********************************************************************************
\r
333 ' <<< [TestScript::Finish] >>>
\r
334 '********************************************************************************
\r
336 Dim TestSymbol, sub_test ' Boolean
\r
340 For Each TestSymbol In m_ManualTests
\r
341 echo "[ManualTest] " + TestSymbol + " in """ + m_ManualTestsPath(i) + """"
\r
348 If WScript.Arguments.Count >= 1 Then
\r
349 If WScript.Arguments(0) = "-sub_test" Then sub_test = True
\r
353 If m_nFail = 0 Then WScript.Quit 0 Else WScript.Quit 1 End If
\r
355 echo "=========================================================="
\r
356 echo "Test Finish (Pass=" & m_nPass & ", Manual=" & UBound(m_ManualTests)+1 & _
\r
357 ", Skip=" & m_nSkip & ", Fail=" & m_nFail & ")"
\r
361 ReDim m_ManualTests(-1)
\r
372 '*-------------------------------------------------------------------------*
\r
373 '*
\81\9f<<<< [Tests] Class >>>> */
\r
374 '*-------------------------------------------------------------------------*
\r
377 Private m_Sets ' As Dictionary of UnitTest. key is UnitTest::Symbol
\r
378 Private m_BaseFolderPath ' as string. All Test ROOT
\r
379 Private m_Prompt ' as TestPrompt or Empty
\r
380 Private m_CurrentSymbol ' as string of current test symbol or ALL or ALL_R
\r
381 Private m_CurrentSubSymbol ' as string
\r
382 Private m_CurrentTest ' as UnitTest of m_CurrentSymbol
\r
383 Public CurrentTestPriority ' as integer small is high priority
\r
384 Private m_bAllTest ' as boolean
\r
385 Private m_AllFName ' as string
\r
386 Private m_Symbol ' as string of doing test symbol
\r
387 Public bTargetDebug ' as boolean
\r
388 Public c_ErrDblSymbol ' as const number
\r
389 Public m_bDisableAddTestScript ' as boolean
\r
390 Public m_bAutoDiff ' as boolean
\r
391 Public m_bSkipSection ' as boolean
\r
393 '----------------------------------
\r
394 Public Property Get Sets : Set Sets = m_Sets : End Property
\r
395 Public Property Get BaseFolderPath : BaseFolderPath = m_BaseFolderPath : End Property
\r
396 Public Property Let BaseFolderPath( x ) : m_BaseFolderPath = x : End Property
\r
397 Public Property Set Prompt( x ) : Set m_Prompt = x : End Property
\r
398 Public Property Get Prompt : Set Prompt = m_Prompt : End Property
\r
399 Public Property Get CurrentSymbol : CurrentSymbol = m_CurrentSymbol : End Property
\r
400 Public Property Get CurrentTest : If IsObject(m_CurrentTest) Then Set CurrentTest = m_CurrentTest : Else CurrentTest = m_CurrentTest : End If : End Property
\r
401 Public Property Get bAllTest : bAllTest = m_bAllTest : End Property
\r
402 Public Property Get Symbol : Symbol = m_Symbol : End Property
\r
404 '********************************************************************************
\r
405 ' <<< [Tests::Class_Initialize] >>>
\r
406 '********************************************************************************
\r
407 Private Sub Class_Initialize
\r
408 Set m_Sets = CreateObject("Scripting.Dictionary")
\r
409 m_BaseFolderPath = g_fs.GetParentFolderName( WScript.ScriptFullName )
\r
410 m_CurrentSymbol = "ALL"
\r
411 m_AllFName = "T_ALL.vbs"
\r
413 Me.bTargetDebug = False
\r
414 Me.c_ErrDblSymbol = 1010
\r
415 m_bDisableAddTestScript = False
\r
416 m_bAutoDiff = False
\r
417 m_bSkipSection = not IsEmpty( g_SkipSection )
\r
418 If not m_bSkipSection Then SkipToSection 0
\r
422 '********************************************************************************
\r
423 ' <<< [Tests::AddTestScriptAuto] >>>
\r
424 '********************************************************************************
\r
425 Public Function AddTestScriptAuto( BasePath, FName )
\r
427 AddTestScriptAuto_EnumSubFolders g_fs.GetFolder( BasePath ), FName
\r
431 Private Sub AddTestScriptAuto_EnumSubFolders( fo, FName )
\r
434 If g_fs.FileExists( fo.Path + "\" + FName ) Then
\r
435 AddTestScript g_fs.GetFileName( fo.Path ), fo.Path + "\" + FName
\r
437 For Each subfo in fo.SubFolders
\r
438 AddTestScriptAuto_EnumSubFolders subfo, FName
\r
442 '********************************************************************************
\r
443 ' <<< [Tests::AddTestScript] >>>
\r
444 '********************************************************************************
\r
445 Public Function AddTestScript( Symbol, Path )
\r
448 If Not g_fs.FileExists( Path ) Then Err.Raise 53,,"
\83t
\83@
\83C
\83\8b\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ " + Path
\r
449 If m_bDisableAddTestScript Then Exit Function
\r
451 Set test = new UnitTest : ErrCheck
\r
452 test.Symbol = Symbol
\r
453 test.ScriptPath = g_fs.GetAbsolutePathName( Path )
\r
454 If m_Sets.Exists( test.Symbol ) Then _
\r
455 Err.Raise c_ErrDblSymbol,"class Tests", "[ERROR] Already defined the symbol '"+Symbol+"' in "+ _
\r
456 m_Sets.Item(Symbol).ScriptPath
\r
457 m_Sets.Add test.Symbol, test
\r
459 Me.CurrentTestPriority = 1000
\r
460 If g_debug Then call_vbs_d Path, "test_current", Me _
\r
461 Else call_vbs_t Path, "test_current", Me
\r
462 test.Priority = Me.CurrentTestPriority
\r
464 Set AddTestScript = test
\r
468 '********************************************************************************
\r
469 ' <<< [Tests::SetCurrentSymbol] >>>
\r
470 '********************************************************************************
\r
471 Public Function SetCurrentSymbol( Symbol_or_Path )
\r
474 SetCurrentSymbol = 0
\r
476 '// ALL and ALL_R is special symbol
\r
477 If Symbol_or_Path = "ALL" or Symbol_or_Path = "ALL_R" Then m_CurrentSymbol = Symbol_or_Path : _
\r
478 m_CurrentTest = Empty : Exit Function
\r
480 '// Search by test symbol
\r
481 For Each key in m_Sets.Keys()
\r
482 If key = Symbol_or_Path Then m_CurrentSymbol = Symbol_or_Path : _
\r
483 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol ) : Exit Function
\r
487 For Each item in m_Sets.Items()
\r
488 If item.ScriptPath = Symbol_or_Path Then m_CurrentSymbol = item.Symbol : _
\r
489 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol ) : Exit Function
\r
492 '// If Symbol is path, Add test symbol
\r
493 If g_fs.FileExists( Symbol_or_Path ) Then
\r
494 If UCase(g_fs.GetFileName( Symbol_or_Path )) = UCase(m_AllFName) Then _
\r
495 m_CurrentSymbol = g_fs.GetFileName( g_fs.GetParentFolderName( g_fs.GetAbsolutePathName(Symbol_or_Path) ) ) _
\r
496 Else m_CurrentSymbol = g_fs.GetBaseName( Symbol_or_Path )
\r
498 b = True : If m_Sets.Exists( m_CurrentSymbol ) Then _
\r
499 b = ( m_Sets.Item( m_CurrentSymbol ).ScriptPath <> g_fs.GetAbsolutePathName( Symbol_or_Path ) )
\r
500 If b Then 'If Not m_Sets.Exists( m_CurrentSymbol ) or _
\r
501 ' m_Sets.Item( m_CurrentSymbol ).ScriptPath <> g_fs.GetAbsolutePathName( Symbol_or_Path ) Then
\r
502 AddTestScript m_CurrentSymbol, Symbol_or_Path
\r
504 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol )
\r
509 echo "[ERROR] Not found symbol or path """ + Symbol_or_Path + """. CurrentDirectory = " & g_sh.CurrentDirectory
\r
510 SetCurrentSymbol = 1
\r
515 '********************************************************************************
\r
516 ' <<< [Tests::DoTest] >>>
\r
517 '********************************************************************************
\r
518 Public Sub DoTest( Func, bReverse )
\r
520 If m_CurrentSymbol = "ALL" Or m_CurrentSymbol = "ALL_R" Then
\r
524 ShakerSort_fromDic m_Sets, utests, -1, GetRef("CmpUnitTestPriorityDec"), Empty
\r
526 ShakerSort_fromDic m_Sets, utests, +1, GetRef("CmpUnitTestPriorityInc"), Empty
\r
529 g_Test.m_DefLogFName = m_BaseFolderPath + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
531 If m_bAutoDiff Then g_Test.m_MemLog = ""
\r
532 For Each m_CurrentTest in utests
\r
534 g_Test.Do_ m_CurrentTest.ScriptPath, "test_current", Me
\r
536 g_Test.Do_ m_CurrentTest.ScriptPath, Func, Me
\r
537 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
541 g_Test.m_DefLogFName = g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
543 If m_bAutoDiff Then g_Test.m_MemLog = ""
\r
544 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol )
\r
546 g_Test.Do_ m_CurrentTest.ScriptPath, "test_current", Me
\r
548 g_Test.Do_ m_CurrentTest.ScriptPath, Func, Me
\r
549 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
555 '********************************************************************************
\r
556 ' <<< [Tests::DebugTest] >>>
\r
557 '********************************************************************************
\r
558 Public Sub DebugTest( Func, bReverse )
\r
559 If m_CurrentSymbol = "ALL" Or m_CurrentSymbol = "ALL_R" Then
\r
562 i = m_Sets.Count - 1
\r
563 ReDim Preserve items( i )
\r
565 For Each m_CurrentTest in m_Sets.Items()
\r
566 Set items( i ) = m_CurrentTest
\r
571 For Each m_CurrentTest in m_Sets.Items()
\r
572 Set items( i ) = m_CurrentTest
\r
577 g_Test.m_DefLogFName = m_BaseFolderPath + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
579 For Each m_CurrentTest in items
\r
580 If NotSkipSection() Then
\r
582 g_Test.Debug m_CurrentTest.ScriptPath, "test_current", Me
\r
584 g_Test.Debug m_CurrentTest.ScriptPath, Func, Me
\r
589 g_Test.m_DefLogFName = g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
591 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol )
\r
593 g_Test.Debug m_CurrentTest.ScriptPath, "test_current", Me
\r
595 g_Test.Debug m_CurrentTest.ScriptPath, Func, Me
\r
601 '********************************************************************************
\r
602 ' <<< [Tests::DoAllTest] >>>
\r
603 '********************************************************************************
\r
604 Public Sub DoAllTest()
\r
606 If m_CurrentSymbol = "ALL" Or m_CurrentSymbol = "ALL_R" Then
\r
607 Redim utests_inc(-1), utests_dec(-1)
\r
609 ShakerSort_fromDic m_Sets, utests_inc, +1, GetRef("CmpUnitTestPriorityInc"), Empty
\r
610 ShakerSort_fromDic m_Sets, utests_dec, -1, GetRef("CmpUnitTestPriorityDec"), Empty
\r
612 g_Test.m_DefLogFName = m_BaseFolderPath + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
614 If m_bAutoDiff Then g_Test.m_MemLog = ""
\r
616 For Each m_CurrentTest in utests_inc
\r
617 If NotSkipSection() Then
\r
619 g_Test.Do_ m_CurrentTest.ScriptPath, "test_current", Me
\r
620 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
623 For Each m_CurrentTest in utests_inc
\r
624 If NotSkipSection() Then
\r
626 g_Test.Do_ m_CurrentTest.ScriptPath, "test_build", Me
\r
627 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
630 For Each m_CurrentTest in utests_inc
\r
631 If NotSkipSection() Then
\r
633 g_Test.Do_ m_CurrentTest.ScriptPath, "test_setup", Me
\r
634 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
637 For Each m_CurrentTest in utests_inc
\r
638 If NotSkipSection() Then
\r
640 g_Test.Do_ m_CurrentTest.ScriptPath, "test_start", Me
\r
641 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
644 For Each m_CurrentTest in utests_dec
\r
645 If NotSkipSection() Then
\r
647 g_Test.Do_ m_CurrentTest.ScriptPath, "test_check", Me
\r
648 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
651 For Each m_CurrentTest in utests_dec
\r
652 If NotSkipSection() Then
\r
654 g_Test.Do_ m_CurrentTest.ScriptPath, "test_clean", Me
\r
655 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
658 If m_bSkipSection Then g_Test.Raise 1, "SkipToSection
\82ð
\83J
\83b
\83g
\82µ
\82Ä
\82Â
\82¾
\82³
\82¢
\81B"
\r
661 Set m_CurrentTest = m_Sets.Item( m_CurrentSymbol )
\r
662 g_Test.m_DefLogFName = g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) + "\" + g_fs.GetFileName( g_Test.m_DefLogFName )
\r
664 If m_bAutoDiff Then g_Test.m_MemLog = ""
\r
665 If NotSkipSection() Then
\r
667 g_Test.Do_ m_CurrentTest.ScriptPath, "test_current", Me
\r
669 If NotSkipSection() Then
\r
671 g_Test.Do_ m_CurrentTest.ScriptPath, "test_build", Me
\r
672 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
674 If NotSkipSection() Then
\r
676 g_Test.Do_ m_CurrentTest.ScriptPath, "test_setup", Me
\r
677 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
679 If NotSkipSection() Then
\r
681 g_Test.Do_ m_CurrentTest.ScriptPath, "test_start", Me
\r
682 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
684 If NotSkipSection() Then
\r
686 g_Test.Do_ m_CurrentTest.ScriptPath, "test_check", Me
\r
687 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
689 If NotSkipSection() Then
\r
691 g_Test.Do_ m_CurrentTest.ScriptPath, "test_clean", Me
\r
692 If Me.AutoDiff Then g_Test.Finish : m_bAllTest = False : Exit Sub
\r
694 If m_bSkipSection Then g_Test.Raise 1, "SkipToSection
\82ð
\83J
\83b
\83g
\82µ
\82Ä
\82Â
\82¾
\82³
\82¢
\81B"
\r
703 '********************************************************************************
\r
704 ' <<< [Tests::TestCurrentSetup] >>>
\r
705 '********************************************************************************
\r
706 Private Sub TestCurrentSetup()
\r
707 m_Symbol = m_CurrentTest.Symbol
\r
708 CurrentTestPriority = m_CurrentTest.Priority
\r
709 g_Test.m_Pass = True
\r
713 '********************************************************************************
\r
714 ' <<< [Tests::TestSetup] >>>
\r
715 '********************************************************************************
\r
716 Private Sub TestSetup()
\r
717 m_Symbol = m_CurrentTest.Symbol
\r
718 g_Test.m_Pass = False
\r
722 '********************************************************************************
\r
723 ' <<< [Tests::SetCur] >>>
\r
724 '********************************************************************************
\r
725 Public Sub SetCur( SubSymbol )
\r
726 m_CurrentSubSymbol = SubSymbol
\r
730 '********************************************************************************
\r
731 ' <<< [Tests::IsCur] >>>
\r
732 '********************************************************************************
\r
733 Public Function IsCur( SubSymbol )
\r
734 If m_CurrentSubSymbol = "ALL" Or m_CurrentSubSymbol = "ALL_R" Or _
\r
735 m_CurrentSubSymbol = SubSymbol Then
\r
743 '********************************************************************************
\r
744 ' <<< [Tests::AutoDiff] >>>
\r
745 '********************************************************************************
\r
746 Public Function AutoDiff()
\r
747 If m_bAutoDiff and g_Test.m_nFail > 0 Then
\r
748 Dim f : Set f = new StringStream : ErrCheck
\r
753 '//=== parse the output of fc command
\r
755 f.SetString g_Test.m_MemLog
\r
756 Do Until f.AtEndOfStream
\r
758 If Left( line, 6 ) = "***** " Then
\r
759 path( n_path ) = Mid( line, 7 )
\r
760 n_path = n_path + 1
\r
761 If n_path = 2 Then Exit Do
\r
767 '//=== Start Diff tool
\r
768 If not IsEmpty( path(1) ) Then
\r
769 path(0) = GetAbsPath( path(0), g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) )
\r
770 path(1) = GetAbsPath( path(1), g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) )
\r
771 If IsDefined("Setting_getDiffCmdLine") Then
\r
772 line = """" + Setting_getDiffCmdLine(0) + """ """ + path(0) + """ """ + path(1) + """"
\r
773 CreateFile g_fs.GetParentFolderName( m_CurrentTest.ScriptPath ) + "\Test_diff.bat", _
\r
774 "start """" " + line
\r
777 echo "[WARNING] Cannot open diff tool : not defined Setting_getDiffCmdLine"
\r
779 AutoDiff = True : Exit Function
\r
787 '********************************************************************************
\r
788 ' <<< [Tests::OpenFailFolder] >>>
\r
789 '********************************************************************************
\r
790 Public Sub OpenFailFolder()
\r
791 echo ">OpenFailFolder"
\r
793 Set ec = new EchoOff : ErrCheck
\r
796 Dim ds_:Set ds_= new CurDirStack : ErrCheck
\r
798 Set f = OpenTextFile( g_Test.m_DefLogFName )
\r
801 Do Until f.AtEndOfStream
\r
803 If Left( line, 6 ) = "[FAIL]" Then
\r
805 '//=== Open fail folder and ReTest
\r
810 Set ec = new EchoOff : ErrCheck
\r
812 s = MeltQuot( line, i )
\r
814 s = MeltQuot( line, i )
\r
815 If not IsEmpty( s ) Then
\r
817 Setting_openFolder s
\r
819 If LCase( g_fs.GetFileName( s ) ) = "test.vbs" Then
\r
820 CreateFile g_fs.GetParentFolderName( s ) + "\Test_debugger.bat", _
\r
821 "cscript //x Test.vbs /g_debug:1 /set_input:8.5.5."
\r
822 echo "Created debug.bat"
\r
824 echo "Run Test.vbs AutoDiff mode"
\r
825 g_sh.Run "cscript """ + s + """ /set_input:8.5.2.9.",,True
\r
827 '// echo "Run Test.vbs AutoDiff mode"
\r
828 '// cd g_fs.GetParentFolderName( s )
\r
829 '// g_sh.Run "debug.bat"
\r
835 '//=== Change from [FAIL] to [FAIL:Checked] in Test_logs.txt file
\r
837 Set f = StartReplace( "Test_logs.txt", "Test_logs_replacing.txt", False )
\r
839 Do Until f.r.AtEndOfStream
\r
840 line = f.r.ReadLine
\r
841 If i = 0 and InStr( line, "[FAIL]" ) > 0 Then
\r
842 line = Replace( line, "[FAIL]", "[FAIL:Checked]" )
\r
855 '********************************************************************************
\r
856 ' <<< [Tests::NextFail] >>>
\r
857 '********************************************************************************
\r
858 Public Sub NextFail()
\r
860 Dim ds_:Set ds_= new CurDirStack : ErrCheck
\r
862 Set f = OpenTextFile( g_Test.m_DefLogFName )
\r
864 Do Until f.AtEndOfStream
\r
866 If Left( line, 6 ) = "[FAIL]" Then
\r
868 '//=== Open fail folder
\r
873 s = MeltQuot( line, i )
\r
875 s = MeltQuot( line, i )
\r
876 If not IsEmpty( s ) Then
\r
877 Setting_openFolder s
\r
878 If LCase( g_fs.GetFileName( s ) ) = "test.vbs" Then
\r
879 CreateFile g_fs.GetParentFolderName( s ) + "\Test_debugger.bat", _
\r
880 "cscript //x Test.vbs /g_debug:1 /set_input:8.5.5."
\r
881 echo "Created debug.bat"
\r
883 echo "Run Test.vbs AutoDiff mode"
\r
884 g_sh.Run "cscript """ + s + """ /set_input:8.5.2.9.",,True
\r
886 '// echo "Run Test.vbs AutoDiff mode"
\r
887 '// cd g_fs.GetParentFolderName( s )
\r
888 '// g_sh.Run "debug.bat"
\r
894 '//=== Change from [FAIL] to [FAIL:Checked] in Test_logs.txt file
\r
896 Set f = StartReplace( "Test_logs.txt", "Test_logs_replacing.txt", False )
\r
898 Do Until f.r.AtEndOfStream
\r
899 line = f.r.ReadLine
\r
900 If i = 0 and InStr( line, "[FAIL]" ) > 0 Then
\r
901 line = Replace( line, "[FAIL]", "[FAIL:Checked]" )
\r
915 '********************************************************************************
\r
916 ' <<< [CmpUnitTestPriorityInc] >>>
\r
917 '********************************************************************************
\r
918 Function CmpUnitTestPriorityInc( left, right, param )
\r
919 CmpUnitTestPriorityInc = left.Priority - right.Priority
\r
922 '********************************************************************************
\r
923 ' <<< [CmpUnitTestPriorityDec] >>>
\r
924 '********************************************************************************
\r
925 Function CmpUnitTestPriorityDec( left, right, param )
\r
926 CmpUnitTestPriorityDec = right.Priority - left.Priority
\r
929 '*-------------------------------------------------------------------------*
\r
930 '*
\81\9f<<<< [UnitTest] Class >>>> */
\r
931 '*-------------------------------------------------------------------------*
\r
934 Public Symbol ' As String
\r
935 Public ScriptPath ' As String
\r
936 Public Priority ' As Integer
\r
938 '----------------------------------
\r
939 Private Sub Class_Initialize
\r
940 Symbol = "NoSymbol"
\r
944 Public Function Value
\r
945 Value = "[" & Symbol & "]" & vbCR & vbLF & " " & ScriptPath
\r
948 Public Function PathToAbs( BaseFolderPath )
\r
951 s = g_fs.GetAbsolutePathName( BaseFolderPath & "\" & ScriptPath )
\r
952 If Not g_fs.FileExists( s ) Then echo "[ERROR] Not found " + ScriptPath + ", Base=" + BaseFolderPath : PathToAbs = False
\r
960 '*-------------------------------------------------------------------------*
\r
961 '*
\81\9f<<<< Test Result >>>> */
\r
962 '*-------------------------------------------------------------------------*
\r
965 '********************************************************************************
\r
967 '********************************************************************************
\r
969 Dim b : b = g_EchoObj.m_bEchoOff : g_EchoObj.m_bEchoOff = False
\r
971 g_EchoObj.m_bEchoOff = b
\r
973 Err.Raise Err_TestPass, WScript.ScriptFullName, "Pass."
\r
979 '********************************************************************************
\r
981 '********************************************************************************
\r
983 Err.Raise Err_TestFail,, "Fail the Test"
\r
989 '********************************************************************************
\r
991 '********************************************************************************
\r
993 Err.Raise Err_TestSkip,, "[SKIP] Skip the Test"
\r
999 '********************************************************************************
\r
1000 ' <<< [ManualTest] >>>
\r
1001 '********************************************************************************
\r
1002 Sub ManualTest( TestSymbol )
\r
1003 Dim b : b = g_EchoObj.m_bEchoOff : g_EchoObj.m_bEchoOff = False
\r
1004 echo "((( ["+TestSymbol+"] )))"
\r
1005 echo "This is ManualTest."
\r
1006 g_EchoObj.m_bEchoOff = b
\r
1008 g_Test.AddManualTest TestSymbol
\r
1012 '*-------------------------------------------------------------------------*
\r
1013 '*
\81\9f<<<< Tools for Test Program >>>> */
\r
1014 '*-------------------------------------------------------------------------*
\r
1017 '********************************************************************************
\r
1018 ' <<< [EchoTestStart] >>>
\r
1019 '********************************************************************************
\r
1020 Sub EchoTestStart( TestSymbol )
\r
1021 echo "((( ["+TestSymbol+"] )))"
\r
1026 '********************************************************************************
\r
1027 ' <<< [CheckTestErrLevel] >>>
\r
1028 '********************************************************************************
\r
1029 Sub CheckTestErrLevel( r )
\r
1030 If r = Err_TestSkip Then
\r
1032 ElseIf r <> Err_TestPass Then
\r
1039 '********************************************************************************
\r
1040 ' <<< [ConvertToAbsPath] >>>
\r
1041 '********************************************************************************
\r
1042 Sub ConvertToAbsPath( SrcPath, DstPath )
\r
1043 Dim src, dst, dst_parent, line, p1, p2, path
\r
1045 Set src = OpenTextFile( SrcPath )
\r
1047 echo ">ConvertToAbsPath """ + SrcPath + """, """ + DstPath + """"
\r
1048 g_AppKey.AddNewWritableFolder DstPath
\r
1049 Set dst = g_fs.CreateTextFile( DstPath, True, (g_TextFileConvertFormat = F_Unicode) )
\r
1051 Do Until src.AtEndOfStream
\r
1052 line = src.ReadLine
\r
1054 p1 = InStr( line, "%AbsPath(" )
\r
1055 If p1 = 0 Then Exit Do
\r
1056 p2 = InStr( p1 + 9, line, ")%" )
\r
1057 path = Mid( line, p1+9, p2-p1-9 )
\r
1058 path = GetAbsPath( path, g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( SrcPath ) ) )
\r
1059 line = Left( line, p1 - 1 ) + path + Mid( line, p2 + 2 )
\r
1061 line = Replace( line, "%DesktopPath%", g_sh.SpecialFolders("Desktop") )
\r
1062 dst.WriteLine line
\r
1069 '********************************************************************************
\r
1070 ' <<< [OpenTextFile] >>>
\r
1071 '********************************************************************************
\r
1072 Function OpenTextFile( Path )
\r
1075 On Error Resume Next
\r
1076 Set OpenTextFile = g_fs.OpenTextFile( Path,,,-2 )
\r
1077 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1078 If en = E_FileNotExist or en = E_PathNotFound Then Err.raise en,,ed+" : "+Path
\r
1079 If en <> 0 Then Err.Raise en,,ed
\r