Skip to content

Add test for fix of issue #7754#7756

Merged
sholderbach merged 7 commits intonushell:mainfrom
Xoffio:issue_7754
Jan 19, 2023
Merged

Add test for fix of issue #7754#7756
sholderbach merged 7 commits intonushell:mainfrom
Xoffio:issue_7754

Conversation

@Xoffio
Copy link
Contributor

@Xoffio Xoffio commented Jan 15, 2023

Description

Fixes issue #7754 which used to crash on when name of the alias was shorter than the command and if the command contains any pipes. check bellow for an example:

before

add the next to your $nu.config-path

 alias ll = ls -l

Now press tab right after the c

# This will crash
> ll -a | c
[process exited with code 101 (0x00000065)]

After

With the patch on this PR the shell no longer crashes on that situation.

User-Facing Changes

None

Tests + Formatting

Checking how to add test to this particular case.... Is it actually possible?

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

@fdncred
Copy link
Contributor

fdncred commented Jan 15, 2023

please add more info in the description. "This PR fixes issue #7754 which blah blah blah. Here are how it works before: and after:"

@Xoffio
Copy link
Contributor Author

Xoffio commented Jan 15, 2023

@fdncred sorry about that I though the information in the issue was enough. I updated it :)

@fdncred
Copy link
Contributor

fdncred commented Jan 15, 2023

No worries. It's better for us to have a proper title and description on each PR in case we have to revert one. Thanks.

@Xoffio Xoffio changed the title Fixes Issue 7754 Fixes shell crashing because alias name is shorter than alias command and there are pipes present. (Fixes Issue 7754) Jan 15, 2023
@sholderbach
Copy link
Member

Would you mind adding a test that reproduces the previous panic?

@Xoffio
Copy link
Contributor Author

Xoffio commented Jan 16, 2023

Would you mind adding a test that reproduces the previous panic?

I tried to do that but the code actually does the suggestion instead of crashing.... I tested in the main branch with this:

// crates\nu-cli\tests\completions.rs
#[rstest]
fn alias_offset_bug_7754() {
    let (dir, _, mut engine, mut stack) = new_engine();

    // Create an alias
    let alias = r#"alias ll = ls -l"#;
    assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack, dir.clone()).is_ok());

    let mut completer = NuCompleter::new(std::sync::Arc::new(engine), stack);
    let suggestions = completer.complete("ll -a | c", 9);

    println!(" --------- suggestions: {:?}", suggestions);
}

and instead of crashing it actually gets the suggestions... Am I doing something wrong?

@Xoffio
Copy link
Contributor Author

Xoffio commented Jan 16, 2023

@sholderbach never mind. It does crash on the main branch. Test added!

@sholderbach
Copy link
Member

Great! Is the corresponding fix already landed through #7779?

@Xoffio
Copy link
Contributor Author

Xoffio commented Jan 18, 2023

@sholderbach We still need to merge this PR. The bug is similar to the one fixed on #7779 (issue related to the offset) but this code patches different areas

@sholderbach
Copy link
Member

OK maybe something went wrong in the merge process because Github only shows the added tests in the final diff.

@Xoffio
Copy link
Contributor Author

Xoffio commented Jan 18, 2023

@sholderbach Actually you are right. Yes! sorry for the confusion. I was working on one bug and then someone else pointed out another one and I branched out from that one. So, yes, the fix was already landed through #7779 but it is missing the test that it is still here

@sholderbach sholderbach changed the title Fixes shell crashing because alias name is shorter than alias command and there are pipes present. (Fixes Issue 7754) Add test for fix of issue #7754 Jan 19, 2023
@sholderbach sholderbach merged commit 6a43e1a into nushell:main Jan 19, 2023
@sholderbach
Copy link
Member

Great! Thanks for the test as well.

Xoffio added a commit to Xoffio/nushell that referenced this pull request Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants