Skip to content
Merged
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
14 changes: 0 additions & 14 deletions diff-so-fancy
Original file line number Diff line number Diff line change
Expand Up @@ -490,26 +490,12 @@ sub git_config_boolean {
my $search_key = lc($_[0] || "");
my $default_value = lc($_[1] || 0); # Default to false

# If we're in a unit test, use the default (don't read the users config)
if (in_unit_test()) {
return boolean($default_value);
}

my $result = git_config($search_key,$default_value);
my $ret = boolean($result);

return $ret;
}

# Check if we're inside of BATS
sub in_unit_test {
if ($ENV{BATS_CWD}) {
return 1;
} else {
return 0;
}
}

sub get_less_charset {
my @less_char_vars = ("LESSCHARSET", "LESSCHARDEF", "LC_ALL", "LC_CTYPE", "LANG");
foreach my $key (@less_char_vars) {
Expand Down
22 changes: 19 additions & 3 deletions test/bugs.bats
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
#!/usr/bin/env bats

load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/util'
# Used by both `setup_file` and `setup`, which are special bats callbacks.
__load_imports__() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/util'
}

setup_file() {
__load_imports__
setup_default_dsf_git_config
}

setup() {
__load_imports__
}

teardown_file() {
teardown_default_dsf_git_config
}

# https://github.com/paulirish/dotfiles/commit/6743b907ff586c28cd36e08d1e1c634e2968893e#commitcomment-13459061
@test "All removed lines are present in diff" {
Expand Down
28 changes: 22 additions & 6 deletions test/diff-so-fancy.bats
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/usr/bin/env bats

load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/util'
# Helper invoked by `setup_file` and `setup`, which are special bats callbacks.
__load_imports__() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load 'test_helper/util'
}

set_env
setup_file() {
__load_imports__
set_env
setup_default_dsf_git_config
# bats fails to handle our multiline result, so we save to $output ourselves
__dsf_cached_output="$( load_fixture "ls-function" | $diff_so_fancy )"
export __dsf_cached_output
}

# bats fails to handle our multiline result, so we save to $output ourselves
output=$( load_fixture "ls-function" | $diff_so_fancy )
setup() {
__load_imports__
output="${__dsf_cached_output}"
}

teardown_file() {
teardown_default_dsf_git_config
}

@test "diff-so-fancy runs and exits without error" {
load_fixture "ls-function" | $diff_so_fancy
Expand Down
39 changes: 29 additions & 10 deletions test/test_helper/util.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,36 @@ set_env() {
export LC_CTYPE="en_US.UTF-8"
}

dsf_test_git_config() {
printf '%s/gitconfig' "${BATS_TMPDIR}"
}

# applying colors so ANSI color values will match
# FIXME: not everyone will have these set, so we need to test for that.
git config color.diff.meta "227"
git config color.diff.frag "magenta bold"
git config color.diff.commit "227 bold"
git config color.diff.old "red bold"
git config color.diff.new "green bold"
git config color.diff.whitespace "red reverse"
setup_default_dsf_git_config() {
GIT_CONFIG="$(dsf_test_git_config)" || return $?
cat > "${GIT_CONFIG}" <<EOF || return $?
[color "diff"]
meta = 227
frag = magenta bold
commit = 227 bold
old = red bold
new = green bold
whitespace = red reverse

[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22
EOF
export GIT_CONFIG
export GIT_CONFIG_NOSYSTEM=1
}

git config color.diff-highlight.oldNormal "red bold"
git config color.diff-highlight.oldHighlight "red bold 52"
git config color.diff-highlight.newNormal "green bold"
git config color.diff-highlight.newHighlight "green bold 22"
teardown_default_dsf_git_config() {
local test_config
test_config="$(dsf_test_git_config)" || return $?
[ ! -f "${test_config}" ] || rm -f "${test_config}"
GIT_CONFIG=/dev/null
}