Use Nix for testing

This commit is contained in:
Ajeet D'Souza 2020-11-11 18:23:37 +05:30
parent 58bcbef7aa
commit e6e67b16bc
6 changed files with 75 additions and 45 deletions

View File

@ -5,29 +5,21 @@ on:
pull_request: pull_request:
jobs: jobs:
test-linux: test-unix:
runs-on: ubuntu-18.04 runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps: steps:
- run: sudo apt update
- run: sudo apt install wget apt-transport-https
- run: wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
- run: sudo dpkg -i packages-microsoft-prod.deb
- run: sudo apt update
- run: sudo add-apt-repository universe
- run: sudo apt install bash dash fish powershell python3 python3-pip shellcheck xonsh zsh
- run: sudo snap install shfmt
- run: sudo pip3 install --upgrade pip setuptools
- run: sudo pip3 install --upgrade black mypy pylint
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - uses: cachix/install-nix-action@v12
with: with:
profile: minimal nix_path: nixpkgs=channel:nixos-unstable
toolchain: stable # - uses: cachix/cachix-action@v8
override: true # with:
- uses: actions-rs/cargo@v1 # name: zoxide
with: # authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
command: test - run: nix-shell --run "cargo test --no-fail-fast"
args: --all-features --no-fail-fast
test-windows: test-windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:

34
shell.nix Normal file
View File

@ -0,0 +1,34 @@
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz") {} }:
let
my-python3-pkgs = python3-pkgs: with python3-pkgs; [
black
mypy
pylint
];
my-python3 = pkgs.python3.withPackages my-python3-pkgs;
in
pkgs.mkShell {
name = "env";
nativeBuildInputs = [
pkgs.rustc
pkgs.cargo
];
buildInputs = [
pkgs.bash
pkgs.dash
pkgs.fish
pkgs.fzf
pkgs.git
pkgs.powershell
pkgs.shellcheck
pkgs.shfmt
pkgs.xonsh
pkgs.zsh
my-python3
];
# Set Environment Variables
RUST_BACKTRACE = 1;
}

View File

@ -73,11 +73,10 @@ enum Shell {
fn env_help() -> &'static str { fn env_help() -> &'static str {
static ENV_HELP: OnceCell<String> = OnceCell::new(); static ENV_HELP: OnceCell<String> = OnceCell::new();
ENV_HELP.get_or_init(|| { ENV_HELP.get_or_init(|| {
const PATH_SPLIT_SEPARATOR: u8 = if cfg!(any(target_os = "redox", target_os = "windows")) { #[cfg(unix)]
b';' const PATH_SPLIT_SEPARATOR: u8 = b':';
} else { #[cfg(any(target_os = "redox", target_os = "windows"))]
b':' const PATH_SPLIT_SEPARATOR: u8 = b'\\';
};
format!( format!(
"\ "\

View File

@ -9,7 +9,10 @@ pub struct Opts<'a> {
} }
impl Opts<'_> { impl Opts<'_> {
pub const DEVNULL: &'static str = if cfg!(windows) { "NUL" } else { "/dev/null" }; #[cfg(unix)]
pub const DEVNULL: &'static str = "/dev/null";
#[cfg(windows)]
pub const DEVNULL: &'static str = "NUL";
} }
macro_rules! make_template { macro_rules! make_template {
@ -113,7 +116,7 @@ mod tests {
let opts = dbg!(&opts()[i]); let opts = dbg!(&opts()[i]);
let source = Bash(opts).render().unwrap(); let source = Bash(opts).render().unwrap();
Command::new("shellcheck") Command::new("shellcheck")
.args(&["--shell", "bash", "-"]) .args(&["--enable", "all", "--shell", "bash", "-"])
.write_stdin(source) .write_stdin(source)
.assert() .assert()
.success() .success()
@ -186,7 +189,7 @@ mod tests {
let opts = dbg!(&opts()[i]); let opts = dbg!(&opts()[i]);
let source = Posix(opts).render().unwrap(); let source = Posix(opts).render().unwrap();
Command::new("shellcheck") Command::new("shellcheck")
.args(&["--shell", "sh", "-"]) .args(&["--enable", "all", "--shell", "sh", "-"])
.write_stdin(source) .write_stdin(source)
.assert() .assert()
.success() .success()

View File

@ -37,11 +37,11 @@ function __zoxide_hook() {
{%- when Hook::Pwd %} {%- when Hook::Pwd %}
function __zoxide_hook() { function __zoxide_hook() {
local -r __zoxide_pwd_tmp="$(__zoxide_pwd)" local -r __zoxide_pwd_tmp="$(__zoxide_pwd)"
if [ -z "$__zoxide_pwd_old" ]; then if [ -z "${__zoxide_pwd_old}" ]; then
__zoxide_pwd_old="$__zoxide_pwd_tmp" __zoxide_pwd_old="${__zoxide_pwd_tmp}"
elif [ "$__zoxide_pwd_old" != "$__zoxide_pwd_tmp" ]; then elif [ "${__zoxide_pwd_old}" != "${__zoxide_pwd_tmp}" ]; then
__zoxide_pwd_old="$__zoxide_pwd_tmp" __zoxide_pwd_old="${__zoxide_pwd_tmp}"
zoxide add "$__zoxide_pwd_old" zoxide add "${__zoxide_pwd_old}"
fi fi
} }
{%- endmatch %} {%- endmatch %}
@ -51,7 +51,7 @@ function __zoxide_hook() {
{{ NOT_CONFIGURED }} {{ NOT_CONFIGURED }}
{%- else %} {%- else %}
case "$PROMPT_COMMAND" in case "${PROMPT_COMMAND}" in
*__zoxide_hook*) ;; *__zoxide_hook*) ;;
*) PROMPT_COMMAND="${PROMPT_COMMAND:+${PROMPT_COMMAND};}__zoxide_hook" ;; *) PROMPT_COMMAND="${PROMPT_COMMAND:+${PROMPT_COMMAND};}__zoxide_hook" ;;
esac esac
@ -68,24 +68,25 @@ function __zoxide_z() {
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
__zoxide_cd ~ __zoxide_cd ~
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
if [ -n "$OLDPWD" ]; then if [ -n "${OLDPWD}" ]; then
__zoxide_cd "$OLDPWD" __zoxide_cd "${OLDPWD}"
else else
echo "zoxide: \\$OLDPWD is not set" # shellcheck disable=SC2016
echo 'zoxide: $OLDPWD is not set'
return 1 return 1
fi fi
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
__zoxide_cd "$1" __zoxide_cd "$1"
else else
local __zoxide_result local __zoxide_result
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result" __zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}"
fi fi
} }
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
function __zoxide_zi() { function __zoxide_zi() {
local __zoxide_result local __zoxide_result
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "$__zoxide_result" __zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
} }
# Add a new entry to the database. # Add a new entry to the database.

View File

@ -52,7 +52,7 @@ __zoxide_hook() {
{{ NOT_CONFIGURED }} {{ NOT_CONFIGURED }}
{%- when Hook::Prompt %} {%- when Hook::Prompt %}
case "$PS1" in case "${PS1}" in
*\$\(__zoxide_hook\)*) ;; *\$\(__zoxide_hook\)*) ;;
*) PS1="${PS1}\$(__zoxide_hook)" ;; *) PS1="${PS1}\$(__zoxide_hook)" ;;
esac esac
@ -72,22 +72,23 @@ __zoxide_z() {
if [ "$#" -eq 0 ]; then if [ "$#" -eq 0 ]; then
__zoxide_cd ~ __zoxide_cd ~
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
if [ -n "$OLDPWD" ]; then if [ -n "${OLDPWD}" ]; then
__zoxide_cd "$OLDPWD" __zoxide_cd "${OLDPWD}"
else else
echo "zoxide: \\$OLDPWD is not set" # shellcheck disable=SC2016
echo 'zoxide: $OLDPWD is not set'
return 1 return 1
fi fi
elif [ "$#" -eq 1 ] && [ -d "$1" ]; then elif [ "$#" -eq 1 ] && [ -d "$1" ]; then
__zoxide_cd "$1" __zoxide_cd "$1"
else else
__zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "$__zoxide_result" __zoxide_result="$(zoxide query -- "$@")" && __zoxide_cd "${__zoxide_result}"
fi fi
} }
# Jump to a directory using interactive search. # Jump to a directory using interactive search.
__zoxide_zi() { __zoxide_zi() {
__zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "$__zoxide_result" __zoxide_result="$(zoxide query -i -- "$@")" && __zoxide_cd "${__zoxide_result}"
} }
# Add a new entry to the database. # Add a new entry to the database.