- Timestamp:
- Aug 19, 2022, 10:53:15 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 4 4 SVNZero.lps 5 5 heaptrclog.trc 6 Languages/*.mo
-
- Property svn:ignore
-
trunk/Languages/svnzero.cs.po
r4 r6 20 20 msgid "Zeroed files count: %d" 21 21 msgstr "Počet vynulovaných souborů: %d" 22 23 #: utest.sfailed 24 msgid "Failed" 25 msgstr "" 26 27 #: utest.snone 28 msgid "None" 29 msgstr "" 30 31 #: utest.spassed 32 msgid "Passed" 33 msgstr "" 34 -
trunk/Languages/svnzero.pot
r4 r6 11 11 msgstr "" 12 12 13 #: utest.sfailed 14 msgid "Failed" 15 msgstr "" 16 17 #: utest.snone 18 msgid "None" 19 msgstr "" 20 21 #: utest.spassed 22 msgid "Passed" 23 msgstr "" 24 -
trunk/SVNZero.lpi
r4 r6 87 87 <IsPartOfProject Value="True"/> 88 88 </Unit> 89 <Unit> 90 <Filename Value="UTestCases.pas"/> 91 <IsPartOfProject Value="True"/> 92 </Unit> 89 93 </Units> 90 94 </ProjectOptions> -
trunk/SVNZero.lpr
r5 r6 5 5 cthreads, 6 6 {$ENDIF} 7 Classes, SysUtils, CustApp, USubversion, UTest, USvnZero 7 Classes, SysUtils, CustApp, USubversion, UTest, USvnZero, UTestCases 8 8 { you can add units after this }; 9 9 … … 29 29 begin 30 30 if HasOption('t', 'test') then begin 31 with TTest .Create do31 with TTestCases.Create do 32 32 try 33 AddNew('Add', TTestCaseAdd); 34 AddNew('Update', TTestCaseUpdate); 35 AddNew('Modify', TTestCaseModify); 36 AddNew('Delete', TTestCaseDelete); 33 37 Run; 34 38 finally -
trunk/UTest.pas
r5 r6 4 4 5 5 uses 6 Classes, SysUtils, USubversion, FileUtil ;6 Classes, SysUtils, USubversion, FileUtil, Generics.Collections; 7 7 8 8 type 9 TTestResult = (trNone, trPassed, trFailed); 9 10 10 { TTest }11 { TTestCase } 11 12 12 TTest = class 13 TTestCase = class 14 public 15 Name: string; 16 TestResult: TTestResult; 17 Log: string; 18 procedure Run; virtual; 19 procedure Evaluate(Passed: Boolean); 20 procedure Pass; 21 procedure Fail; 22 constructor Create; virtual; 23 end; 24 25 TTestCaseClass = class of TTestCase; 26 27 { TTestCases } 28 29 TTestCases = class(TObjectList<TTestCase>) 30 function AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 31 procedure Run; 32 end; 33 34 { TTestCaseSvn } 35 36 TTestCaseSvn = class(TTestCase) 13 37 private 14 38 Subversion: TExecute; 15 39 SubversionAdmin: TSubversionAdmin; 40 function CheckError(Text: string): Boolean; 41 protected 16 42 RepoDir: string; 17 43 WorkDir: string; 18 44 TestDir: string; 19 TestResult: Boolean;20 45 procedure Svn(Parameters: array of string); 21 46 procedure SvnAdmin(Parameters: array of string); 22 function CheckError(Text: string): Boolean;23 procedure Eval(TestResult: Boolean);24 procedure TestAdd;25 procedure TestModify;26 procedure TestUpdate;27 procedure TestDelete;28 47 public 29 procedure Run; 30 constructor Create; 48 procedure Run; override; 49 constructor Create; override; 31 50 destructor Destroy; override; 32 51 end; 52 53 resourcestring 54 SNone = 'None'; 55 SPassed = 'Passed'; 56 SFailed = 'Failed'; 57 58 const 59 ResultText: array[TTestResult] of string = (SNone, SPassed, SFailed); 60 61 procedure Translate; 62 procedure SaveStringToFile(S, FileName: string); 33 63 34 64 … … 37 67 uses 38 68 USvnZero; 69 70 procedure Translate; 71 begin 72 ResultText[trNone] := SNone; 73 ResultText[trPassed] := SPassed; 74 ResultText[trFailed] := SFailed; 75 end; 76 39 77 40 78 procedure SaveStringToFile(S, FileName: string); … … 51 89 end; 52 90 91 { TTestCase } 53 92 54 { TTest } 93 procedure TTestCase.Run; 94 begin 95 end; 55 96 56 procedure TTest.Svn(Parameters: array of string); 97 procedure TTestCase.Evaluate(Passed: Boolean); 98 begin 99 if Passed then TestResult := trPassed 100 else TestResult := trFailed; 101 end; 102 103 procedure TTestCase.Pass; 104 begin 105 TestResult := trPassed; 106 end; 107 108 procedure TTestCase.Fail; 109 begin 110 TestResult := trFailed; 111 end; 112 113 constructor TTestCase.Create; 114 begin 115 end; 116 117 { TTestCases } 118 119 function TTestCases.AddNew(Name: string; TestClass: TTestCaseClass): TTestCase; 120 begin 121 Result := TestClass.Create; 122 Result.Name := Name; 123 Add(Result); 124 end; 125 126 procedure TTestCases.Run; 127 var 128 I: Integer; 129 Passed: Integer; 130 Failed: Integer; 131 begin 132 for I := 0 to Count - 1 do 133 with Items[I] do begin 134 WriteLn('== ' + Name + ' ======= '); 135 Run; 136 end; 137 138 Passed := 0; 139 Failed := 0; 140 for I := 0 to Count - 1 do 141 with Items[I] do begin 142 WriteLn(Name + ': ' + ResultText[TestResult]); 143 if TestResult = trPassed then Inc(Passed); 144 if TestResult = trFailed then Inc(Failed); 145 end; 146 WriteLn('Total: ' + IntToStr(Count) + ', Passed: ' + IntToStr(Passed) + 147 ', Failed: ' + IntToStr(Failed)); 148 end; 149 150 { TTestCaseSvn } 151 152 procedure TTestCaseSvn.Svn(Parameters: array of string); 57 153 begin 58 154 Subversion.ExecuteOutput(Parameters); 59 155 if CheckError(Subversion.ErrorOutput) then 60 TestResult := False;156 TestResult := trFailed; 61 157 end; 62 158 63 procedure TTest .SvnAdmin(Parameters: array of string);159 procedure TTestCaseSvn.SvnAdmin(Parameters: array of string); 64 160 begin 65 161 SubversionAdmin.ExecuteOutput(Parameters); 66 162 if CheckError(SubversionAdmin.ErrorOutput) then 67 TestResult := False;163 TestResult := trFailed; 68 164 end; 69 165 70 function TTest .CheckError(Text: string): Boolean;166 function TTestCaseSvn.CheckError(Text: string): Boolean; 71 167 begin 72 168 Result := Pos('svn: E', Text) > 0; 73 169 end; 74 170 75 procedure TTest .Eval(TestResult: Boolean);171 procedure TTestCaseSvn.Run; 76 172 begin 77 if TestResult then WriteLn('PASSED') 78 else WriteLn('FAILED'); 173 ChDir(TestDir); 79 174 end; 80 175 81 procedure TTest.TestAdd; 82 var 83 TestFile: string; 84 LastDir: string; 85 begin 86 TestResult := True; 87 LastDir := GetCurrentDir; 88 TestFile := 'TestFile.txt'; 89 SvnAdmin(['create', RepoDir]); 90 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 91 ChDir(WorkDir); 92 SaveStringToFile('Some text', TestFile); 93 Svn(['add', TestFile]); 94 Svn(['commit', '-m', '"Commit message"']); 95 ChDir(LastDir); 96 DeleteDirectory(WorkDir, False); 97 DeleteDirectory(RepoDir, False); 98 Eval(TestResult); 99 end; 100 101 procedure TTest.TestModify; 102 var 103 TestFile: string; 104 LastDir: string; 105 begin 106 TestResult := True; 107 LastDir := GetCurrentDir; 108 TestFile := 'TestFile.txt'; 109 SvnAdmin(['create', RepoDir]); 110 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 111 ChDir(WorkDir); 112 SaveStringToFile('Some text', TestFile); 113 Svn(['add', TestFile]); 114 Svn(['commit', '-m', '"Commit message"']); 115 SaveStringToFile('Different text', TestFile); 116 Svn(['commit', '-m', '"Commit message 2"']); 117 ChDir(LastDir); 118 DeleteDirectory(WorkDir, False); 119 DeleteDirectory(RepoDir, False); 120 Eval(TestResult); 121 end; 122 123 procedure TTest.TestUpdate; 124 var 125 TestFile: string; 126 LastDir: string; 127 begin 128 TestResult := True; 129 LastDir := GetCurrentDir; 130 TestFile := 'TestFile.txt'; 131 SvnAdmin(['create', RepoDir]); 132 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 133 ChDir(WorkDir); 134 SaveStringToFile('Some text', TestFile); 135 Svn(['add', TestFile]); 136 Svn(['commit', '-m', '"Commit message"']); 137 SaveStringToFile('Different text', TestFile); 138 Svn(['commit', '-m', '"Commit message 2"']); 139 Svn(['update', '-r', '1', TestFile]); 140 Svn(['update']); 141 ChDir(LastDir); 142 DeleteDirectory(WorkDir, False); 143 DeleteDirectory(RepoDir, False); 144 Eval(TestResult); 145 end; 146 147 procedure TTest.TestDelete; 148 var 149 TestFile: string; 150 LastDir: string; 151 begin 152 TestResult := True; 153 LastDir := GetCurrentDir; 154 TestFile := 'TestFile.txt'; 155 SvnAdmin(['create', RepoDir]); 156 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 157 ChDir(WorkDir); 158 SaveStringToFile('Some text', TestFile); 159 Svn(['add', TestFile]); 160 Svn(['commit', '-m', '"Commit message"']); 161 Svn(['delete', TestFile]); 162 Svn(['commit', '-m', '"Commit message 2"']); 163 ChDir(LastDir); 164 DeleteDirectory(WorkDir, False); 165 DeleteDirectory(RepoDir, False); 166 Eval(TestResult); 167 end; 168 169 procedure TTest.Run; 170 begin 171 ChDir(TestDir); 172 TestAdd; 173 TestModify; 174 TestUpdate; 175 TestDelete; 176 end; 177 178 constructor TTest.Create; 176 constructor TTestCaseSvn.Create; 179 177 begin 180 178 TestDir := GetTempDir(False) + 'SVNZero'; … … 187 185 end; 188 186 189 destructor TTest .Destroy;187 destructor TTestCaseSvn.Destroy; 190 188 begin 191 189 FreeAndNil(SubversionAdmin);
Note:
See TracChangeset
for help on using the changeset viewer.