Skip to content

Add test for -WhatIf for New-FileCatalog - #8966

Merged
Ilya (iSazonov) merged 6 commits into
PowerShell:masterfrom
mjanko5:newfilecatalog-whatif
Feb 27, 2019
Merged

Ilya (iSazonov) merged 6 commits into
PowerShell:masterfrom
mjanko5:newfilecatalog-whatif

Conversation

@mjanko5

Copy link
Copy Markdown
Contributor

PR Summary

fixes #2866.
Implemented by Matt Jankowski (@mjanko5) (me) and Marek Zietek (@MarekZietek) with the guidance of TylerLeonhardt and Rob Holt (@rjmholt) at HackIllinois 2019.

PR Context

The new code adds a second parameter to the ShouldProcess method to CatalogCommands.cs, which makes -WhatIf work for the New-FileCatalog command.

PR Checklist

{
PerformAction(paths, catalogFilePath);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove this newline


if (ShouldProcess(catalogFilePath))
string action = StringUtil.Format(Modules.CreatingModuleManifestFile, catalogFilePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need for this newline

$result | Should -Be "Valid"
}

It "TestCatalogWhatIfForNewFileCatalog"{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
It "TestCatalogWhatIfForNewFileCatalog"{
It "New-FileCatalog -WhatIf does not create file" {

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.

The rest of the file has the smooshed test titles... do you think we should move away from what the rest of the file does, Rob Holt (@rjmholt)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally speaking in newer tests we opt for not smooshing them. Probably this test file should have a followup PR to make the test titles more readable across the whole file when we're done here. 🙂

}

if (ShouldProcess(catalogFilePath))
string action = StringUtil.Format(Modules.CreatingModuleManifestFile, catalogFilePath);

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 noticed here you are using the

Modules.CreatingModuleManifestFile

property which comes from the file:

PowerShell/src/System.Management.Automation/resources/Modules.resx

Rather than using that one, you should add a new entry in that resx file called like CreatingFileCatalog

and use it instead.

NOTE: In order to rebuild the resx files... instead of running

Start-PSBuild
you run
Start-PSBuild -Clean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually TylerLeonhardt if all you're doing is regenerating your resx files you want to Start-PSBuild -ResGen

But yeah clean build is easy and covers it for ya. 😄

@iSazonov

Copy link
Copy Markdown
Collaborator

I wonder if this fix works. If it works it is a tricky bug in ShouldProcess() and it is better fix the bug.
We can see implementation in src\System.Management.Automation\engine\MshCommandRuntime.cs
And I'd use debugger to understand how the code works.

@TylerLeonhardt

Copy link
Copy Markdown
Member

Ilya (@iSazonov) the fix does work (hence the added test). And I agree with you that the underlying bug should be investigated and fixed.

That said, one thing that this fix does is align the ShouldProcess call to the same call as New-ModuleManifest which does a similar action.

So I still think this PR is valid.

The student also followed up on the original issue regarding this bug in ShouldProcess

@iSazonov

Ilya (iSazonov) commented Feb 24, 2019 •

Copy link
Copy Markdown
Collaborator

the fix does work (hence the added test).

The test is passed without the fix.
And I can not repo with example from source issue.

@mjanko5

Matt Jankowski (mjanko5) commented Feb 24, 2019 •

Copy link
Copy Markdown
Contributor Author

TylerLeonhardt Rob Holt (@rjmholt) Ilya (@iSazonov) Rain Sallow (/u/ta11ow) (@vexx32) Looks like there is a conversation about our code update / PR. However, I will leave at that here, and look forward to working with your team in the future. Thanks to Rob and Tyler for their mentorship and guidance at the hackathon. I learned a lot about PowerShell, GitHub, and open source.

@iSazonov

Ilya (iSazonov) commented Feb 25, 2019 •

Copy link
Copy Markdown
Collaborator

TylerLeonhardt Rob Holt (@rjmholt) Can you repro? If no please close the PR.

@rjmholt

Copy link
Copy Markdown
Collaborator

This already seems to work in 6.2.0-preview.4.

@TylerLeonhardt

Copy link
Copy Markdown
Member

The test addition is worth something...

@rjmholt Rob Holt (rjmholt) added the Hacktoberfest Potential candidate to participate in Hacktoberfest label Feb 25, 2019
@rjmholt

Copy link
Copy Markdown
Collaborator

Have patched this up

@iSazonov Ilya (iSazonov) added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Feb 26, 2019
@iSazonov Ilya (iSazonov) self-assigned this Feb 26, 2019
@TylerLeonhardt TylerLeonhardt changed the title Make -WhatIf work for New-FileCatalog Add test for -WhatIf for New-FileCatalog Feb 26, 2019
@iSazonov
Ilya (iSazonov) merged commit 7e0411f into PowerShell:master Feb 27, 2019
@daxian-dbw Dongbo Wang (daxian-dbw) added this to the 6.2.0 milestone Mar 11, 2019
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 Hacktoberfest Potential candidate to participate in Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New-FileCatalog ignores -WhatIf

6 participants