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
This commit is contained in:
Junio C Hamano
2021-04-20 17:23:34 -07:00
9 changed files with 213 additions and 109 deletions

View File

@@ -479,22 +479,26 @@ test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
'
test_expect_success 'setup -L :funcname with userdiff driver' '
echo "fortran-* diff=fortran" >.gitattributes &&
fortran_file=fortran-external-function &&
orig_file="$TEST_DIRECTORY/t4018/$fortran_file" &&
cp "$orig_file" . &&
git add "$fortran_file" &&
GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" \
git commit -m "add fortran file" &&
sed -e "s/ChangeMe/IWasChanged/" <"$orig_file" >"$fortran_file" &&
git add "$fortran_file" &&
GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" \
git commit -m "change fortran file"
'
test_expect_success 'blame -L :funcname with userdiff driver' '
check_count -f fortran-external-function -L:RIGHT A 7 B 1
cat >file.template <<-\EOF &&
DO NOT MATCH THIS LINE
function RIGHT(a, b) result(c)
AS THE DEFAULT DRIVER WOULD
integer, intent(in) :: ChangeMe
EOF
fortran_file=file.f03 &&
test_when_finished "rm .gitattributes" &&
echo "$fortran_file diff=fortran" >.gitattributes &&
test_commit --author "A <A@test.git>" \
"add" "$fortran_file" \
"$(cat file.template)" &&
test_commit --author "B <B@test.git>" \
"change" "$fortran_file" \
"$(cat file.template | sed -e s/ChangeMe/IWasChanged/)" &&
check_count -f "$fortran_file" -L:RIGHT A 3 B 1
'
test_expect_success 'setup incremental' '

View File

@@ -73,6 +73,7 @@ static struct test_cmd cmds[] = {
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
{ "subprocess", cmd__subprocess },
{ "trace2", cmd__trace2 },
{ "userdiff", cmd__userdiff },
{ "urlmatch-normalization", cmd__urlmatch_normalization },
{ "xml-encode", cmd__xml_encode },
{ "wildmatch", cmd__wildmatch },

View File

@@ -63,6 +63,7 @@ int cmd__submodule_config(int argc, const char **argv);
int cmd__submodule_nested_repo_config(int argc, const char **argv);
int cmd__subprocess(int argc, const char **argv);
int cmd__trace2(int argc, const char **argv);
int cmd__userdiff(int argc, const char **argv);
int cmd__urlmatch_normalization(int argc, const char **argv);
int cmd__xml_encode(int argc, const char **argv);
int cmd__wildmatch(int argc, const char **argv);

46
t/helper/test-userdiff.c Normal file
View File

@@ -0,0 +1,46 @@
#include "test-tool.h"
#include "cache.h"
#include "userdiff.h"
#include "config.h"
static int driver_cb(struct userdiff_driver *driver,
enum userdiff_driver_type type, void *priv)
{
enum userdiff_driver_type *want_type = priv;
if (type & *want_type && driver->funcname.pattern)
puts(driver->name);
return 0;
}
static int cmd__userdiff_config(const char *var, const char *value, void *cb)
{
if (userdiff_config(var, value) < 0)
return -1;
return 0;
}
int cmd__userdiff(int argc, const char **argv)
{
enum userdiff_driver_type want = 0;
if (argc != 2)
return 1;
if (!strcmp(argv[1], "list-drivers"))
want = (USERDIFF_DRIVER_TYPE_BUILTIN |
USERDIFF_DRIVER_TYPE_CUSTOM);
else if (!strcmp(argv[1], "list-builtin-drivers"))
want = USERDIFF_DRIVER_TYPE_BUILTIN;
else if (!strcmp(argv[1], "list-custom-drivers"))
want = USERDIFF_DRIVER_TYPE_CUSTOM;
else
return error("unknown argument %s", argv[1]);
if (want & USERDIFF_DRIVER_TYPE_CUSTOM) {
setup_git_directory();
git_config(cmd__userdiff_config, NULL);
}
for_each_userdiff_driver(driver_cb, &want);
return 0;
}

View File

@@ -25,34 +25,26 @@ test_expect_success 'setup' '
echo B >B.java
'
test_expect_success 'setup: test-tool userdiff' '
# Make sure additions to builtin_drivers are sorted
test_when_finished "rm builtin-drivers.sorted" &&
test-tool userdiff list-builtin-drivers >builtin-drivers &&
test_file_not_empty builtin-drivers &&
sort <builtin-drivers >builtin-drivers.sorted &&
test_cmp builtin-drivers.sorted builtin-drivers &&
# Ditto, but "custom" requires the .git directory and config
# to be setup and read.
test_when_finished "rm custom-drivers.sorted" &&
test-tool userdiff list-custom-drivers >custom-drivers &&
test_file_not_empty custom-drivers &&
sort <custom-drivers >custom-drivers.sorted &&
test_cmp custom-drivers.sorted custom-drivers
'
diffpatterns="
ada
bash
bibtex
cpp
csharp
css
dts
elixir
fortran
fountain
golang
html
java
markdown
matlab
objc
pascal
perl
php
python
ruby
rust
scheme
tex
custom1
custom2
custom3
$(cat builtin-drivers)
$(cat custom-drivers)
"
for p in $diffpatterns
@@ -102,13 +94,7 @@ test_expect_success 'setup hunk header tests' '
# check each individual file
for i in $(git ls-files)
do
if grep broken "$i" >/dev/null 2>&1
then
result=failure
else
result=success
fi
test_expect_$result "hunk header: $i" "
test_expect_success "hunk header: $i" "
git diff -U1 $i >actual &&
grep '@@ .* @@.*RIGHT' actual
"

View File

@@ -7,9 +7,6 @@ at least two lines from the line that must appear in the hunk header.
The text that must appear in the hunk header must contain the word
"right", but in all upper-case, like in the title above.
To mark a test case that highlights a malfunction, insert the word
BROKEN in all lower-case somewhere in the file.
This text is a bit twisted and out of order, but it is itself a
test case for the default hunk header pattern. Know what you are doing
if you change it.