-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use functions instead of aliases and patch warning (#2499)
* Use functions instead of aliases and patch warning * Skip description check on Should-* * Somehow the sleep sleeps for 0.5 ms, cannot repro
- Loading branch information
Showing
41 changed files
with
160 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace Pester | ||
{ | ||
/// <summary> | ||
/// Modifies that list of recommended Verbs, so we can export Should-* functions directly without | ||
/// showing a warning to the user. Reverts the change after few seconds. | ||
/// </summary> | ||
public static class VerbsPatcher | ||
{ | ||
// Keep the tasks we started so they finish and are not garbage collected. | ||
// Concurrent bag in case we start this multiple times, and god forbid in parallel. | ||
private static ConcurrentBag<Task> s_tasks = new ConcurrentBag<Task>(); | ||
|
||
public static void AllowShouldVerb(int powershellVersion) | ||
{ | ||
var should = "Should"; | ||
|
||
var fieldName = powershellVersion == 5 ? "validVerbs" : "s_validVerbs"; | ||
var verbsType = typeof(System.Management.Automation.VerbsCommon).Assembly.GetType("System.Management.Automation.Verbs"); | ||
var verbsField = verbsType.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic); | ||
|
||
// private static readonly Dictionary<string, bool> s_validVerbs; | ||
Dictionary<string, bool> validVerbs = (Dictionary<string, bool>)verbsField.GetValue(null); | ||
// Overwrite when we call this multiple times. | ||
validVerbs[should] = true; // The bool does not matter. | ||
|
||
s_tasks.Add(Task.Run(async () => | ||
{ | ||
await Task.Delay(5_000); | ||
try | ||
{ | ||
if (validVerbs.ContainsKey(should)) | ||
{ | ||
validVerbs.Remove(should); | ||
} | ||
} | ||
catch { } | ||
})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/functions/assert/Collection/Should-NotContainCollection.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
function Assert-Throw { | ||
function Should-Throw { | ||
<# | ||
.SYNOPSIS | ||
Asserts that a script block throws an exception. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.