tj.git-extras/tests/git-authors.bats
Edwin Kofler 18ecffef5e
Some checks failed
ci / lint (push) Has been cancelled
ci / typo (push) Has been cancelled
ci / test (push) Has been cancelled
ci / build (macos-latest) (push) Has been cancelled
ci / build (ubuntu-latest) (push) Has been cancelled
Implement half of tests in Bats (#1187)
* Initial scaffold

* Finish first half of Bats tests

* Add Bats to CI

* Fix CI

* Fix CI

* Fix configuration to set git name and email

* Fix `GIT_CONFIG_{KEY,VALUE}` indexing

* Fix Git config override precedence

* Remove unused and untested function
2025-03-12 18:15:37 +08:00

53 lines
1.1 KiB
Bash

# shellcheck shell=bash
source "$BATS_TEST_DIRNAME/test_util.sh"
setup_file() {
test_util.setup_file
}
setup() {
test_util.cd_test
git init
GIT_CONFIG_VALUE_0='test@example.com'
GIT_CONFIG_VALUE_1='test'
printf '%s\n' 'A' > tmpfile
git add .
git commit -m 'test: add data A'
GIT_CONFIG_VALUE_0='testagain@example.com'
GIT_CONFIG_VALUE_1='testagain'
printf '%s\n' 'B' > tmpfile
git add .
git commit -m 'test: add data B'
}
@test "output authors has email without any parameter" {
run git authors
assert_success
local content=$(<AUTHORS)
assert_equal "$content" $'test <test@example.com>\ntestagain <testagain@example.com>'
}
@test "list authors has email defaultly" {
run git authors --list
assert_output $'test <test@example.com>\ntestagain <testagain@example.com>'
assert_success
run git authors -l
assert_output $'test <test@example.com>\ntestagain <testagain@example.com>'
assert_success
}
@test "list authors has no email" {
run git authors --list --no-email
assert_output $'test\ntestagain'
assert_success
run git authors -l --no-email
assert_output $'test\ntestagain'
assert_success
}