Changeset 8 for trunk/UTestCases.pas
- Timestamp:
- Aug 20, 2022, 8:22:00 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.