Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to remove leading shell prompt literal $ #996

Merged
merged 3 commits into from Nov 2, 2019

Conversation

boonwj
Copy link
Contributor

@boonwj boonwj commented Oct 28, 2019

Rule added to remove leading shell prompt literals found in the command.

This usually happens when a command is copy pasted from documentations with code blocks that contain it.

$ $ echo hello world
bash: $: command not found...
$ fuck
echo hello world [enter/↑/↓/ctrl+c]
hello world

Rule added to handle cases where the $ symbol is used in the command,
this usually happens when the command is copy pasted from a
documentation that includes the shell prompt symbol in the code blocks.
Copy link
Collaborator

@scorphus scorphus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! Please, mind my comments.



@pytest.mark.parametrize(
"command",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about parametrizing only script (as string) and declare a Command instance with "$: command not found" as output?

Suggested change
"command",
"script",

That would make all test tables more readable.

@pytest.mark.parametrize(
"command",
[
Command("$ cd newdir", "$: command not found"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Command("$ cd newdir", "$: command not found"),
"$ cd newdir",

Command(" $ cd newdir", "$: command not found"),
],
)
def test_match(command):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_match(command):
def test_match(script):

],
)
def test_match(command):
assert match(command)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert match(command)
assert match(Command(script, "$: command not found"))

Comment on lines 17 to 33
@pytest.mark.parametrize(
"command",
[Command("$", ""), Command("$?", ""), Command(" $?", ""), Command("", "")],
)
def test_not_match(command):
assert not match(command)


@pytest.mark.parametrize(
"command, new_command",
[
(Command("$ cd newdir", ""), "cd newdir"),
(Command("$ python3 -m virtualenv env", ""), "python3 -m virtualenv env"),
],
)
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

return command.script.replace("$", "", 1).strip()


requires_output = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be omitted as requires_output's default value is True.

- Refactor test for cleaner test tables
- Removed unnecessary requires_output=True option
@boonwj
Copy link
Contributor Author

boonwj commented Oct 28, 2019

Thanks for the comments @scorphus!

I have made the modifications as suggested. However, the non matches were not changed as I realised that the outputs were not the same for every test case.

@nvbn
Copy link
Owner

nvbn commented Nov 2, 2019

Looks good, thanks!

@nvbn nvbn merged commit 793510a into nvbn:master Nov 2, 2019
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.

None yet

3 participants