Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore_paths: ./completion.*
ignore_paths: ./completion.*, ./t/sharness.sh
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:
name: Sharness tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run test suite
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t/test-results/
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ PREFIX?=/usr/local
INSTALLDIR?=$(PREFIX)
INSTALL=install

TESTS?=$(wildcard t/t[0-9]*.sh)

test:
@prove $(TESTS)

install:
${INSTALL} -d ${DESTDIR}${INSTALLDIR}/bin
${INSTALL} -m755 git-fixup ${DESTDIR}${INSTALLDIR}/bin/git-fixup
Expand Down
96 changes: 96 additions & 0 deletions t/sharness.d/git-fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Shared test helpers for the git-fixup test suite.
#
# This file is sourced automatically by sharness through t/sharness.d/.
# shellcheck shell=sh
# shellcheck disable=SC2154

# Isolate the tests from the user's own git configuration.
XDG_CONFIG_HOME="$SHARNESS_TRASH_DIRECTORY/.config"; export XDG_CONFIG_HOME
# Editing should never block or spawn an interactive editor during tests.
GIT_EDITOR=:; export GIT_EDITOR
GIT_SEQUENCE_EDITOR=:; export GIT_SEQUENCE_EDITOR
# Test repositories get a fixed identity from the environment, so tests do not
# need per-repository git config for an author and committer (as in git/git).
GIT_AUTHOR_NAME="Test User"; export GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL=test@test.com; export GIT_AUTHOR_EMAIL
GIT_COMMITTER_NAME="Test User"; export GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL=test@test.com; export GIT_COMMITTER_EMAIL

# Compare two files and print a unified diff when they differ.
test_cmp () {
diff -u "$2" "$1"
}

# Write <content> to <file>, honouring printf escapes such as \n, and stage
# the new content in the current repository.
stage_file () {
file=$1
content=$2
printf '%b' "$content" >"$file" &&
git add -- "$file"
}

# Write <content> to <file> and commit it, like git/git's test_commit() but
# without creating a tag.
commit_file () {
message=$1
file=$2
content=$3
stage_file "$file" "$content" &&
git commit -m "$message" >/dev/null
}

# Create a fresh non-bare repository <name> in the trash directory and cd into
# it.
fresh_repo () {
name=$1
cd "$SHARNESS_TRASH_DIRECTORY" &&
rm -rf "$name" &&
git init -q "$name" &&
cd "$name"
}

# Create a repository <name>repo cloned from a bare <name>remote and cd into
# it.
clone_repo () {
name=$1
cd "$SHARNESS_TRASH_DIRECTORY" &&
rm -rf "$name"remote "$name"repo &&
git init -q --bare "$name"remote &&
git clone -q "$name"remote "$name"repo &&
cd "$name"repo
}

# Create a repository tracked by a remote. The upstream is pushed after the
# second commit, so the candidate search range covers "Add line three" and the
# remote-tracking branch resolves for @{upstream}.
#
# Commits:
# Initial commit
# Add line two <- origin/master
# Add line three
setup_repo () {
(
# A subshell scopes errexit, so a failing git command stops the
# setup without && chains and without leaking state to the tests.
set -e
cd "$SHARNESS_TRASH_DIRECTORY"
rm -rf remote repo
git init -q --bare remote
git clone -q remote repo
cd repo
commit_file "Initial commit" file.txt 'line one\n'
commit_file "Add line two" file.txt 'line one\nline two\n'
git push -q -u origin master
commit_file "Add line three" file.txt 'line one\nline two\nline three\n'
) || return 1
# Tests leave the working directory inside the previous repo, so restore
# it for the next test body that cd's into the freshly created one.
cd "$SHARNESS_TRASH_DIRECTORY" || return 1
}

# Stage an extra line in file.txt
stage_change () {
echo "$1" >>file.txt &&
git add file.txt
}
Loading
Loading