From 58313c67e7e587d7932164d4f95fbfe9bcc0b686 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Sat, 18 Sep 2021 01:29:46 +0530 Subject: [PATCH] Add cargo xtask test --- CHANGELOG.md | 18 ++++++++++-------- README.md | 8 +++++++- shell.nix | 20 +++++++++++--------- templates/powershell.txt | 16 +++++++--------- xtask/src/main.rs | 22 +++++++++++++++------- 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bf70e0f..9fdb9607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ - + # Changelog @@ -112,13 +112,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed -- Aliases: `za`, `zq`, `zqi`, `zr`, `zri`. These are trivial aliases to zoxide that can easily be defined manually, and aren't very useful to most users. +- Aliases: `za`, `zq`, `zqi`, `zr`, `zri`. These are trivial aliases that can + easily be defined manually, and aren't very useful to most users. ## [0.5.0] - 2020-10-30 ### Added -- Inaccessible directories are no longer removed; zoxide can now remember paths on removable devices. - `$_ZO_EXCLUDE_DIRS` now supports globs. - `zoxide init` now defines `__zoxide_z*` functions that can be aliased as needed. - Support for the [xonsh](https://xon.sh/) shell. @@ -135,6 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Deprecated PWD hooks for POSIX shells. +- Lazy deletion for inaccessible directories. ## [0.4.3] - 2020-07-04 @@ -153,7 +154,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Increased default value of `$_ZO_MAXAGE` to `10000`. -- Symlinks are treated as separate directories by default, this can be changed by setting `_ZO_RESOLVE_SYMLINKS=1`. +- Symlinks are treated as separate directories by default, this can be changed + by setting `_ZO_RESOLVE_SYMLINKS=1`. ### Removed @@ -182,7 +184,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `zoxide remove` now throws an error if there was no match in the database. -- Interactive mode in `zoxide` no longer throws an error if `fzf` exits gracefully. +- Interactive mode in `zoxide` no longer errors out if `fzf` exits gracefully. - Canonicalize to regular paths instead of UNC paths on Windows. - `zoxide init` now uses PWD hooks by default for better performance. - `$_ZO_ECHO` now only works when set to `1`. @@ -203,7 +205,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Query output no longer has the `query:` prefix, so `$(zq)` can now be used as an argument to commands. +- `zoxide query` output no longer has the `query:` prefix. ### Fixed @@ -214,7 +216,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Automatic migration from `v0.2.x` databases. -- `$_ZO_EXCLUDE_DIRS` to prevent certain directories from being added to the database. +- `$_ZO_EXCLUDE_DIRS` to prevent directories from being added to the database. - Support for POSIX-compliant shells. ### Changed @@ -225,7 +227,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Achieve thread safety using unique temporary database file names for each `zoxide` instance. +- Thread safety using unique tempfile names for each `zoxide` instance. - Incomprehensive "could not allocate" message on database corruption. ## [0.2.2] - 2020-03-20 diff --git a/README.md b/README.md index 4fb0576e..32c42ba4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ - + # `zoxide` diff --git a/shell.nix b/shell.nix index 25820ec1..ab69b77b 100644 --- a/shell.nix +++ b/shell.nix @@ -2,7 +2,6 @@ let rust = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/ad311f5bb5c5ef475985f1e0f264e831470a8510.tar.gz"); pkgs = import { overlays = [ rust ]; }; pkgs-latest = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/b4692e4197869c42c46d77e31af7e687e1892f55.tar.gz") {}; - pkgs-python = pkgs-latest.python3.withPackages (pkgs: [ pkgs.black pkgs.mypy pkgs.pylint ]); in pkgs.mkShell { buildInputs = [ @@ -10,26 +9,29 @@ pkgs.mkShell { pkgs.rust-bin.stable.latest.default # Shells - pkgs-latest.bash - pkgs-latest.dash pkgs-latest.elvish - pkgs-latest.nushell pkgs-latest.fish - pkgs-latest.powershell + pkgs-latest.nushell pkgs-latest.xonsh - pkgs-latest.zsh + pkgs.bash + pkgs.dash + pkgs.powershell + pkgs.zsh # Linters pkgs-latest.cargo-audit + pkgs-latest.nodePackages.markdownlint-cli + pkgs-latest.python3Packages.black + pkgs-latest.python3Packages.mypy + pkgs-latest.python3Packages.pylint pkgs-latest.shellcheck pkgs-latest.shfmt - pkgs-python # Dependencies pkgs.cacert pkgs.libiconv - pkgs-latest.fzf - pkgs-latest.git + pkgs.fzf + pkgs.git ]; RUST_BACKTRACE = 1; diff --git a/templates/powershell.txt b/templates/powershell.txt index a953eb24..e53d39a9 100644 --- a/templates/powershell.txt +++ b/templates/powershell.txt @@ -28,17 +28,13 @@ function __zoxide_cd($dir) { # Hook to add new entries to the database. function __zoxide_hook { $result = __zoxide_pwd - if ($result -ne $null) { + if ($null -ne $result) { zoxide add -- $result } } # Initialize hook. -{# Initialize $__zoxide_hooked if it does not exist. Removing this will cause - # an unset variable error in StrictMode. #} -$__zoxide_hooked = (Get-Variable __zoxide_hooked -ValueOnly -ErrorAction SilentlyContinue) -if ($__zoxide_hooked -ne 1) { - $__zoxide_hooked = 1 +if (-Not (Get-Command '__zoxide_hook' -ErrorAction SilentlyContinue)) { {%- match hook %} {%- when InitHook::None %} {{ not_configured }} @@ -53,7 +49,8 @@ if ($__zoxide_hooked -ne 1) { $ExecutionContext.InvokeCommand.LocationChangedAction = { $null = __zoxide_hook } - } else { + } + else { Write-Error ("`n" + "zoxide: PWD hooks are not supported below powershell 6.`n" + " Use 'zoxide init powershell --hook prompt' instead.") @@ -79,9 +76,10 @@ function __zoxide_z { } else { $result = __zoxide_pwd - if ($result -ne $null) { + if ($null -ne $result) { $result = zoxide query --exclude $result -- @args - } else { + } + else { $result = zoxide query -- @args } if ($LASTEXITCODE -eq 0) { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index fb3c18ad..bc150314 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,18 +1,19 @@ use std::process::Command; -use clap::{ArgEnum, Clap}; +use clap::Clap; #[derive(Clap, Debug)] struct App { - #[clap(arg_enum)] + #[clap(subcommand)] task: Task, #[clap(long)] nix: Option, } -#[derive(ArgEnum, Debug)] +#[derive(Clap, Debug)] enum Task { CI, + Test { keywords: Vec }, } fn run(args: &[&str], nix: bool) { @@ -32,17 +33,24 @@ fn run(args: &[&str], nix: bool) { fn main() { let app = App::parse(); - let color = if std::env::var_os("CI").is_some() { "--color=always" } else { "--color=auto" }; let nix = app.nix.unwrap_or_else(|| Command::new("nix-shell").arg("--version").output().is_ok()); let run = |args: &[&str]| run(args, nix); match app.task { Task::CI => { + let color = if std::env::var_os("CI").is_some() { "--color=always" } else { "" }; run(&["cargo", "fmt", "--", "--check", color, "--files-with-diff"]); run(&["cargo", "check", "--all-features", color]); - run(&["cargo", "clippy", "--all-features", color, "--", "--deny=warnings", "--deny=clippy::all"]); + run(&["cargo", "clippy", "--all-features", color, "--", "--deny=clippy::all", "--deny=warnings"]); run(&["cargo", "test", if nix { "--all-features" } else { "" }, color, "--no-fail-fast"]); - // color: https://github.com/rustsec/rustsec/pull/436 - run(&["cargo", "audit", "--deny=warnings"]); + run(&["cargo", "audit", color, "--deny=warnings"]); + if nix { + run(&["markdownlint", "--ignore-path=.gitignore", "."]); + } + } + Task::Test { keywords } => { + let mut args = vec!["cargo", "test", if nix { "--all-features" } else { "" }, "--no-fail-fast", "--"]; + args.extend(keywords.iter().map(String::as_str)); + run(&args); } } }