Skip to content

Commit ab99efc

Browse files
committed
Merge branch 'ab/userdiff-tests'
A bit of code clean-up and a lot of test clean-up around userdiff area. * ab/userdiff-tests: blame tests: simplify userdiff driver test blame tests: don't rely on t/t4018/ directory userdiff: remove support for "broken" tests userdiff tests: list builtin drivers via test-tool userdiff tests: explicitly test "default" pattern userdiff: add and use for_each_userdiff_driver() userdiff style: normalize pascal regex declaration userdiff style: declare patterns with consistent style userdiff style: re-order drivers in alphabetical order
2 parents 6d7a62d + f08b401 commit ab99efc

File tree

9 files changed

+213
-109
lines changed

9 files changed

+213
-109
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
753753
TEST_BUILTINS_OBJS += test-subprocess.o
754754
TEST_BUILTINS_OBJS += test-trace2.o
755755
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
756+
TEST_BUILTINS_OBJS += test-userdiff.o
756757
TEST_BUILTINS_OBJS += test-wildmatch.o
757758
TEST_BUILTINS_OBJS += test-windows-named-pipe.o
758759
TEST_BUILTINS_OBJS += test-write-cache.o

t/annotate-tests.sh

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -479,22 +479,26 @@ test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
479479
check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
480480
'
481481

482-
test_expect_success 'setup -L :funcname with userdiff driver' '
483-
echo "fortran-* diff=fortran" >.gitattributes &&
484-
fortran_file=fortran-external-function &&
485-
orig_file="$TEST_DIRECTORY/t4018/$fortran_file" &&
486-
cp "$orig_file" . &&
487-
git add "$fortran_file" &&
488-
GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="[email protected]" \
489-
git commit -m "add fortran file" &&
490-
sed -e "s/ChangeMe/IWasChanged/" <"$orig_file" >"$fortran_file" &&
491-
git add "$fortran_file" &&
492-
GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="[email protected]" \
493-
git commit -m "change fortran file"
494-
'
495-
496482
test_expect_success 'blame -L :funcname with userdiff driver' '
497-
check_count -f fortran-external-function -L:RIGHT A 7 B 1
483+
cat >file.template <<-\EOF &&
484+
DO NOT MATCH THIS LINE
485+
function RIGHT(a, b) result(c)
486+
AS THE DEFAULT DRIVER WOULD
487+
488+
integer, intent(in) :: ChangeMe
489+
EOF
490+
491+
fortran_file=file.f03 &&
492+
test_when_finished "rm .gitattributes" &&
493+
echo "$fortran_file diff=fortran" >.gitattributes &&
494+
495+
test_commit --author "A <[email protected]>" \
496+
"add" "$fortran_file" \
497+
"$(cat file.template)" &&
498+
test_commit --author "B <[email protected]>" \
499+
"change" "$fortran_file" \
500+
"$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" &&
501+
check_count -f "$fortran_file" -L:RIGHT A 3 B 1
498502
'
499503

500504
test_expect_success 'setup incremental' '

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static struct test_cmd cmds[] = {
7373
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
7474
{ "subprocess", cmd__subprocess },
7575
{ "trace2", cmd__trace2 },
76+
{ "userdiff", cmd__userdiff },
7677
{ "urlmatch-normalization", cmd__urlmatch_normalization },
7778
{ "xml-encode", cmd__xml_encode },
7879
{ "wildmatch", cmd__wildmatch },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int cmd__submodule_config(int argc, const char **argv);
6363
int cmd__submodule_nested_repo_config(int argc, const char **argv);
6464
int cmd__subprocess(int argc, const char **argv);
6565
int cmd__trace2(int argc, const char **argv);
66+
int cmd__userdiff(int argc, const char **argv);
6667
int cmd__urlmatch_normalization(int argc, const char **argv);
6768
int cmd__xml_encode(int argc, const char **argv);
6869
int cmd__wildmatch(int argc, const char **argv);

t/helper/test-userdiff.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "test-tool.h"
2+
#include "cache.h"
3+
#include "userdiff.h"
4+
#include "config.h"
5+
6+
static int driver_cb(struct userdiff_driver *driver,
7+
enum userdiff_driver_type type, void *priv)
8+
{
9+
enum userdiff_driver_type *want_type = priv;
10+
if (type & *want_type && driver->funcname.pattern)
11+
puts(driver->name);
12+
return 0;
13+
}
14+
15+
static int cmd__userdiff_config(const char *var, const char *value, void *cb)
16+
{
17+
if (userdiff_config(var, value) < 0)
18+
return -1;
19+
return 0;
20+
}
21+
22+
int cmd__userdiff(int argc, const char **argv)
23+
{
24+
enum userdiff_driver_type want = 0;
25+
if (argc != 2)
26+
return 1;
27+
28+
if (!strcmp(argv[1], "list-drivers"))
29+
want = (USERDIFF_DRIVER_TYPE_BUILTIN |
30+
USERDIFF_DRIVER_TYPE_CUSTOM);
31+
else if (!strcmp(argv[1], "list-builtin-drivers"))
32+
want = USERDIFF_DRIVER_TYPE_BUILTIN;
33+
else if (!strcmp(argv[1], "list-custom-drivers"))
34+
want = USERDIFF_DRIVER_TYPE_CUSTOM;
35+
else
36+
return error("unknown argument %s", argv[1]);
37+
38+
if (want & USERDIFF_DRIVER_TYPE_CUSTOM) {
39+
setup_git_directory();
40+
git_config(cmd__userdiff_config, NULL);
41+
}
42+
43+
for_each_userdiff_driver(driver_cb, &want);
44+
45+
return 0;
46+
}

t/t4018-diff-funcname.sh

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,26 @@ test_expect_success 'setup' '
2525
echo B >B.java
2626
'
2727

28+
test_expect_success 'setup: test-tool userdiff' '
29+
# Make sure additions to builtin_drivers are sorted
30+
test_when_finished "rm builtin-drivers.sorted" &&
31+
test-tool userdiff list-builtin-drivers >builtin-drivers &&
32+
test_file_not_empty builtin-drivers &&
33+
sort <builtin-drivers >builtin-drivers.sorted &&
34+
test_cmp builtin-drivers.sorted builtin-drivers &&
35+
36+
# Ditto, but "custom" requires the .git directory and config
37+
# to be setup and read.
38+
test_when_finished "rm custom-drivers.sorted" &&
39+
test-tool userdiff list-custom-drivers >custom-drivers &&
40+
test_file_not_empty custom-drivers &&
41+
sort <custom-drivers >custom-drivers.sorted &&
42+
test_cmp custom-drivers.sorted custom-drivers
43+
'
44+
2845
diffpatterns="
29-
ada
30-
bash
31-
bibtex
32-
cpp
33-
csharp
34-
css
35-
dts
36-
elixir
37-
fortran
38-
fountain
39-
golang
40-
html
41-
java
42-
markdown
43-
matlab
44-
objc
45-
pascal
46-
perl
47-
php
48-
python
49-
ruby
50-
rust
51-
scheme
52-
tex
53-
custom1
54-
custom2
55-
custom3
46+
$(cat builtin-drivers)
47+
$(cat custom-drivers)
5648
"
5749

5850
for p in $diffpatterns
@@ -102,13 +94,7 @@ test_expect_success 'setup hunk header tests' '
10294
# check each individual file
10395
for i in $(git ls-files)
10496
do
105-
if grep broken "$i" >/dev/null 2>&1
106-
then
107-
result=failure
108-
else
109-
result=success
110-
fi
111-
test_expect_$result "hunk header: $i" "
97+
test_expect_success "hunk header: $i" "
11298
git diff -U1 $i >actual &&
11399
grep '@@ .* @@.*RIGHT' actual
114100
"

t/t4018/README

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ at least two lines from the line that must appear in the hunk header.
77
The text that must appear in the hunk header must contain the word
88
"right", but in all upper-case, like in the title above.
99

10-
To mark a test case that highlights a malfunction, insert the word
11-
BROKEN in all lower-case somewhere in the file.
12-
1310
This text is a bit twisted and out of order, but it is itself a
1411
test case for the default hunk header pattern. Know what you are doing
1512
if you change it.

0 commit comments

Comments
 (0)