Skip to content

Add testexe.exe -echocmdline to output raw command line received by the process on Windows - #18591

Merged
Dongbo Wang (daxian-dbw) merged 5 commits into
PowerShell:masterfrom
daxian-dbw:echoarg
Dec 6, 2022
Merged

Dongbo Wang (daxian-dbw) merged 5 commits into
PowerShell:masterfrom
daxian-dbw:echoarg

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Nov 17, 2022 •

Copy link
Copy Markdown
Member

PR Summary

Add testexe.exe -echocmdline to output raw command line received by the process on Windows

It could be useful to print out the raw command line received by the testing process on Windows because it will show what is actually passed in by PowerShell when starting a native command.

image

image

PR Checklist

@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Update testexe.exe -echoargs to output raw command line received by the process on Windows Add testexe.exe -echoraw to output raw command line received by the process on Windows Nov 17, 2022
Comment thread test/tools/TestExe/TestExe.cs Resolved
Comment thread test/tools/TestExe/TestExe.cs Resolved

@SteveL-MSFT Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know you're adding this as part of researching some issues with $PSNativeCommandArgumentPassing, but would it makes sense to add some pester tets for native command arg passing using this test feature?

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 17, 2022
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 17, 2022
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Nov 17, 2022 •

Copy link
Copy Markdown
Member Author

but would it make sense to add some pester tets for native command arg passing using this test feature?

I updated the changes to make testexe -echocmdline to only write out the raw command line on Windows ("N/A" on Unix platforms), so it can be used in Pester tests now.

What pester tests you'd like to add using testexe -echocmdline? Do you want them to be added in this PR or a separate?

@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Add testexe.exe -echoraw to output raw command line received by the process on Windows Add testexe.exe -echocmdline to output raw command line received by the process on Windows Nov 17, 2022
rawCmdLine = Marshal.PtrToStringUni(cmdLinePtr);
}

Console.WriteLine(rawCmdLine);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make more sense to return a non-zero exit code and write message to StdErr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

return a non-zero exit code and write message to StdErr

What is the purpose of doing this? Do you have some testing scenarios in mind that would need it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is what any well-behaved CLI should do: print error messages to stderr, indicate failure via a non-zero exit code. Except in cases where backward compatibility must (unfortunately) be maintained, there's no good reason not to do this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with Michael Klement (@mklement0), even though this is a test tool, we want to set good examples as other folks may end up using this code for their own projects.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm afraid I need some clarification on this.
Are you suggesting returning non-zero exit code and write an error message instead of just writing out N/A when running on non-windows? The initial comment looks like suggesting always doing that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I understood Steve Lee (@SteveL-MSFT) correctly, his comment was solely related to this unrelated piece of code, which deals with passing an unknown test name to the utility (the cited code originally showed that).

                    default:
                        Console.WriteLine("Unknown test {0}. Run with '-h' for help.", args[0]);
                        break;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Steve Lee (@SteveL-MSFT) Is that what you mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have updated that piece of code based on the feedback. Please let me know if you mean something else.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 21, 2022
@SteveL-MSFT

Copy link
Copy Markdown
Member

Maybe James Truher (@JamesWTruher) has some ideas on what tests can use this. Just seems odd to have this in testexe without it being used in a test. That can be a separate PR and doesn't block this PR as this is useful for investigating issues.

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 22, 2022
@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 34 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +31 -3
Percentile : 13.6%

Total files changed: 1

Change summary by file extension:
.cs : +31 -3

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@daxian-dbw

Copy link
Copy Markdown
Member Author

Steve Lee (@SteveL-MSFT) Can you please take another look when you get a chance? Thanks!

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Dec 6, 2022
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit bd6edfd into PowerShell:master Dec 6, 2022
@ghost

Copy link
Copy Markdown

🎉v7.4.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Test Indicates that a PR should be marked as a test change in the Change Log Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants