- Timestamp:
- Aug 20, 2022, 8:22:00 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SVNZero.lpr
r7 r8 31 31 with TTestCases.Create do 32 32 try 33 {AddNew('Add', TTestCaseAdd);33 AddNew('Add', TTestCaseAdd); 34 34 AddNew('Update', TTestCaseUpdate); 35 35 AddNew('Modify', TTestCaseModify); 36 36 AddNew('Delete', TTestCaseDelete); 37 } AddNew('Merge', TTestCaseMerge); 37 AddNew('Merge', TTestCaseMerge); 38 AddNew('Update multiple', TTestCaseUpdateMultiple); 38 39 Run; 39 40 finally -
trunk/USvnZero.pas
r5 r8 10 10 { TSvnZero } 11 11 12 TSvnZero = class(T Execute)12 TSvnZero = class(TSubversion) 13 13 private 14 14 Subversion: TSubversion; -
trunk/UTest.pas
r7 r8 4 4 5 5 uses 6 Classes, SysUtils, USubversion,FileUtil, Generics.Collections;6 Classes, SysUtils, FileUtil, Generics.Collections; 7 7 8 8 type … … 16 16 TestResult: TTestResult; 17 17 Log: string; 18 procedure Initialize; virtual; 18 19 procedure Run; virtual; 20 procedure Finalize; virtual; 19 21 procedure Evaluate(Passed: Boolean); 20 22 procedure Pass; … … 32 34 end; 33 35 34 { TTestCaseSvn }35 36 TTestCaseSvn = class(TTestCase)37 private38 Subversion: TExecute;39 SubversionAdmin: TSubversionAdmin;40 function CheckError(Text: string): Boolean;41 protected42 RepoDir: string;43 WorkDir: string;44 TestDir: string;45 procedure Svn(Parameters: array of string);46 procedure SvnAdmin(Parameters: array of string);47 public48 procedure Run; override;49 constructor Create; override;50 destructor Destroy; override;51 end;52 36 53 37 resourcestring … … 64 48 65 49 implementation 66 67 uses68 USvnZero;69 50 70 51 procedure Translate; … … 91 72 { TTestCase } 92 73 74 procedure TTestCase.Initialize; 75 begin 76 end; 77 93 78 procedure TTestCase.Run; 79 begin 80 end; 81 82 procedure TTestCase.Finalize; 94 83 begin 95 84 end; … … 129 118 Passed: Integer; 130 119 Failed: Integer; 131 LastDir: string;132 120 begin 133 121 for I := 0 to Count - 1 do 134 122 with Items[I] do begin 135 123 WriteLn('== ' + Name + ' ======= '); 136 LastDir := GetCurrentDir;124 Initialize; 137 125 Run; 138 ChDir(LastDir);126 Finalize; 139 127 end; 140 128 … … 151 139 end; 152 140 153 { TTestCaseSvn }154 155 procedure TTestCaseSvn.Svn(Parameters: array of string);156 begin157 Subversion.ExecuteOutput(Parameters);158 if CheckError(Subversion.ErrorOutput) then159 TestResult := trFailed;160 end;161 162 procedure TTestCaseSvn.SvnAdmin(Parameters: array of string);163 begin164 SubversionAdmin.ExecuteOutput(Parameters);165 if CheckError(SubversionAdmin.ErrorOutput) then166 TestResult := trFailed;167 end;168 169 function TTestCaseSvn.CheckError(Text: string): Boolean;170 begin171 Result := Pos('svn: E', Text) > 0;172 end;173 174 procedure TTestCaseSvn.Run;175 begin176 ChDir(TestDir);177 end;178 179 constructor TTestCaseSvn.Create;180 begin181 TestDir := GetTempDir(False) + 'SVNZero';182 ForceDirectories(TestDir);183 RepoDir := TestDir + DirectorySeparator + 'Repo';184 WorkDir := TestDir + DirectorySeparator + 'Work';185 //Subversion := TSubversion.Create;186 Subversion := TSvnZero.Create;187 SubversionAdmin := TSubversionAdmin.Create;188 end;189 190 destructor TTestCaseSvn.Destroy;191 begin192 FreeAndNil(SubversionAdmin);193 FreeAndNil(Subversion);194 inherited;195 end;196 197 141 end. 198 142 -
trunk/UTestCases.pas
r7 r8 4 4 5 5 uses 6 Classes, SysUtils, FileUtil, UTest ;6 Classes, SysUtils, FileUtil, UTest, USubversion; 7 7 8 8 type 9 { TTestCaseSvn } 10 11 TTestCaseSvn = class(TTestCase) 12 private 13 Subversion: TExecute; 14 SubversionAdmin: TSubversionAdmin; 15 function CheckError(Text: string): Boolean; 16 protected 17 LastDir: string; 18 RepoDir: string; 19 WorkDir: string; 20 TestDir: string; 21 procedure Svn(Parameters: array of string); 22 procedure SvnAdmin(Parameters: array of string); 23 public 24 procedure Initialize; override; 25 procedure Run; override; 26 procedure Finalize; override; 27 constructor Create; override; 28 destructor Destroy; override; 29 end; 30 31 { TTestCaseAdd } 32 9 33 TTestCaseAdd = class(TTestCaseSvn) 10 34 procedure Run; override; 11 35 end; 12 36 37 { TTestCaseModify } 38 13 39 TTestCaseModify = class(TTestCaseSvn) 14 40 procedure Run; override; 15 41 end; 16 42 43 { TTestCaseUpdate } 44 17 45 TTestCaseUpdate = class(TTestCaseSvn) 18 46 procedure Run; override; 19 47 end; 20 48 49 { TTestCaseDelete } 50 21 51 TTestCaseDelete = class(TTestCaseSvn) 22 52 procedure Run; override; … … 29 59 end; 30 60 61 { TTestCaseUpdateMultiple } 62 63 TTestCaseUpdateMultiple = class(TTestCaseSvn) 64 procedure Run; override; 65 end; 31 66 32 67 implementation 33 68 34 { TTestCaseMerge } 35 36 procedure TTestCaseMerge.Run; 37 var 38 TestFile: string; 39 begin 40 TestFile := 'TestFile.txt'; 69 uses 70 USvnZero; 71 72 { TTestCaseSvn } 73 74 procedure TTestCaseSvn.Svn(Parameters: array of string); 75 begin 76 Subversion.ExecuteOutput(Parameters); 77 if CheckError(Subversion.ErrorOutput) then 78 TestResult := trFailed; 79 end; 80 81 procedure TTestCaseSvn.SvnAdmin(Parameters: array of string); 82 begin 83 SubversionAdmin.ExecuteOutput(Parameters); 84 if CheckError(SubversionAdmin.ErrorOutput) then 85 TestResult := trFailed; 86 end; 87 88 procedure TTestCaseSvn.Initialize; 89 begin 90 inherited; 91 LastDir := GetCurrentDir; 92 ChDir(TestDir); 41 93 SvnAdmin(['create', RepoDir]); 42 94 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 43 95 ChDir(WorkDir); 96 end; 97 98 function TTestCaseSvn.CheckError(Text: string): Boolean; 99 begin 100 Result := Pos('svn: E', Text) > 0; 101 end; 102 103 procedure TTestCaseSvn.Run; 104 begin 105 end; 106 107 procedure TTestCaseSvn.Finalize; 108 begin 109 ChDir(LastDir); 110 DeleteDirectory(WorkDir, False); 111 DeleteDirectory(RepoDir, False); 112 inherited; 113 end; 114 115 constructor TTestCaseSvn.Create; 116 begin 117 TestDir := GetTempDir(False) + 'SVNZero'; 118 ForceDirectories(TestDir); 119 RepoDir := TestDir + DirectorySeparator + 'Repo'; 120 WorkDir := TestDir + DirectorySeparator + 'Work'; 121 //Subversion := TSubversion.Create; 122 Subversion := TSvnZero.Create; 123 SubversionAdmin := TSubversionAdmin.Create; 124 end; 125 126 destructor TTestCaseSvn.Destroy; 127 begin 128 FreeAndNil(SubversionAdmin); 129 FreeAndNil(Subversion); 130 inherited; 131 end; 132 133 { TTestCaseMerge } 134 135 procedure TTestCaseMerge.Run; 136 var 137 TestFile: string; 138 begin 139 TestFile := 'TestFile.txt'; 44 140 SaveStringToFile('First line' + LineEnding + 'Second line' + LineEnding + 'Third line', TestFile); 45 141 Svn(['add', TestFile]); … … 51 147 Svn(['update', TestFile]); 52 148 Svn(['commit', '-m', '"Commit message 3"']); 53 DeleteDirectory(WorkDir, False);54 DeleteDirectory(RepoDir, False);55 149 Evaluate(True); 56 150 end; … … 61 155 begin 62 156 TestFile := 'TestFile.txt'; 63 SvnAdmin(['create', RepoDir]); 64 Svn(['checkout', 'file:///' + RepoDir, WorkDir]); 65 ChDir(WorkDir); 66 SaveStringToFile('Some text', TestFile); 67 Svn(['add', TestFile]); 68 Svn(['commit', '-m', '"Commit message"']); 69 DeleteDirectory(WorkDir, False); 70 DeleteDirectory(RepoDir, False); 157 SaveStringToFile('Some text', TestFile); 158 Svn(['add', TestFile]); 159 Svn(['commit', '-m', '"Commit message"']); 71 160 Evaluate(True); 72 161 end; … … 77 166 begin 78 167 TestFile := 'TestFile.txt'; 79 SvnAdmin(['create', RepoDir]);80 Svn(['checkout', 'file:///' + RepoDir, WorkDir]);81 ChDir(WorkDir);82 168 SaveStringToFile('Some text', TestFile); 83 169 Svn(['add', TestFile]); … … 85 171 SaveStringToFile('Different text', TestFile); 86 172 Svn(['commit', '-m', '"Commit message 2"']); 87 DeleteDirectory(WorkDir, False);88 DeleteDirectory(RepoDir, False);89 173 Evaluate(True); 90 174 end; … … 95 179 begin 96 180 TestFile := 'TestFile.txt'; 97 SvnAdmin(['create', RepoDir]);98 Svn(['checkout', 'file:///' + RepoDir, WorkDir]);99 ChDir(WorkDir);100 181 SaveStringToFile('Some text', TestFile); 101 182 Svn(['add', TestFile]); … … 104 185 Svn(['commit', '-m', '"Commit message 2"']); 105 186 Svn(['update', '-r', '1', TestFile]); 187 Svn(['update', '-r', '2', TestFile]); 106 188 Svn(['update']); 107 DeleteDirectory(WorkDir, False);108 DeleteDirectory(RepoDir, False);109 189 Evaluate(True); 110 190 end; … … 115 195 begin 116 196 TestFile := 'TestFile.txt'; 117 SvnAdmin(['create', RepoDir]);118 Svn(['checkout', 'file:///' + RepoDir, WorkDir]);119 ChDir(WorkDir);120 197 SaveStringToFile('Some text', TestFile); 121 198 Svn(['add', TestFile]); … … 123 200 Svn(['delete', TestFile]); 124 201 Svn(['commit', '-m', '"Commit message 2"']); 125 DeleteDirectory(WorkDir, False); 126 DeleteDirectory(RepoDir, False); 127 Evaluate(True); 128 end; 129 202 Evaluate(True); 203 end; 204 205 procedure TTestCaseUpdateMultiple.Run; 206 var 207 I: Integer; 208 const 209 Count = 20; 210 begin 211 for I := 0 to Count - 1 do begin 212 SaveStringToFile('Some text', 'TestFile' + IntToStr(I) + '.txt'); 213 Svn(['add', 'TestFile' + IntToStr(I) + '.txt']); 214 end; 215 Svn(['commit', '-m', '"Commit message"']); 216 for I := 0 to Count - 1 do 217 SaveStringToFile('Different text', 'TestFile' + IntToStr(I) + '.txt'); 218 Svn(['commit', '-m', '"Commit message 2"']); 219 Svn(['update', '-r', '1']); 220 Svn(['update', '-r', '2']); 221 Svn(['update']); 222 Evaluate(True); 223 end; 130 224 131 225 end.
Note:
See TracChangeset
for help on using the changeset viewer.