Skip to content

Commit

Permalink
test: add snapshot, add test shortcut script
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed Aug 19, 2024
1 parent a4be269 commit 2947ceb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
sudo apt install zsh -y
- name: Run Tests
run: ./test/git-open.test.zsh
run: ./test
release:
needs:
- test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
sudo apt install zsh -y
- name: Run Tests
run: ./test/git-open.test.zsh
run: ./test
3 changes: 3 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env zsh

. "${0:A:h}/tests/test.zsh"
13 changes: 13 additions & 0 deletions tests/snapshot.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Usage: git open [-s] <command>

Commands:
project|repo|repository|open|. Open the project
branch Open the project at given (or current) branch
commit Open the project at given (or current) commit
file Open the project at given file. Can also append ref hash
prs|mrs Open the PR list
pr|mr Open a new PR
actions|pipelines|ci Open the CI/CD pipelines

Flags:
-s, --silent Silent mode (no output)
14 changes: 9 additions & 5 deletions test/git-open.test.zsh → tests/test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ if [[ -z "$TERM" ]]; then
fi

### Setup
echo "$(tput setaf 4)Setting up...$(tput sgr0)"

snapshot="${0:A:h}/snapshot.txt"
current_branch=$(git branch --show-current)
current_ref=$(git rev-parse HEAD)
remote_url=$(git remote -v | grep "(push)" | awk '{print $2}')

__UTILS_PATH="${0:A:h}/utils.mock.zsh" \
__UNLOAD_PATH="/dev/null" \
. "${0:A:h}/../git-open.zsh" > /dev/null
Expand All @@ -31,10 +38,7 @@ describe() {

### Tests

current_branch=$(git branch --show-current)
current_ref=$(git rev-parse HEAD)
remote_url=$(git remote -v | grep "(push)" | awk '{print $2}')

echo "$(tput setaf 4)Running tests...$(tput sgr0)"

describe "git_open_project"
assert_value "https://github.com/chenasraf/git-open" $(git_open_project)
Expand Down Expand Up @@ -80,7 +84,7 @@ describe "git_open_pipelines"
assert_value "https://github.com/chenasraf/git-open/actions" $(git_open_pipelines)

describe "without args"
assert_value "Usage: git open [-s] <command>" "$(git_open | head -n 1)"
assert_value "$(cat $snapshot)" "$(git_open)"

### Teardown
echo ''
Expand Down
4 changes: 4 additions & 0 deletions tests/update_snapshot.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env zsh

snap="${0:A:h}/snapshot.txt"
. "${0:A:h}/../git-open.zsh" > $snap
File renamed without changes.

0 comments on commit 2947ceb

Please sign in to comment.