Skip to content

Commit

Permalink
Merge pull request #52 from groggemans/update-tests
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
Zach Kelling committed May 6, 2016
2 parents 9451b01 + 402b29b commit d1e159f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 43 deletions.
106 changes: 75 additions & 31 deletions test/ellipsis.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,23 @@ setup() {
export ELLIPSIS_PACKAGES="$ELLIPSIS_HOME/.ellipsis/packages"
mkdir -p "$ELLIPSIS_PACKAGES"
echo 'old' > "$ELLIPSIS_HOME/.file"
}

clone_test_package() {
git clone "$TESTS_DIR/fixtures/dot-test" "$ELLIPSIS_PACKAGES/test" &>/dev/null
}

link_test_package() {
mv "$ELLIPSIS_HOME/.file" "$ELLIPSIS_HOME/.file.bak"
ln -s "$ELLIPSIS_PACKAGES/test/common/file" "$ELLIPSIS_HOME/.file"
}

link_broken() {
ln -s "$ELLIPSIS_PACKAGES/test/doesnotexist" "$ELLIPSIS_HOME/.doesnotexist"
}

modify_test_package() {
echo modified > "$ELLIPSIS_PACKAGES/test/common/file"
}

if [ $BATS_TEST_NUMBER -gt 2 ]; then
clone_test_package
fi
clone_test_package() {
git clone "$TESTS_DIR/fixtures/dot-test" "$ELLIPSIS_PACKAGES/test" &>/dev/null
}

if [ $BATS_TEST_NUMBER -gt 3 ]; then
link_test_package
fi
link_test_package() {
mv "$ELLIPSIS_HOME/.file" "$ELLIPSIS_HOME/.file.bak"
ln -s "$ELLIPSIS_PACKAGES/test/common/file" "$ELLIPSIS_HOME/.file"
}

if [ $BATS_TEST_NUMBER -eq 13 ] || [ $BATS_TEST_NUMBER -eq 14 ]; then
link_broken
fi
link_broken() {
ln -s "$ELLIPSIS_PACKAGES/test/doesnotexist" "$ELLIPSIS_HOME/.doesnotexist"
}

if [ $BATS_TEST_NUMBER -eq 15 ]; then
modify_test_package
fi
modify_test_package() {
echo modified > "$ELLIPSIS_PACKAGES/test/common/file"
}

teardown() {
Expand Down Expand Up @@ -70,94 +54,154 @@ teardown() {
}

@test "ellipsis.link should link a package" {
# Test specific setup
clone_test_package

run ellipsis.link test
[ $status -eq 0 ]
[ -L "$ELLIPSIS_HOME/.file" ]
}

@test "ellipsis.uninstall should uninstall a package" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.uninstall test
[ $status -eq 0 ]
[ ! -e "$ELLIPSIS_PACKAGES/test/ellipsis.sh" ]
[ ! -e "$ELLIPSIS_HOME/.file" ]
}

@test "ellipsis.unlink should unlink a package" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.unlink test
[ $status -eq 0 ]
[ ! -L "$ELLIPSIS_HOME/.file" ]
}

@test "ellipsis.installed should list installed packages" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.installed
[ $status -eq 0 ]
[[ "$(utils.strip_colors ${lines[0]})" == ellipsis* ]] || false
[[ "$(utils.strip_colors ${lines[1]})" == test* ]] || false
}

@test "ellipsis.edit should edit package ellipsis.sh" {
# Test specific setup
clone_test_package
link_test_package

export EDITOR=cat
run ellipsis.edit test
[ $status -eq 0 ]
[ "${lines[0]}" = "#!/usr/bin/env bash" ]
}

@test "ellipsis.new should create a new package" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.new foo
[ $status -eq 0 ]
[ -e "$ELLIPSIS_PACKAGES/foo/ellipsis.sh" ]
[ -e "$ELLIPSIS_PACKAGES/foo/README.md" ]
}

@test "ellipsis.each should run hook for each installed package" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.each pkg.run_hook "installed"
[ $status -eq 0 ]
[[ "$(utils.strip_colors ${lines[0]})" == ellipsis* ]] || false
[[ "$(utils.strip_colors ${lines[1]})" == test* ]] || false
}

@test "ellipsis.list_packages should list installed packages" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.list_packages
[ $status -eq 0 ]
[[ "$output" == "$ELLIPSIS_PACKAGES/test" ]] || false
}

@test "ellipsis.links should list symlinks to installed packages" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.links
[ $status -eq 0 ]
[[ "${lines[0]}" == test/common/file* ]] || false
}

@test "ellipsis.broken should not list symlinks if none are broken" {
# Test specific setup
clone_test_package
link_test_package

run ellipsis.broken
[[ "$output" == "" ]] || false
}

@test "ellipsis.broken should list broken symlinks" {
# Test specific setup
link_broken

run ellipsis.broken
[[ "$output" == test/doesnotexist* ]] || false
}

@test "ellipsis.clean should remove broken symlinks from ELLIPSIS_HOME" {
# Test specific setup
link_broken

run ellipsis.clean
[ $status -eq 0 ]
[ ! -e "$ELLIPSIS_HOME/.doesnotexist" ]
}

@test "ellipsis.status should show diffstat if changes in packages" {
# Test specific setup
clone_test_package
link_test_package
modify_test_package

run ellipsis.status
[ $status -eq 0 ]
[[ "$output" = *common/file* ]] || false
}

@test "ellipsis.pull should update packages" {
skip
skip "No test implementation"

# Test specific setup
clone_test_package
link_test_package

run ellipsis.pull
[ $status -eq 0 ]
}

@test "ellipsis.push should push changes in packages" {
skip
skip "No test implementation"

# Test specific setup
clone_test_package
link_test_package

run ellipsis.push
[ $status -eq 0 ]
}
20 changes: 10 additions & 10 deletions test/pkg.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ teardown() {
}

@test "pkg.name_from_path should derive package name from package path" {
skip
skip "No test implementation"
}

@test "pkg.path_from_name should derive package path from package name" {
skip
skip "No test implementation"
}

@test "pkg.init_globals should setup PKG_PATH and PKG_NAME properly" {
skip
skip "No test implementation"
}

@test "pkg.init should initialize globals for package and source hooks" {
skip
skip "No test implementation"
}

@test "pkg.list_symlinks should list symlinks for package" {
skip
skip "No test implementation"
}

@test "pkg.symlinks_mappings should list symlink mappings for package" {
skip
skip "No test implementation"
}

@test "pkg.run should run command or hook from PKG_PATH" {
skip
skip "No test implementation"
}

@test "pkg.run_hook should run_hook from PKG_PATH" {
skip
skip "No test implementation"
}

@test "pkg.del should unset globals/hooks setup by package initialization" {
skip
skip "No test implementation"
}

@test "pkg.del should unset globals/hooks setup by package initialization" {
skip
skip "No test implementation"
}
4 changes: 2 additions & 2 deletions test/utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ teardown() {
}

@test "utils.prompt should return true if yes otherwise no" {
skip
skip "No test implementation"
run echo y | utils.prompt "select yes"
[ $status -eq 0 ]
}

@test "utils.prompt should return true if yes otherwise no" {
skip
skip "No test implementation"
run echo n | utils.prompt "select yes"
[ $status -eq 1 ]
}
Expand Down

0 comments on commit d1e159f

Please sign in to comment.