[Feature] Address Feedback: Fix style and xml doc issues. Update tests

This commit is contained in:
Dongbo Wang
2018-07-10 12:46:48 -07:00
parent 2c9519ba3b
commit 0ac878f72c
6 changed files with 54 additions and 29 deletions
@@ -639,12 +639,12 @@ namespace System.Management.Automation
#region Experimental Feature Related Properties
/// <summary>
/// Name of the experimental feature this attribute is associated with.
/// Get name of the experimental feature this attribute is associated with.
/// </summary>
public string ExperimentName { get; }
/// <summary>
/// Action for engine to take when the experimental feature is enabled.
/// Get action for engine to take when the experimental feature is enabled.
/// </summary>
public ExperimentAction ExperimentAction { get; }
@@ -652,7 +652,7 @@ namespace System.Management.Automation
internal bool ToShow => EffectiveAction == ExperimentAction.Show;
/// <summary>
/// Effective action to take at run time.
/// Get effective action to take at run time.
/// </summary>
private ExperimentAction EffectiveAction
{
@@ -13,7 +13,7 @@ using System.Runtime.CompilerServices;
namespace System.Management.Automation
{
/// <summary>
/// Support experimental features in PowerShell
/// Support experimental features in PowerShell.
/// </summary>
public class ExperimentalFeature
{
@@ -103,7 +103,11 @@ namespace System.Management.Automation
// instead, it will be done when the type is used for the first time, which is always earlier than
// any experimental features take effect.
string[] enabledFeatures = Utils.EmptyArray<string>();
try { enabledFeatures = PowerShellConfig.Instance.GetExperimentalFeatures(); } catch (Exception e) when (LogException(e)) { }
try
{
enabledFeatures = PowerShellConfig.Instance.GetExperimentalFeatures();
}
catch (Exception e) when (LogException(e)) { }
EnabledExperimentalFeatureNames = ProcessEnabledFeatures(enabledFeatures);
}
@@ -165,7 +169,7 @@ namespace System.Management.Automation
/// <summary>
/// Check if the name follows the engine experimental feature name convention.
/// Convention: prefix 'PS' to the feature name -- PSFeatureName
/// Convention: prefix 'PS' to the feature name -- 'PSFeatureName'.
/// </summary>
internal static bool IsEngineFeatureName(string featureName)
{
@@ -174,10 +178,10 @@ namespace System.Management.Automation
/// <summary>
/// Check if the name follows the module experimental feature name convention.
/// Convention: ModuleName.FeatureName
/// Convention: prefix the module name to the feature name -- 'ModuleName.FeatureName'.
/// </summary>
/// <param name="featureName">The feature name to check.</param>
/// <param name="moduleName">When specified, we check if the feature name matches the module name</param>
/// <param name="moduleName">When specified, we check if the feature name matches the module name.</param>
internal static bool IsModuleFeatureName(string featureName, string moduleName = null)
{
// Feature names cannot start with a dot
@@ -263,12 +267,12 @@ namespace System.Management.Automation
public sealed class ExperimentalAttribute : ParsingBaseAttribute
{
/// <summary>
/// Specify the experimental feature this attribute is associated with.
/// Get name of the experimental feature this attribute is associated with.
/// </summary>
public string ExperimentName { get; }
/// <summary>
/// Specify the action for engine to take when the experimental feature is enabled.
/// Get action for engine to take when the experimental feature is enabled.
/// </summary>
public ExperimentAction ExperimentAction { get; }
@@ -316,7 +320,7 @@ namespace System.Management.Automation
internal bool ToShow => EffectiveAction == ExperimentAction.Show;
/// <summary>
/// Effective action to take at run time.
/// Get effective action to take at run time.
/// </summary>
private ExperimentAction EffectiveAction
{
@@ -17,14 +17,14 @@ namespace Microsoft.PowerShell.Commands
public class GetExperimentalFeatureCommand : PSCmdlet
{
/// <summary>
/// Specify the feature names.
/// Get and set the feature names.
/// </summary>
[Parameter(ValueFromPipeline = true, Position = 0)]
[ValidateNotNullOrEmpty]
public string[] Name { get; set; }
/// <summary>
/// Search module paths to find all available experimental features.
/// Get and set the switch flag to search module paths to find all available experimental features.
/// </summary>
[Parameter]
public SwitchParameter ListAvailable { get; set; }
@@ -2071,8 +2071,8 @@ namespace Microsoft.PowerShell.Commands
if (writingErrors)
{
WriteError(new ErrorRecord(new ArgumentException(Modules.ExperimentalFeatureNameMissingOrEmpty),
"Modules_ExperimentalFeatureNameMissingOrEmpty",
ErrorCategory.InvalidData, null));
"Modules_ExperimentalFeatureNameMissingOrEmpty",
ErrorCategory.InvalidData, null));
}
containedErrors = true;
@@ -2086,8 +2086,8 @@ namespace Microsoft.PowerShell.Commands
string invalidNameStr = String.Join(", ", invalidNames);
string errorMsg = StringUtil.Format(Modules.InvalidExperimentalFeatureName, invalidNameStr);
WriteError(new ErrorRecord(new ArgumentException(errorMsg),
"Modules_InvalidExperimentalFeatureName",
ErrorCategory.InvalidData, null));
"Modules_InvalidExperimentalFeatureName",
ErrorCategory.InvalidData, null));
}
containedErrors = true;
@@ -1419,7 +1419,10 @@ namespace System.Management.Automation.Language
{
return Compiler.GetAttribute(potentialExpAttr) as ExperimentalAttribute;
}
catch (Exception) { /* catch all and assume it's not a declaration of ExperimentalAttribute */ }
catch (Exception)
{
// catch all and assume it's not a declaration of ExperimentalAttribute
}
}
return null;
@@ -381,18 +381,36 @@ Describe "Expected errors" -Tag "CI" {
{ [Experimental()]param() } | Should -Throw -ErrorId "MethodCountCouldNotFindBest"
}
It "Argument validation for constructors of 'ExperimentalAttribute' and 'ParameterAttribute'" {
{ [Experimental]::new("", "None") } | Should -Throw -ErrorId "PSArgumentNullException"
{ [Experimental]::new([NullString]::Value, "None") } | Should -Throw -ErrorId "PSArgumentNullException"
{ [Experimental]::new("feature", "None") } | Should -Throw -ErrorId "PSArgumentException"
{ [Experimental]::new("feature", "Show") } | Should -Not -Throw
{ [Experimental]::new("feature", "Hide") } | Should -Not -Throw
It "Argument validation for constructors of 'ExperimentalAttribute' - <TestName>" -TestCases @(
@{ TestName = "Name is empty string"; FeatureName = ""; FeatureAction = "None"; ErrorId = "PSArgumentNullException" }
@{ TestName = "Name is null"; FeatureName = [NullString]::Value; FeatureAction = "None"; ErrorId = "PSArgumentNullException" }
@{ TestName = "Action is None"; FeatureName = "feature"; FeatureAction = "None"; ErrorId = "PSArgumentException" }
@{ TestName = "Action is Show"; FeatureName = "feature"; FeatureAction = "Show"; ErrorId = $null }
@{ TestName = "Action is Hide"; FeatureName = "feature"; FeatureAction = "Hide"; ErrorId = $null }
) {
param($FeatureName, $FeatureAction, $ErrorId)
{ [Parameter]::new("", "None") } | Should -Throw -ErrorId "PSArgumentNullException"
{ [Parameter]::new([NullString]::Value, "None") } | Should -Throw -ErrorId "PSArgumentNullException"
{ [Parameter]::new("feature", "None") } | Should -Throw -ErrorId "PSArgumentException"
{ [Parameter]::new("feature", "Show") } | Should -Not -Throw
{ [Parameter]::new("feature", "Hide") } | Should -Not -Throw
if ($ErrorId -ne $null) {
{ [Experimental]::new($FeatureName, $FeatureAction) } | Should -Throw -ErrorId $ErrorId
} else {
{ [Experimental]::new($FeatureName, $FeatureAction) } | Should -Not -Throw
}
}
It "Argument validation for constructors of 'ParameterAttribute' - <TestName>" -TestCases @(
@{ TestName = "Name is empty string"; FeatureName = ""; FeatureAction = "None"; ErrorId = "PSArgumentNullException" }
@{ TestName = "Name is null"; FeatureName = [NullString]::Value; FeatureAction = "None"; ErrorId = "PSArgumentNullException" }
@{ TestName = "Action is None"; FeatureName = "feature"; FeatureAction = "None"; ErrorId = "PSArgumentException" }
@{ TestName = "Action is Show"; FeatureName = "feature"; FeatureAction = "Show"; ErrorId = $null }
@{ TestName = "Action is Hide"; FeatureName = "feature"; FeatureAction = "Hide"; ErrorId = $null }
) {
param($FeatureName, $FeatureAction, $ErrorId)
if ($ErrorId -ne $null) {
{ [Parameter]::new($FeatureName, $FeatureAction) } | Should -Throw -ErrorId $ErrorId
} else {
{ [Parameter]::new($FeatureName, $FeatureAction) } | Should -Not -Throw
}
}
It "Feature name check" {