Add a testing suite for CMD based on CMD scripts.
[reactos.git] / rostests / win32 / cmd / script_testsuite / lib / testlib.cmd
1 ::
2 :: PROJECT: ReactOS CMD Testing Suite
3 :: LICENSE: GPL v2 or any later version
4 :: FILE: lib/testlib.cmd
5 :: PURPOSE: Library with functions available for all tests
6 :: COPYRIGHT: Copyright 2008 Colin Finck <mail@colinfinck.de>
7 ::
8
9 :: Indicate that a test ran successfully
10 :_successful
11 set /a test_count+=1
12 set /a successful_tests+=1
13 goto :EOF
14
15
16 :: Indicate that a test failed
17 :: @param 1 Description of the test that failed
18 :_failed
19 set /a test_count+=1
20 set /a failed_tests+=1
21 echo Test "%~1" failed!
22 goto :EOF
23
24
25 :: Test whether a call succeeded
26 :: @param 1 The test command to run and check
27 :_test
28 %~1
29
30 if "%errorlevel%" == "0" (
31 call :_successful
32 ) else (
33 call :_failed "%~1"
34 )
35 goto :EOF
36
37
38 :: Test whether a call failed
39 :: @param 1 The test command to run and check
40 :_testnot
41 %~1
42
43 if "%errorlevel%" == "0" (
44 call :_failed "%~1"
45 ) else (
46 call :_successful
47 )
48 goto :EOF
49
50
51 :: Test the value of a variable
52 :: @param 1 The variable to check (like %test%)
53 :: @param 2 The variable name (like test)
54 :: @param 3 The expected result (like 5)
55 :: If this parameter wasn't given, _testvar checks if the variable is not ""
56 :_testvar
57 if "%~3" == "" (
58 set testvar_operator=not
59 ) else (
60 set testvar_operator=
61 )
62
63 if %testvar_operator% "%~1" == "%~3" (
64 call :_successful
65 ) else (
66 call :_failed "if %%~2%% == %~3, actual result was %~1"
67 )
68
69 goto :EOF