Skip to content

Commit

Permalink
avoiding duplicate path elements on push and append (fix #1) (#41)
Browse files Browse the repository at this point in the history
* reproducing issue #1 in the 'push' and 'append' commands test

* ci housekeeping

* fixed push and append dedup elements
  • Loading branch information
sha1n authored Sep 20, 2024
1 parent 509a40a commit c2970cd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Install Zsh
if: runner.os == 'Linux'
run: |
Expand All @@ -33,8 +36,8 @@ jobs:
- name: Zsh Version
run: zsh --version

- name: Update Submodules
run: make update_submodules
- name: Initialize Submodules
run: make init

- name: Run Tests
run: make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BASEDIR := $(shell pwd)
default: test

test:
@-$(BASEDIR)/tests/zsh-scriptest/run_tests.sh $(BASEDIR)/tests
$(BASEDIR)/tests/zsh-scriptest/run_tests.sh $(BASEDIR)/tests


init:
Expand Down
8 changes: 6 additions & 2 deletions peth-edit.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ function __pe_reset() {

# Prepends the specified path element re-exports PATH
function __pe_push() {
local original_path=$(__pe_strip_original_path)
PATH_ETHIC_HEAD=$(__pe_normalize_path "$1:$PATH_ETHIC_HEAD")
__pe_reexport_path

__pe_reexport_path "$original_path"
}

# Appends the specified path element re-exports PATH
function __pe_append() {
local original_path=$(__pe_strip_original_path)
PATH_ETHIC_TAIL=$(__pe_normalize_path "$PATH_ETHIC_TAIL:$1")
__pe_reexport_path

__pe_reexport_path "$original_path"
}

function __pe_add_path_element() {
Expand Down
20 changes: 14 additions & 6 deletions tests/path_edit_commands.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,32 @@ function test_peth_reset() {
function test_peth_push() {
before_each

local push_path=$(mktemp -d)
local push_path1=$(mktemp -d)
local push_path2=$(mktemp -d)
local original_path="$PATH"

peth push $push_path
peth push $push_path1
peth push $push_path2

assert_equal $PATH_ETHIC_HEAD $push_path
assert_equal $PATH_ETHIC_HEAD "$push_path2:$push_path1"
assert_equal $PATH_ETHIC_TAIL ""
assert_equal $PATH "$PATH_ETHIC_HEAD:$original_path"
}

# peth append #################################################################
function test_peth_append() {
before_each

local append_path=$(mktemp -d)
local append_path1=$(mktemp -d)
local append_path2=$(mktemp -d)
local original_path="$PATH"

peth append $append_path
peth append $append_path1
peth append $append_path2

assert_equal $PATH_ETHIC_TAIL $append_path
assert_equal $PATH_ETHIC_TAIL "$append_path1:$append_path2"
assert_equal $PATH_ETHIC_HEAD ""
assert_equal $PATH "$original_path:$PATH_ETHIC_TAIL"
}

# peth flip #####################################################################
Expand Down
1 change: 1 addition & 0 deletions tests/unit.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env zsh

autoload -U colors && colors

source "$__ZSH_SCRIPTEST_HOME/matchers.sh"
Expand Down
2 changes: 1 addition & 1 deletion tests/zsh-scriptest
Submodule zsh-scriptest updated 1 files
+8 −0 test_util.sh

0 comments on commit c2970cd

Please sign in to comment.