Skip to content

Commit

Permalink
Use nushell 0.77.1 --> 0.84.0
Browse files Browse the repository at this point in the history
  • Loading branch information
domsleee committed Sep 4, 2023
1 parent 3472fe9 commit d89f49b
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 689 deletions.
977 changes: 372 additions & 605 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ readme = "README.md"
clap = { version = "4.1.8", features = ["derive"] }
itertools = "0.10.5"
log = "0.4.17"
nu-cli = "0.77.1"
nu-command = "0.77.1"
nu-parser = "0.77.1"
nu-protocol = "0.77.1"
reedline = "0.17.0"
nu-engine = "0.77.1"
nu-cli = "0.84.0"
nu-command = "0.84.0"
nu-cmd-lang = "0.84.0"
nu-parser = "0.84.0"
nu-protocol = "0.84.0"
reedline = "0.23.0"
nu-engine = "0.84.0"
regex = "1.7.1"
env_logger = "0.10.0"

Expand Down
6 changes: 5 additions & 1 deletion resource/completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def "nu-complete git remotes" [] {
^git remote | lines | each { |line| $line | str trim }
}

def "nu-complete git remote or branch" [] {
(nu-complete git remotes) ++ (nu-complete git branches)
}

def "nu-complete git log" [] {
^git log --pretty=%h | lines | each { |line| $line | str trim }
}
Expand Down Expand Up @@ -249,7 +253,7 @@ extern "git merge" [

# Forward-port local commits to the updated upstream head
extern "git rebase" [
remote?: string@"nu-complete git remotes", # the name of the remote
remoteOrBranch?: string@"nu-complete git remote or branch", # the name of the remote / branch
...refs: string@"nu-complete git branches" # the branch / refspec
--continue # Restart the rebasing process
--abort # Abort the rebase operation
Expand Down
12 changes: 8 additions & 4 deletions src/nu_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
use nu_cli::NuCompleter;
use nu_engine::eval_block;
use nu_parser::parse;
use nu_protocol::report_error;
use nu_protocol::{
engine::{EngineState, Stack, StateWorkingSet},
PipelineData, ShellError, Span, Value,
Expand All @@ -26,8 +27,11 @@ fn merge_input(
) -> Result<(), ShellError> {
let (block, delta) = {
let mut working_set = StateWorkingSet::new(engine_state);
let (block, err) = parse(&mut working_set, None, input, false, &[]);
assert!(err.is_none(), "unexpected error: {err:?}");
let block = parse(&mut working_set, None, input, false);
if let Some(err) = working_set.parse_errors.first() {
report_error(&working_set, err);
std::process::exit(1);
}
(block, working_set.render())
};

Expand All @@ -53,8 +57,8 @@ fn merge_input(

fn new_engine(pwd: &Path) -> (PathBuf, String, EngineState, Stack) {
let dir_str: String = pwd.display().to_string();
let mut engine_state = nu_command::create_default_context();

let mut engine_state =
nu_command::add_shell_command_context(nu_cmd_lang::create_default_context());
let mut stack = Stack::new();
stack.add_env_var(
"PWD".to_string(),
Expand Down
6 changes: 1 addition & 5 deletions tests/test_command_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ use speculoos::prelude::ContainingIntoIterAssertions;

#[apply(shell_to_use)]
fn test_command_names(shell: &str) {
let testenv = TestEnv::new(shell);
let res = testenv
.run_with_profile("Get-CommandNamesUsingRegex")
.unwrap();
let lines = res.stdout.lines().map(|x| x.unwrap()).collect_vec();
let lines = util::run_command(shell, "Get-CommandNamesUsingRegex");
println!("{lines:?}");
assert_that!(lines).contains("git".to_string());
}
Expand Down
68 changes: 0 additions & 68 deletions tests/test_complete.rs

This file was deleted.

26 changes: 26 additions & 0 deletions tests/test_complete_aliases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use rstest::rstest;
use rstest_reuse::{self, *};
use speculoos::assert_that;

extern crate speculoos;
use crate::speculoos::prelude::ContainingIntoIterAssertions;

mod testenv;
pub use testenv::*;

#[apply(shell_to_use)]
fn test_checkout_branches_alias(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'myLongGitCheckoutAlias '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_checkout_completions_registered(shell: &str) {
let lines = util::run_command(
shell,
"Get-ArgumentCompleter -Native | ForEach-Object { \"$($_.CommandName)\" }",
);
assert_that!(lines).contains("myLongGitCheckoutAlias".to_string());
assert_that!(lines).contains("git".to_string());
}
70 changes: 70 additions & 0 deletions tests/test_complete_git.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::io::BufRead;

use itertools::Itertools;
use rstest::rstest;
use rstest_reuse::{self, *};
use speculoos::assert_that;

extern crate speculoos;
use crate::speculoos::prelude::ContainingIntoIterAssertions;

mod testenv;
pub use testenv::*;

#[apply(shell_to_use)]
fn test_checkout_branches(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git checkout '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_checkout_branches2(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git checkout testbranch2'");
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_merge(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git merge '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_fetch_first_arg(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git fetch '");
assert_that!(lines).contains("origin".to_string());
}

#[apply(shell_to_use)]
fn test_fetch_second_arg(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git fetch origin '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_rebase_first_arg(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git rebase '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
assert_that!(lines).contains("origin".to_string());
}

#[apply(shell_to_use)]
fn test_rebase_second_arg(shell: &str) {
let lines = util::run_command(shell, "Invoke-TabComplete 'git rebase origin '");
assert_that!(lines).contains("testbranch".to_string());
assert_that!(lines).contains("testbranch23".to_string());
}

#[apply(shell_to_use)]
fn test_complete_nongit_command(shell: &str) {
let testenv = TestEnv::new_with_other_nu(shell);
let res = testenv
.run_with_profile("Invoke-TabComplete 'burrito -'")
.unwrap();
let lines = res.stdout.lines().map(|x| x.unwrap()).collect_vec();
assert_that!(lines).contains("--hello-there".to_string());
}
2 changes: 2 additions & 0 deletions tests/testenv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
process::{Command, Output},
};
use tempfile::TempDir;
pub mod util;

const PATH: &str = "PATH";

Expand Down Expand Up @@ -142,6 +143,7 @@ fn create_working_dir(profile_prefix_data: Vec<&str>) -> Result<(TempDir, PathBu
run_git(&["config", "user.name", "yourname"]);
run_git(&["commit", "-m", "test"]);
run_git(&["checkout", "-b", "testbranch23"]);
run_git(&["remote", "add", "origin", "[email protected]"]);

profile_path
};
Expand Down
9 changes: 9 additions & 0 deletions tests/testenv/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::io::BufRead;

use crate::TestEnv;

pub fn run_command(shell: &str, command: &str) -> Vec<String> {
let testenv = TestEnv::new(shell);
let res = testenv.run_with_profile(command).unwrap();
res.stdout.lines().map(|x| x.unwrap()).collect()
}

0 comments on commit d89f49b

Please sign in to comment.