Skip to content

Commit 3dfb846

Browse files
committed
Run tests based on sources modifications
There is a new command called `robot` added to `workflows` file that runs the tests for the Elegant Git commands with modified source files or their tests. Also, if interactive mode works, only `testing` command will ask for additional arguments. These changes aim to improve the development experience.
1 parent e5bb290 commit 3dfb846

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

workflows

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,39 @@ publish-worker() {
6060
docker push beeshive/elegant-git-ci:${1}
6161
}
6262

63+
robot() {
64+
# runs a
65+
local smart_testing_status=""
66+
local command_files=($(git ls-files --modified --other -- libexec/git-elegant*))
67+
68+
for command_file in ${command_files[@]}; do
69+
local command_name=$(basename ${command_file})
70+
if ! test -f tests/${command_name}.bats; then continue; fi
71+
( testing ${command_name} && info-text "'${command_file}' testing is passed." ) || {
72+
error-text "'${command_name}' testing is failed."
73+
smart_testing_status=failed
74+
}
75+
done
76+
local tests_files=($(git ls-files --modified --other -- tests/git-elegant*.bats))
77+
for test_file in ${tests_files[@]}; do
78+
local file_name=$(basename ${test_file})
79+
if [[ ${command_files[@]} =~ "${file_name/.bats/}" ]] ; then
80+
continue # already tested
81+
fi
82+
if ! test -f tests/${command_name}.bats; then continue; fi
83+
( testing ${file_name} && info-text "'${file_name}' testing is passed.") || {
84+
error-text "'${file_name}' testing is failed."
85+
smart_testing_status=failed
86+
}
87+
done
88+
if test -z "${smart_testing_status}"; then
89+
info-text "Everything is great!"
90+
else
91+
error-text "Something should be improved!"
92+
exit 1
93+
fi
94+
}
95+
6396
usage() {
6497
cat <<MESSAGE
6598
usage: ${BASH_SOURCE[0]} [command] [arg]...
@@ -69,6 +102,8 @@ Available commands:
69102
testing runs bats tests; accepts a optional pattern for tests
70103
filtering ("${BASH_SOURCE[0]} testing work" run all tests
71104
which have the word in the test name)
105+
robot runs tests for updated "libexec/git-elegant*" or
106+
"tests/git-elegant*.bats" files
72107
repository creates a git repository and installs Elegant Git within
73108
generate-docs generates fresh commands documentation bases on the latest
74109
changes
@@ -83,6 +118,7 @@ MESSAGE
83118
commands=(
84119
usage
85120
testing
121+
robot
86122
repository
87123
generate-docs
88124
preview-docs
@@ -99,8 +135,10 @@ main() {
99135
echo ""
100136
select any in ${commands[@]}; do
101137
command=${any}
102-
question-text "Please give the arguments: "
103-
read args
138+
if test ${command} = testing; then
139+
question-text "Please give the tests pattern: "
140+
read args
141+
fi
104142
break
105143
done
106144
else

0 commit comments

Comments
 (0)