Skip to content

Commit

Permalink
feat: configure, make, cmake, and build ices
Browse files Browse the repository at this point in the history
- 'configure' and 'make' ices refactored
- Delete command now handles programs using 'make' and 'cmake' ices
- Setting `ZINIT[DEBUG]` enables debug logging (i.e., `+zi-log "{dbg}
- New 'build' ice sets 'configure' and 'make ices if no flags are needed.
- New 'cmake' ice will build/install using 'cmake'
- Zunit tests added

Signed-off-by: Vladislav Doster <[email protected]>
  • Loading branch information
vladdoster committed Dec 24, 2023
1 parent 358ef03 commit cd08e34
Show file tree
Hide file tree
Showing 10 changed files with 481 additions and 381 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit tests
name: Unit Tests

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macos-latest", "ubuntu-latest"]
os: ["macos-latest","ubuntu-latest"]
fail-fast: false

steps:
Expand All @@ -39,15 +39,30 @@ jobs:
id: setup-homebrew
uses: Homebrew/actions/setup-homebrew@master

# - name: "install musl"
# if: runner.os == 'Linux'
# run: sudo apt-get install build-essential curl file gcc gcc-multilib glibc-source libc6 libc6-dev unzip xz-utils zsh
- name: "install musl"
if: runner.os == 'Linux'
run: |
sudo apt-get update --yes
sudo apt-get install --yes \
autoconf automake autotools-dev \
build-essential byacc\
cmake curl \
file \
gcc gettext glibc-source grep \
libc6 libc6-dev libevent-dev libncurses5-dev libncursesw5-dev libtool libuvc0 lua5.1 \
m4 \
ninja-build \
pkg-config \
unzip \
xz-utils \
zsh
- name: "install dependencies"
id: install-deps
run: |
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew install --force --overwrite gnu-sed coreutils unzip xz zsh
brew install --force --overwrite autoconf automake binutils byacc cmake coreutils curl gettext gnu-sed libevent libtool libuv lua [email protected] make ninja ncurses pkg-config texinfo unzip xz zsh
brew link --force --overwrite ncurses
- name: "install zunit"
id: install-zunit
Expand All @@ -56,23 +71,20 @@ jobs:
git clone --depth 1 https://github.com/zdharma-continuum/zunit; cd ./zunit
zsh -c -l './build.zsh' && sudo chmod u+x ./zunit && cp ./zunit "$HOME/.local/bin/"
# - name: disable secssessment system policy security
# run: sudo spctl --master-disable

- name: "annexes"
run: zunit run tests/annexes.zunit

- name: "commands"
run: zunit run tests/commands.zunit

- name: "plugins"
run: zunit run tests/plugins.zunit

- name: "gh-r"
run: zunit run --fail-fast --verbose tests/gh-r.zunit
run: zunit run tests/gh-r.zunit

- name: "annexes"
run: zunit run tests/annexes.zunit

- name: "ices"
run: zunit run tests/ices.zunit

- name: "plugins"
run: zunit run tests/plugins.zunit

- name: "snippets"
run: zunit run tests/snippets.zunit
5 changes: 5 additions & 0 deletions tests/_support/annex_test_assertions
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ is_annex() {
assert ${PWD}/${${annex}//zinit-annex/z-a}.plugin.zsh is_file
assert ${PWD}/${${annex}//zinit-annex/z-a}.plugin.zsh is_readable
}

load_bin_gem_node(){
run zinit load @zdharma-continuum/zinit-annex-bin-gem-node
zinit default-ice --quiet from'gh-r'
}
66 changes: 38 additions & 28 deletions tests/_support/bootstrap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env zsh
setopt NO_GLOBAL_RCS NO_GLOBAL_EXPORT NO_RCS
emulate zsh
setopt no_global_rcs no_rcs no_aliases extended_glob

# Log functions [[[
function error(){ print -P "%F{red}[ERROR]%f: ${1}" && return 1; }
Expand All @@ -19,24 +19,29 @@ if [[ ! -d ${TMP_ZUNIT} ]]; then
exit 1
fi

typeset -gAH ZINIT;
ZINIT[HOME_DIR]=${TMP_ZUNIT};
ZINIT[BIN_DIR]=$ZINIT[HOME_DIR]/zinit.git;
ZINIT[COMPLETIONS_DIR]=$ZINIT[HOME_DIR]/completions;
ZINIT[PLUGINS_DIR]=$ZINIT[HOME_DIR]/plugins;
ZINIT[SNIPPETS_DIR]=$ZINIT[HOME_DIR]/snippets;
ZINIT[ZCOMPDUMP_PATH]=$ZINIT[HOME_DIR]/zcompdump;
ZPFX=$ZINIT[HOME_DIR]/polaris;
typeset -gx zi_test_dir="${TMP_ZUNIT}"
typeset -gxAUH ZINIT
# DEBUG 'true'
ZINIT+=(
BIN_DIR ${zi_test_dir}/zinit.git
COMPLETIONS_DIR ${zi_test_dir}/completions SNIPPETS_DIR ${zi_test_dir}/snippets
HOME_DIR ${zi_test_dir} PLUGINS_DIR ${zi_test_dir}/plugins
ZCOMPDUMP_PATH ${zi_test_dir}/zcompdump ZPFX ${zi_test_dir}/polaris
POLARIS ${zi_test_dir}/polaris
)
typeset -gxH ZPFX=
ZPFX="$zi_test_dir"/polaris

command git diff > ${ZINIT[HOME_DIR]}/unstaged.diff
info 'creating test env'
# info 'creating test env'
git clone \
--quiet \
--depth=1 \
--dissociate \
--no-hardlinks \
--reference "${GIT_REPO}" \
file://${GIT_REPO:A} \
"${ZINIT[BIN_DIR]}"
"${ZINIT[BIN_DIR]}" >/dev/null
if (( $? != 0 )); then
error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2
exit 1
Expand All @@ -46,23 +51,28 @@ if [[ -s $ZINIT[HOME_DIR]/unstaged.diff ]]; then
(
git -C $ZINIT[BIN_DIR] apply $ZINIT[HOME_DIR]/unstaged.diff && \
chmod g-rwX "${ZINIT[HOME_DIR]}" && \
zcompile "${ZINIT[BIN_DIR]}/zinit.zsh"
)
zcompile "${ZINIT[BIN_DIR]}/zinit.zsh" >/dev/null
) >/dev/null
fi
(( $? != 0 )) && { error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2; exit 1 }

source $ZINIT[BIN_DIR]/zinit.zsh
(( $? != 0 )) && { error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2; exit 1 }
# ]]]
# Install Annexes [[[
info 'installing test dependencies'
for annex (binary-symlink default-ice); do
if [[ ! -d ${GIT_REPO}/tests/_support/$annex ]]; then;
git clone https://github.com/zdharma-continuum/zinit-annex-$annex ${GIT_REPO:A}/tests/_support/$annex
fi
zinit light ${GIT_REPO:A}/tests/_support/$annex
info "loaded $annex dependencies"
done
# ]]]
hash -f
builtin hash -d zinit=$zi_test_dir
builtin hash -d zpfx=$zi_test_dir/polaris
builtin hash -d plugins=$zi_test_dir/plugins
source $zi_test_dir/zinit.git/zinit.zsh
(( $? != 0 )) && { error "Unable to source zinit" >&2; exit 1 }
hash -f
builtin hash -d zinit=$zi_test_dir
builtin hash -d zpfx=$zi_test_dir/polaris
builtin hash -d plugins=$zi_test_dir/plugins
{
zinit for \
@zdharma-continuum/zinit-annex-bin-gem-node \
@zdharma-continuum/zinit-annex-binary-symlink \
@zdharma-continuum/zinit-annex-default-ice \
@zdharma-continuum/zinit-annex-linkman
}>/dev/null

# vim:ft=zsh:sw=2:sts=2:et:foldmarker=[[[,]]]:foldmethod=marker
+zi-log "{m} loaded $annex dependencies"
zinit zstatus
14 changes: 11 additions & 3 deletions tests/commands.zunit
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@
done
run zinit -help
assert $output contains 'Unknown subcommand'
assert $state equals 1
assert $state equals 1
}
@test 'self-update' {
run zinit self-update
assert $output contains 'Already up-to-date.'
assert $state equals 0
}

# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker
@test 'set-debug' {
ZINIT+=(DEBUG 'true')
run +zi-log -n '{dbg} message'
assert $output contains '[debug]'; assert $state equals 0
}
@test 'unset-dbg' {
run +zi-log -n '{dbg} message'; assert $output contains ''
run +zi-log -n '{m} message'
assert $output contains 'message'; assert $state equals 0
}
72 changes: 53 additions & 19 deletions tests/gh-r.zunit
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env zunit


@setup {
HOME="$ZPFX" # Stops programs creating directories in user home
export ZBIN="${ZPFX}/bin"
export os_type="${OSTYPE//[0-9\.]*/}"
zinit default-ice --quiet from'gh-r' lbin
load "${PWD}/tests/_support/annex_test_assertions"
HOME="$zi_test_dir" # Stops programs creating directories in user home
typeset -gx ZBIN="$zi_test_dir/polaris/bin" os_type="${OSTYPE//[0-9\.]*/}"
[[ ! -d $ZBIN ]] && mkdir -p "$ZBIN"
zinit default-ice --quiet from'gh-r' lbin'!' null
}

# @test 'atmos' { Universal Tool for DevOps and Cloud Automation (works with terraform, helm, helmfile, etc)
Expand Down Expand Up @@ -36,7 +36,7 @@
@test 'act' { # Run your GitHub Actions locally
run zinit for @nektos/act; assert $state equals 0
local act="$ZBIN/act"; assert "$act" is_executable
$act --version; assert $state equals 0
run "$act" --version; assert $state equals 0
}
@test 'akamai' { # Manage and configure Akamai from the Command Line.
run zinit id-as'akamai' lbin'akamai*->akamai' for @akamai/cli; assert $state equals 0
Expand Down Expand Up @@ -78,7 +78,7 @@
[[ $OSTYPE =~ 'darwin*' ]] && skip "on $os_type"
run zinit for @imsnif/bandwhich; assert $state equals 0
local bandwhich="$ZBIN/bandwhich"; assert "$bandwhich" is_executable
run $bandwhich --help; assert $state equals 0
run "$bandwhich" --version; assert $state equals 0
}
@test 'bat' { # A cat(1) clone with wings
run zinit for @sharkdp/bat; assert $state equals 0
Expand Down Expand Up @@ -473,12 +473,12 @@
local just="$ZBIN/just"; assert "$just" is_executable
run $just --version; assert $state equals 0
}
@test 'keepassxc' { # a cross-platform community-driven port of the Windows application Keepass Password Safe
[[ $OSTYPE =~ 'linux*' ]] && skip "skipped on $os_type"
run zinit for lbin'!*-cli -> keepassxc-cli' @keepassxreboot/keepassxc; assert $state equals 0
local keepassxc="$ZBIN/keepassxc-cli"; assert "$keepassxc" is_executable
run $keepassxc --version; assert $state equals 0
}
# @test 'keepassxc' { # a cross-platform community-driven port of the Windows application Keepass Password Safe
# [[ $OSTYPE =~ 'linux*' ]] && skip "skipped on $os_type"
# run zinit for lbin'!*-cli -> keepassxc-cli' @keepassxreboot/keepassxc; assert $state equals 0
# local keepassxc="$ZBIN/keepassxc-cli"; assert "$keepassxc" is_executable
# run $keepassxc --version; assert $state equals 0
# }
@test 'ko' { # Build and deploy Go applications on Kubernetes
run zinit for @ko-build/ko; assert $state equals 0
local ko="$ZBIN/ko"; assert "$ko" is_executable
Expand All @@ -499,6 +499,16 @@
local cli="$ZBIN/kubedb"; assert "$cli" is_executable
run "$cli" version; assert $state equals 0
}
@test 'kubectl-plugins' { # Faster way to switch between clusters and namespaces in kubectl
[[ $OSTYPE =~ 'darwin*' ]] && skip "skipped on $os_type"
load_bin_gem_node
run zinit for bpick'kubectx;kubens' sbin'kubectx;kubens' @ahmetb/kubectx
local bin prog
for bin in 'kubectx' 'kubens'; do
prog="$ZBIN/${bin}"; assert "$prog" is_executable;
run "$prog" --help; assert $state equals 0
done
}
@test 'lazygit' { # simple terminal UI for git commands
run zinit for @jesseduffield/lazygit; assert $state equals 0
local lazygit="$ZBIN/lazygit"; assert "$lazygit" is_executable
Expand Down Expand Up @@ -548,14 +558,38 @@
run $mas version; assert $state equals 0
}
@test 'mcfly' { # Fly through your shell history. Great Scott
run zinit for @cantino/mcfly; assert $state equals 0
run zinit ver'v0.8.3' for @cantino/mcfly; assert $state equals 0
local mcfly="$ZBIN/mcfly"; assert "$mcfly" is_executable
run $mcfly --version; assert $state equals 0
run "$mcfly" --version; assert $state equals 0
}
@test 'mdbook-lbin' { # Create book from markdown files. Like Gitbook but implemented in Rust
local mdbook="$ZBIN/mdbook";
run zinit for @rust-lang/mdBook; assert $state equals 0 assert "$mdbook" is_executable

run "$mdbook" --version; assert $state equals 0

run command file "$(command realpath ${mdbook})"; assert $output contains 'executable'

run zinit delete --yes rust-lang/mdBook; assert $state equals 0

run "$mdbook" --version;
assert $state equals 127; assert $output contains 'no such file or directory'
}
@test 'mdbook' { # Create book from markdown files. Like Gitbook but implemented in Rust
run zinit for @rust-lang/mdBook; assert $state equals 0
local mdbook="$ZBIN/mdbook"; assert "$mdbook" is_executable
run $mdbook --version; assert $state equals 0
@test 'mdbook-sbin' { # Create book from markdown files. Like Gitbook but implemented in Rust
load_bin_gem_node
local mdbook="$ZBIN/mdbook";

run zinit from'gh-r' sbin"mdbook" for @rust-lang/mdBook; assert $state equals 0 assert "$mdbook" is_executable

run "$mdbook" --version; assert $state equals 0

run command file "$(command realpath ${mdbook})";
assert $output contains 'zsh script'; assert $output contains 'ASCII text'

run zinit delete --yes rust-lang/mdBook; assert $state equals 0

run "$mdbook" --version;
assert $state equals 127; assert $output contains 'no such file or directory'
}
@test 'mdcat' { # cat for markdown
run zinit for @swsnr/mdcat; assert $state equals 0
Expand Down
2 changes: 1 addition & 1 deletion tests/ices.zunit
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
assert "$ZPLUGINS/test---atclone/readme.md" not_exists
}
@test 'make' {
run zinit as"null" id-as"test/make" atclone"printf 'all:\n\ttouch whatever\n' > Makefile" make"" for zdharma-continuum/null
run zinit as"null" id-as"test/make" atclone"printf 'all:\n\ttouch whatever\n' > Makefile" make"all" for zdharma-continuum/null
assert $state equals 0
assert "$ZPLUGINS/test---make/whatever" is_file
}
Expand Down
Loading

0 comments on commit cd08e34

Please sign in to comment.