Skip to content

Instantly share code, notes, and snippets.

@ctubbsii
Created April 26, 2022 18:17
Show Gist options
  • Save ctubbsii/e17bcc9d5a4b71db68b748dd2b6919cf to your computer and use it in GitHub Desktop.
Save ctubbsii/e17bcc9d5a4b71db68b748dd2b6919cf to your computer and use it in GitHub Desktop.
git-diffTests : create a Maven command line with -Dtest= and -Dit.test= for changed tests
#! /usr/bin/bash
function findTests() {
{
echo 'blah'
git diff --name-only "$2" | grep "$1[.]java" | xargs -n1 basename 2>/dev/null | cut -f1 -d.
} | paste -sd,
}
if [[ -z $1 ]]; then
testarg="-Dtest=$(findTests Test HEAD)"
itarg="-Dit.test=$(findTests IT HEAD)"
else
testarg="-Dtest=$(findTests Test "$1")"
itarg="-Dit.test=$(findTests IT "$1")"
fi
echo "$testarg $itarg" 1>&2
echo "$testarg $itarg"
@DomGarguilo
Copy link

It would be helpful to have the option to run all tests that are different from a specified branch. I find that I often want to run all tests that differ from main, where the changes have already been committed so wont be picked up by the current state of this util.

I have made a small maven project that parses a text file that is populated by git diff --name-status main > diff.txt and provides an output very similar to this tool.

@ctubbsii
Copy link
Author

It would be helpful to have the option to run all tests that are different from a specified branch.

Already supported. That's what lines 14 and 15 do.

I have made a small maven project that parses a text file that is populated by git diff --name-status main > diff.txt and provides an output very similar to this tool.

mvn clean verify $(git-diffTests main)

@DomGarguilo
Copy link

Whoops, I missed that part. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment