Skip to content
This repository was archived by the owner on Dec 13, 2020. It is now read-only.

Commit ca0b7d6

Browse files
committed
Clar tests for status/ignore
1 parent c91a680 commit ca0b7d6

File tree

4 files changed

+159
-4
lines changed

4 files changed

+159
-4
lines changed

tests/GitForDelphi.dpr

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ uses
3030
t10_refs in 'TestsFromLibGit2\t10_refs.pas',
3131
uGitForDelphi in '..\uGitForDelphi.pas',
3232
t15_config in 'TestsFromLibGit2\t15_config.pas',
33-
t18_status in 'TestsFromLibGit2\t18_status.pas';
33+
t18_status in 'TestsFromLibGit2\t18_status.pas',
34+
status in 'TestsFromLibGit2\clar\status.pas',
35+
uClar in 'TestsFromLibGit2\clar\uClar.pas';
3436

3537
{$R *.RES}
3638

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
unit status;
2+
3+
interface
4+
5+
uses
6+
TestFramework, SysUtils, Windows, Classes,
7+
uTestsFromLibGit2, uGitForDelphi, uClar;
8+
9+
type
10+
Test_status_ignore = class(TClarTest)
11+
private
12+
g_repo: Pgit_repository;
13+
protected
14+
procedure SetUp; override;
15+
procedure TearDown; override;
16+
published
17+
procedure TestIgnores;
18+
end;
19+
20+
implementation
21+
22+
{ Test_status_ignore }
23+
24+
procedure Test_status_ignore.SetUp;
25+
begin
26+
inherited;
27+
cl_fixture_sandbox('attr');
28+
cl_git_pass(p_rename('attr/.gitted', 'attr/.git'));
29+
cl_git_pass(p_rename('attr/gitignore', 'attr/.gitignore'));
30+
cl_git_pass(git_repository_open(g_repo, 'attr/.git'));
31+
end;
32+
33+
procedure Test_status_ignore.TearDown;
34+
begin
35+
inherited;
36+
git_repository_free(g_repo);
37+
g_repo := nil;
38+
cl_fixture_cleanup('attr');
39+
end;
40+
41+
type
42+
ignore_test_cases = record
43+
path: AnsiString;
44+
expected: Integer;
45+
end;
46+
procedure Test_status_ignore.TestIgnores;
47+
const
48+
test_cases: array [0..13] of ignore_test_cases = (
49+
(path: 'file'; expected: 0),
50+
(path: 'ign'; expected:1 ),
51+
(path: 'sub'; expected:1 ),
52+
(path: 'sub/file'; expected:0 ),
53+
(path: 'sub/ign'; expected:1 ),
54+
(path: 'sub/sub'; expected:1 ),
55+
(path: 'sub/sub/file'; expected:0 ),
56+
(path: 'sub/sub/ign'; expected:1 ),
57+
(path: 'sub/sub/sub'; expected:1 ),
58+
//* pattern 'dir/' from .gitignore */
59+
(path: 'dir'; expected:1 ),
60+
(path: 'dir/'; expected:1 ),
61+
(path: 'sub/dir'; expected:1 ),
62+
(path: 'sub/dir/'; expected:1 ),
63+
(path: 'sub/sub/dir'; expected:0 ) //* dir is not actually a dir, but a file */
64+
);
65+
var
66+
i, ignored: Integer;
67+
begin
68+
for i := Low(test_cases) to High(test_cases) do
69+
begin
70+
cl_git_pass(git_status_should_ignore(g_repo, PAnsiChar(test_cases[i].path), @ignored));
71+
cl_assert_(ignored = test_cases[i].expected, test_cases[i].path);
72+
end;
73+
end;
74+
75+
initialization
76+
RegisterTest('From libgit2/clar/status', Test_status_ignore.NamedSuite('ignore'));
77+
78+
end.

tests/TestsFromLibGit2/clar/uClar.pas

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
unit uClar;
2+
3+
interface
4+
5+
uses
6+
TestFramework, SysUtils, Windows, Classes,
7+
uTestsFromLibGit2, uGitForDelphi;
8+
9+
type
10+
TClarTest = class(TTestFromLibGit2)
11+
public
12+
function p_rename(const aFrom, aTo: AnsiString): Integer; override;
13+
14+
procedure cl_fixture_sandbox(const aFixtureName: AnsiString);
15+
procedure cl_fixture_cleanup(const aFixtureName: AnsiString);
16+
procedure cl_git_pass(expr: Integer);
17+
procedure cl_assert_(b: Boolean; const aDescr: String); overload;
18+
procedure cl_assert_(b: Boolean; const aDescr: AnsiString); overload;
19+
end;
20+
21+
implementation
22+
23+
{ TClarTest }
24+
25+
procedure TClarTest.cl_fixture_sandbox(const aFixtureName: AnsiString);
26+
var
27+
path: AnsiString;
28+
begin
29+
path := 'resources/' + aFixtureName;
30+
copydir_recurs(path, aFixtureName);
31+
end;
32+
33+
procedure TClarTest.cl_assert_(b: Boolean; const aDescr: String);
34+
begin
35+
CheckTrue(b, aDescr);
36+
end;
37+
38+
procedure TClarTest.cl_assert_(b: Boolean; const aDescr: AnsiString);
39+
begin
40+
CheckTrue(b, String(aDescr));
41+
end;
42+
43+
procedure TClarTest.cl_fixture_cleanup(const aFixtureName: AnsiString);
44+
var
45+
path: AnsiString;
46+
begin
47+
path := './' + aFixtureName;
48+
rmdir_recurs(path);
49+
end;
50+
51+
procedure TClarTest.cl_git_pass(expr: Integer);
52+
begin
53+
git_clearerror();
54+
// if ((expr) <> GIT_SUCCESS)
55+
// clar__assert(0, __FILE__, __LINE__, 'Function call failed: ' #expr, git_lasterror(), 1);
56+
// } while(0);
57+
58+
if expr <> GIT_SUCCESS then
59+
Fail('Funciton failed ' + String(AnsiString(git_lasterror())), CallerAddr);
60+
end;
61+
62+
function TClarTest.p_rename(const aFrom, aTo: AnsiString): Integer;
63+
begin
64+
if DirectoryExists(String(aFrom)) then
65+
begin
66+
if RenameDir(aFrom, aTo) then
67+
Result := GIT_SUCCESS
68+
else
69+
Result := GIT_ERROR;
70+
end
71+
else
72+
Result := inherited p_rename(aFrom, aTo);
73+
end;
74+
75+
end.

tests/TestsFromLibGit2/uTestsFromLibGit2.pas

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TTestFromLibGit2 = class (TTestCase)
3333
function remove_placeholders(directory_path, filename: PAnsiChar): Integer;
3434
function RenameDir(const aFrom, aTo: AnsiString): Boolean;
3535
function p_unlink(const aFileName: String): Integer;
36-
function p_rename(const aFrom, aTo: AnsiString): Integer;
36+
function p_rename(const aFrom, aTo: AnsiString): Integer; virtual;
3737
end;
3838

3939
TTestSuiteForLibGit2 = class(TTestSuite, ITestSuite, ITest)
@@ -450,8 +450,8 @@ function TTestFromLibGit2.open_temp_repo(var repo: Pgit_repository; const path:
450450

451451
function TTestFromLibGit2.p_rename(const aFrom, aTo: AnsiString): Integer;
452452
begin
453-
RenameFile(aFrom, aTo);
454-
if (not FileExists(aFrom)) and FileExists(aTo) then
453+
RenameFile(String(aFrom), String(aTo));
454+
if (not FileExists(String(aFrom))) and FileExists(String(aTo)) then
455455
Result := 0
456456
else
457457
Result := GIT_ERROR;

0 commit comments

Comments
 (0)