Add autoload for TestLanguage.psm1 TestHelpers.psm1 (#3456)
* Add autoload for TestHelpers.psm1 Test.Helpers.psm1 was renamed to TestHelpers.psm1 * Resolve conflit and rebase Add autoload for TestLanguage.psm1 * Remove unneeded comments from PSD1 files * Rename test modules Remove approved verbs (Get-Verb) from module names. * Enhance ShouldBeErrorId to output exception into pipeline for later analysis * Remove unneeded comments * Resolve merge conflict
This commit is contained in:
parent
599eae9b1b
commit
e00161a8af
|
@ -1,7 +1,6 @@
|
|||
#
|
||||
# Copyright (c) Microsoft Corporation, 2014
|
||||
#
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
|
||||
try {
|
||||
#
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
Describe 'NestedModules' -Tags "CI" {
|
||||
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
|
||||
function New-TestModule {
|
||||
param(
|
||||
[string]$Name,
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
# Copyright (c) Microsoft Corporation, 2015
|
||||
#
|
||||
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
|
||||
Describe 'Classes inheritance syntax' -Tags "CI" {
|
||||
|
||||
It 'Base types' {
|
||||
|
|
|
@ -2,8 +2,6 @@ Describe 'using module' -Tags "CI" {
|
|||
BeforeAll {
|
||||
$originalPSModulePath = $env:PSModulePath
|
||||
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
|
||||
function New-TestModule {
|
||||
param(
|
||||
[string]$Name,
|
||||
|
|
|
@ -75,8 +75,6 @@ Describe 'enums' -Tags "CI" {
|
|||
|
||||
Describe 'Basic enum errors' -Tags "CI" {
|
||||
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
|
||||
AfterAll {
|
||||
Remove-Module LanguageTestSupport
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
set-strictmode -v 2
|
||||
set-strictmode -v 2
|
||||
|
||||
Describe 'for statement parsing' -Tags "CI" {
|
||||
ShouldBeParseError 'for' MissingOpenParenthesisAfterKeyword 4 -CheckColumnNumber
|
||||
|
|
|
@ -9,9 +9,6 @@ using namespace System.Diagnostics
|
|||
using namespace System.Diagnostics; using namespace System.Runtime.CompilerServices
|
||||
using namespace System.Collections.Generic
|
||||
|
||||
Import-Module $PSScriptRoot\..\LanguageTestSupport.psm1
|
||||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
|
||||
# Flags is System.FlagsAttribute
|
||||
# This tests our implicit 'using namespace System'
|
||||
# despite having other explicit using namespace statements.
|
||||
|
|
|
@ -12,10 +12,6 @@ $script2 = @'
|
|||
"line 3"
|
||||
'@
|
||||
|
||||
$testroot = resolve-path (join-path $psscriptroot ../../..)
|
||||
$common = join-path $testroot Common
|
||||
$helperModule = join-path $common Test.Helpers.psm1
|
||||
|
||||
Describe "Breakpoints when set should be hit" -tag "CI" {
|
||||
BeforeAll {
|
||||
$path = setup -pass -f TestScript_1.ps1 -content $script1
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
$testroot = resolve-path (join-path $psscriptroot ../../..)
|
||||
$common = join-path $testroot Common
|
||||
$helperModule = join-path $common Test.Helpers.psm1
|
||||
|
||||
Describe 'native commands lifecycle' -tags 'Feature' {
|
||||
|
||||
BeforeAll {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
Describe "Job Cmdlet Tests" -Tag "CI" {
|
||||
Context "Simple Jobs" {
|
||||
BeforeEach {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
Describe "Basic FileSystem Provider Tests" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$testDir = "TestDir"
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
|
||||
Describe "Start-Process" -Tags @("CI","SLOW") {
|
||||
|
||||
BeforeAll {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
# determine whether we're elevated
|
||||
Describe "Set-Date" -Tag "CI" {
|
||||
BeforeAll {
|
||||
Import-Module (join-path $psscriptroot "../../Common/Test.Helpers.psm1")
|
||||
$IsElevated = Test-IsElevated
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
|
||||
Describe "New-ModuleManifest tests" -tags "CI" {
|
||||
BeforeEach {
|
||||
New-Item -ItemType Directory -Path testdrive:/module
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
Import-Module $PSScriptRoot\..\..\Common\Test.Helpers.psm1
|
||||
|
||||
Describe "Test-ModuleManifest tests" -tags "CI" {
|
||||
|
||||
AfterEach {
|
||||
|
|
21
test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Normal file
21
test/tools/Modules/HelpersCommon/HelpersCommon.psd1
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Module manifest for module 'HelpersCommon'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
RootModule = 'HelpersCommon.psm1'
|
||||
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
GUID = 'cc1c8e94-51d1-4bc1-b508-62bc09f02f54'
|
||||
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
Description = 'Temporary module contains functions for using in tests'
|
||||
|
||||
FunctionsToExport = 'Wait-UntilTrue', 'Test-IsElevated', 'ShouldBeErrorId'
|
||||
|
||||
}
|
|
@ -57,14 +57,14 @@ function ShouldBeErrorId
|
|||
|
||||
try
|
||||
{
|
||||
& $sb
|
||||
Throw "Exception expected, execution should not have reached here"
|
||||
& $sb | Out-Null
|
||||
Throw "No Exception!"
|
||||
}
|
||||
catch
|
||||
{
|
||||
$_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId
|
||||
$_.FullyQualifiedErrorId | Should Be $FullyQualifiedErrorId | Out-Null
|
||||
# Write the exception to output that allow us to check later other properies of the exception
|
||||
Write-Output $_
|
||||
}
|
||||
}
|
||||
|
||||
export-modulemember -function Wait-UntilTrue,Test-IsElevated, ShouldBeErrorId
|
||||
|
21
test/tools/Modules/HelpersHostCS/HelpersHostCS.psd1
Normal file
21
test/tools/Modules/HelpersHostCS/HelpersHostCS.psd1
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Module manifest for module 'HelpersHostCS'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
RootModule = 'HelpersHostCS.psm1'
|
||||
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
GUID = '40a19c05-d765-41a1-995e-98ca5f247ee1'
|
||||
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
Description = 'Simple console host for console IO tests.'
|
||||
|
||||
FunctionsToExport = 'New-TestHost'
|
||||
|
||||
}
|
|
@ -1,316 +1,315 @@
|
|||
$definition = @'
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Host;
|
||||
using System.Globalization;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Security;
|
||||
using System.Collections;
|
||||
|
||||
namespace TestHost
|
||||
{
|
||||
public class TestHostRawUI : PSHostRawUserInterface
|
||||
{
|
||||
private ConsoleColor _backgroundColor = ConsoleColor.Black;
|
||||
public override ConsoleColor BackgroundColor
|
||||
{
|
||||
get { return _backgroundColor; }
|
||||
set { _backgroundColor = value; }
|
||||
}
|
||||
private ConsoleColor _foregroundColor = ConsoleColor.White;
|
||||
public override ConsoleColor ForegroundColor
|
||||
{
|
||||
get { return _foregroundColor; }
|
||||
set { _foregroundColor = value; }
|
||||
}
|
||||
private string _windowTitle = "title";
|
||||
public override string WindowTitle
|
||||
{
|
||||
get { return _windowTitle; }
|
||||
set { _windowTitle = value; }
|
||||
}
|
||||
private Size _bufferSize = new Size(10,10);
|
||||
public override Size BufferSize
|
||||
{
|
||||
get { return _bufferSize; }
|
||||
set { _bufferSize = value; }
|
||||
}
|
||||
private Coordinates _cursorPosition = new Coordinates(0, 0);
|
||||
public override Coordinates CursorPosition
|
||||
{
|
||||
get { return _cursorPosition; }
|
||||
set { _cursorPosition = value; }
|
||||
}
|
||||
private int _cursorSize = 10;
|
||||
public override int CursorSize
|
||||
{
|
||||
get { return _cursorSize; }
|
||||
set { _cursorSize = value; }
|
||||
}
|
||||
private bool _keyAvailable = false;
|
||||
public override bool KeyAvailable
|
||||
{
|
||||
get { return _keyAvailable; }
|
||||
}
|
||||
public override Size MaxPhysicalWindowSize
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
public override Size MaxWindowSize
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
private Coordinates _windowPosition = new Coordinates(0, 0);
|
||||
public override Coordinates WindowPosition
|
||||
{
|
||||
get { return _windowPosition; }
|
||||
|
||||
set { _windowPosition = value; }
|
||||
}
|
||||
private Size _windowSize = new Size(80, 40);
|
||||
public override Size WindowSize
|
||||
{
|
||||
get { return _windowSize; }
|
||||
set { _windowSize = value; }
|
||||
}
|
||||
public override BufferCell[,] GetBufferContents(Rectangle rectangle) { throw new NotImplementedException(); }
|
||||
public override void FlushInputBuffer() { throw new NotImplementedException(); }
|
||||
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException(); }
|
||||
public override void SetBufferContents(Coordinates origin, BufferCell[,] contents) { throw new NotImplementedException(); }
|
||||
public override void SetBufferContents(Rectangle rectangle, BufferCell fill) { throw new NotImplementedException(); }
|
||||
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill) { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public class Streams
|
||||
{
|
||||
public ArrayList ConsoleOutput = new ArrayList();
|
||||
public ArrayList Input = new ArrayList();
|
||||
public ArrayList Error = new ArrayList();
|
||||
public ArrayList Verbose = new ArrayList();
|
||||
public ArrayList Debug = new ArrayList();
|
||||
public ArrayList Warning = new ArrayList();
|
||||
public ArrayList Information = new ArrayList();
|
||||
public ArrayList Progress = new ArrayList();
|
||||
public ArrayList Prompt = new ArrayList();
|
||||
public void Clear() {
|
||||
ConsoleOutput.Clear();
|
||||
Input.Clear();
|
||||
Error.Clear();
|
||||
Verbose.Clear();
|
||||
Debug.Clear();
|
||||
Warning.Clear();
|
||||
Information.Clear();
|
||||
Progress.Clear();
|
||||
Prompt.Clear();
|
||||
}
|
||||
}
|
||||
public class TestPSHostUserInterface : PSHostUserInterface
|
||||
{
|
||||
private PSHostRawUserInterface _rawui = new TestHostRawUI();
|
||||
public string ReadLineData = "This is readline data";
|
||||
public int PromptedChoice = 0;
|
||||
public string StringForSecureString = "TEST";
|
||||
public string UserNameForCredential = "Admin";
|
||||
public object promptResponse = "this is a prompt response";
|
||||
|
||||
public Streams Streams = new Streams();
|
||||
public override PSHostRawUserInterface RawUI
|
||||
{
|
||||
get { return _rawui; }
|
||||
}
|
||||
|
||||
public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions)
|
||||
{
|
||||
if (descriptions == null || descriptions[0] == null)
|
||||
{
|
||||
throw new ArgumentException("descriptions");
|
||||
}
|
||||
|
||||
string s = descriptions[0].Name;
|
||||
Streams.Prompt.Add(caption + ":" + message + ":" + s);
|
||||
Dictionary<string, PSObject> d = new Dictionary<string, PSObject>();
|
||||
d.Add(s, new PSObject(promptResponse));
|
||||
return d;
|
||||
}
|
||||
|
||||
public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice)
|
||||
{
|
||||
Streams.Prompt.Add(caption + ":" + message);
|
||||
return PromptedChoice;
|
||||
}
|
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
|
||||
{
|
||||
Streams.Prompt.Add("Credential:" + caption + ":" + message);
|
||||
SecureString ss = ReadLineAsSecureString();
|
||||
string userNameToUse = string.IsNullOrEmpty(userName) ? UserNameForCredential : userName;
|
||||
return new PSCredential(userNameToUse, ss);
|
||||
}
|
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
|
||||
{
|
||||
Streams.Prompt.Add("Credential:" + caption + ":" + message);
|
||||
SecureString ss = ReadLineAsSecureString();
|
||||
string userNameToUse = string.IsNullOrEmpty(userName) ? UserNameForCredential : userName;
|
||||
return new PSCredential(userNameToUse, ss);
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
return ReadLineData;
|
||||
}
|
||||
|
||||
public override SecureString ReadLineAsSecureString()
|
||||
{
|
||||
SecureString ss = new SecureString();
|
||||
foreach(char c in StringForSecureString.ToCharArray()) { ss.AppendChar(c); }
|
||||
return ss;
|
||||
}
|
||||
|
||||
// Cmdlets call 'Write' and 'WriteLine' methods implicitly.
|
||||
// To see difference between 'Write' and 'WriteLine' with and w/o colors in the debug output
|
||||
// we need use a meta information.
|
||||
// So we make a output string as:
|
||||
// <Foregraund color name> : <Background color name> : <'user value'> : <'NewLine' or 'NoNewLine'>
|
||||
//
|
||||
public override void Write(string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add("::"+value+":NoNewLine");
|
||||
}
|
||||
|
||||
public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add(foregroundColor+":"+backgroundColor+":"+value+":NoNewLine");
|
||||
}
|
||||
|
||||
public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add(foregroundColor+":"+backgroundColor+":"+value+":NewLine");
|
||||
}
|
||||
|
||||
public override void WriteDebugLine(string message)
|
||||
{
|
||||
Streams.Debug.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteErrorLine(string value)
|
||||
{
|
||||
Streams.Error.Add(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add("::"+value+":NewLine");
|
||||
}
|
||||
|
||||
public override void WriteProgress(long sourceId, ProgressRecord record)
|
||||
{
|
||||
Streams.Progress.Add(record);
|
||||
}
|
||||
|
||||
public override void WriteVerboseLine(string message)
|
||||
{
|
||||
Streams.Verbose.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteWarningLine(string message)
|
||||
{
|
||||
Streams.Warning.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteInformation(InformationRecord record)
|
||||
{
|
||||
HostInformationMessage hostOutput = record.MessageData as HostInformationMessage;
|
||||
if (hostOutput != null) {
|
||||
string message = hostOutput.Message;
|
||||
Streams.Information.Add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TestHost : PSHost
|
||||
{
|
||||
private Guid _instanceId = Guid.NewGuid();
|
||||
private PSHostUserInterface _ui = new TestPSHostUserInterface();
|
||||
public string _hostName = "TEST HOST";
|
||||
public Version _version = new Version(6, 0);
|
||||
int promptLevel = 0;
|
||||
public override CultureInfo CurrentCulture
|
||||
{
|
||||
get { return Thread.CurrentThread.CurrentCulture; }
|
||||
}
|
||||
|
||||
public override CultureInfo CurrentUICulture
|
||||
{
|
||||
get { return Thread.CurrentThread.CurrentUICulture; }
|
||||
}
|
||||
|
||||
public override Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return _hostName; }
|
||||
}
|
||||
|
||||
public override PSHostUserInterface UI
|
||||
{
|
||||
get { return _ui; }
|
||||
}
|
||||
|
||||
public override Version Version
|
||||
{
|
||||
get { return _version; }
|
||||
}
|
||||
|
||||
public override void EnterNestedPrompt()
|
||||
{
|
||||
promptLevel++;
|
||||
}
|
||||
|
||||
public override void ExitNestedPrompt()
|
||||
{
|
||||
promptLevel--;
|
||||
}
|
||||
|
||||
public override void NotifyBeginApplication()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void NotifyEndApplication()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetShouldExit(int exitCode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
'@
|
||||
## '
|
||||
function New-TestHost
|
||||
{
|
||||
If ($IsCoreCLR)
|
||||
{
|
||||
$references = @()
|
||||
}
|
||||
else
|
||||
{
|
||||
$references = "System.Management.Automation"
|
||||
}
|
||||
|
||||
if ( ! ("TestHost.TestHost" -as "type" )) {
|
||||
$t = add-Type -pass $definition -ref $references
|
||||
}
|
||||
|
||||
[TestHost.TestHost]::New()
|
||||
}
|
||||
|
||||
$definition = @'
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Host;
|
||||
using System.Globalization;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Security;
|
||||
using System.Collections;
|
||||
|
||||
namespace TestHost
|
||||
{
|
||||
public class TestHostRawUI : PSHostRawUserInterface
|
||||
{
|
||||
private ConsoleColor _backgroundColor = ConsoleColor.Black;
|
||||
public override ConsoleColor BackgroundColor
|
||||
{
|
||||
get { return _backgroundColor; }
|
||||
set { _backgroundColor = value; }
|
||||
}
|
||||
private ConsoleColor _foregroundColor = ConsoleColor.White;
|
||||
public override ConsoleColor ForegroundColor
|
||||
{
|
||||
get { return _foregroundColor; }
|
||||
set { _foregroundColor = value; }
|
||||
}
|
||||
private string _windowTitle = "title";
|
||||
public override string WindowTitle
|
||||
{
|
||||
get { return _windowTitle; }
|
||||
set { _windowTitle = value; }
|
||||
}
|
||||
private Size _bufferSize = new Size(10,10);
|
||||
public override Size BufferSize
|
||||
{
|
||||
get { return _bufferSize; }
|
||||
set { _bufferSize = value; }
|
||||
}
|
||||
private Coordinates _cursorPosition = new Coordinates(0, 0);
|
||||
public override Coordinates CursorPosition
|
||||
{
|
||||
get { return _cursorPosition; }
|
||||
set { _cursorPosition = value; }
|
||||
}
|
||||
private int _cursorSize = 10;
|
||||
public override int CursorSize
|
||||
{
|
||||
get { return _cursorSize; }
|
||||
set { _cursorSize = value; }
|
||||
}
|
||||
private bool _keyAvailable = false;
|
||||
public override bool KeyAvailable
|
||||
{
|
||||
get { return _keyAvailable; }
|
||||
}
|
||||
public override Size MaxPhysicalWindowSize
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
public override Size MaxWindowSize
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
private Coordinates _windowPosition = new Coordinates(0, 0);
|
||||
public override Coordinates WindowPosition
|
||||
{
|
||||
get { return _windowPosition; }
|
||||
|
||||
set { _windowPosition = value; }
|
||||
}
|
||||
private Size _windowSize = new Size(80, 40);
|
||||
public override Size WindowSize
|
||||
{
|
||||
get { return _windowSize; }
|
||||
set { _windowSize = value; }
|
||||
}
|
||||
public override BufferCell[,] GetBufferContents(Rectangle rectangle) { throw new NotImplementedException(); }
|
||||
public override void FlushInputBuffer() { throw new NotImplementedException(); }
|
||||
public override KeyInfo ReadKey(ReadKeyOptions options) { throw new NotImplementedException(); }
|
||||
public override void SetBufferContents(Coordinates origin, BufferCell[,] contents) { throw new NotImplementedException(); }
|
||||
public override void SetBufferContents(Rectangle rectangle, BufferCell fill) { throw new NotImplementedException(); }
|
||||
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill) { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public class Streams
|
||||
{
|
||||
public ArrayList ConsoleOutput = new ArrayList();
|
||||
public ArrayList Input = new ArrayList();
|
||||
public ArrayList Error = new ArrayList();
|
||||
public ArrayList Verbose = new ArrayList();
|
||||
public ArrayList Debug = new ArrayList();
|
||||
public ArrayList Warning = new ArrayList();
|
||||
public ArrayList Information = new ArrayList();
|
||||
public ArrayList Progress = new ArrayList();
|
||||
public ArrayList Prompt = new ArrayList();
|
||||
public void Clear() {
|
||||
ConsoleOutput.Clear();
|
||||
Input.Clear();
|
||||
Error.Clear();
|
||||
Verbose.Clear();
|
||||
Debug.Clear();
|
||||
Warning.Clear();
|
||||
Information.Clear();
|
||||
Progress.Clear();
|
||||
Prompt.Clear();
|
||||
}
|
||||
}
|
||||
public class TestPSHostUserInterface : PSHostUserInterface
|
||||
{
|
||||
private PSHostRawUserInterface _rawui = new TestHostRawUI();
|
||||
public string ReadLineData = "This is readline data";
|
||||
public int PromptedChoice = 0;
|
||||
public string StringForSecureString = "TEST";
|
||||
public string UserNameForCredential = "Admin";
|
||||
public object promptResponse = "this is a prompt response";
|
||||
|
||||
public Streams Streams = new Streams();
|
||||
public override PSHostRawUserInterface RawUI
|
||||
{
|
||||
get { return _rawui; }
|
||||
}
|
||||
|
||||
public override Dictionary<string, PSObject> Prompt(string caption, string message, Collection<FieldDescription> descriptions)
|
||||
{
|
||||
if (descriptions == null || descriptions[0] == null)
|
||||
{
|
||||
throw new ArgumentException("descriptions");
|
||||
}
|
||||
|
||||
string s = descriptions[0].Name;
|
||||
Streams.Prompt.Add(caption + ":" + message + ":" + s);
|
||||
Dictionary<string, PSObject> d = new Dictionary<string, PSObject>();
|
||||
d.Add(s, new PSObject(promptResponse));
|
||||
return d;
|
||||
}
|
||||
|
||||
public override int PromptForChoice(string caption, string message, Collection<ChoiceDescription> choices, int defaultChoice)
|
||||
{
|
||||
Streams.Prompt.Add(caption + ":" + message);
|
||||
return PromptedChoice;
|
||||
}
|
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
|
||||
{
|
||||
Streams.Prompt.Add("Credential:" + caption + ":" + message);
|
||||
SecureString ss = ReadLineAsSecureString();
|
||||
string userNameToUse = string.IsNullOrEmpty(userName) ? UserNameForCredential : userName;
|
||||
return new PSCredential(userNameToUse, ss);
|
||||
}
|
||||
|
||||
public override PSCredential PromptForCredential(string caption, string message, string userName, string targetName, PSCredentialTypes allowedCredentialTypes, PSCredentialUIOptions options)
|
||||
{
|
||||
Streams.Prompt.Add("Credential:" + caption + ":" + message);
|
||||
SecureString ss = ReadLineAsSecureString();
|
||||
string userNameToUse = string.IsNullOrEmpty(userName) ? UserNameForCredential : userName;
|
||||
return new PSCredential(userNameToUse, ss);
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
return ReadLineData;
|
||||
}
|
||||
|
||||
public override SecureString ReadLineAsSecureString()
|
||||
{
|
||||
SecureString ss = new SecureString();
|
||||
foreach(char c in StringForSecureString.ToCharArray()) { ss.AppendChar(c); }
|
||||
return ss;
|
||||
}
|
||||
|
||||
// Cmdlets call 'Write' and 'WriteLine' methods implicitly.
|
||||
// To see difference between 'Write' and 'WriteLine' with and w/o colors in the debug output
|
||||
// we need use a meta information.
|
||||
// So we make a output string as:
|
||||
// <Foregraund color name> : <Background color name> : <'user value'> : <'NewLine' or 'NoNewLine'>
|
||||
//
|
||||
public override void Write(string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add("::"+value+":NoNewLine");
|
||||
}
|
||||
|
||||
public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add(foregroundColor+":"+backgroundColor+":"+value+":NoNewLine");
|
||||
}
|
||||
|
||||
public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add(foregroundColor+":"+backgroundColor+":"+value+":NewLine");
|
||||
}
|
||||
|
||||
public override void WriteDebugLine(string message)
|
||||
{
|
||||
Streams.Debug.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteErrorLine(string value)
|
||||
{
|
||||
Streams.Error.Add(value);
|
||||
}
|
||||
|
||||
public override void WriteLine(string value)
|
||||
{
|
||||
Streams.ConsoleOutput.Add("::"+value+":NewLine");
|
||||
}
|
||||
|
||||
public override void WriteProgress(long sourceId, ProgressRecord record)
|
||||
{
|
||||
Streams.Progress.Add(record);
|
||||
}
|
||||
|
||||
public override void WriteVerboseLine(string message)
|
||||
{
|
||||
Streams.Verbose.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteWarningLine(string message)
|
||||
{
|
||||
Streams.Warning.Add(message);
|
||||
}
|
||||
|
||||
public override void WriteInformation(InformationRecord record)
|
||||
{
|
||||
HostInformationMessage hostOutput = record.MessageData as HostInformationMessage;
|
||||
if (hostOutput != null) {
|
||||
string message = hostOutput.Message;
|
||||
Streams.Information.Add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TestHost : PSHost
|
||||
{
|
||||
private Guid _instanceId = Guid.NewGuid();
|
||||
private PSHostUserInterface _ui = new TestPSHostUserInterface();
|
||||
public string _hostName = "TEST HOST";
|
||||
public Version _version = new Version(6, 0);
|
||||
int promptLevel = 0;
|
||||
public override CultureInfo CurrentCulture
|
||||
{
|
||||
get { return Thread.CurrentThread.CurrentCulture; }
|
||||
}
|
||||
|
||||
public override CultureInfo CurrentUICulture
|
||||
{
|
||||
get { return Thread.CurrentThread.CurrentUICulture; }
|
||||
}
|
||||
|
||||
public override Guid InstanceId
|
||||
{
|
||||
get { return _instanceId; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return _hostName; }
|
||||
}
|
||||
|
||||
public override PSHostUserInterface UI
|
||||
{
|
||||
get { return _ui; }
|
||||
}
|
||||
|
||||
public override Version Version
|
||||
{
|
||||
get { return _version; }
|
||||
}
|
||||
|
||||
public override void EnterNestedPrompt()
|
||||
{
|
||||
promptLevel++;
|
||||
}
|
||||
|
||||
public override void ExitNestedPrompt()
|
||||
{
|
||||
promptLevel--;
|
||||
}
|
||||
|
||||
public override void NotifyBeginApplication()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void NotifyEndApplication()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SetShouldExit(int exitCode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
'@
|
||||
## '
|
||||
function New-TestHost
|
||||
{
|
||||
If ($IsCoreCLR)
|
||||
{
|
||||
$references = @()
|
||||
}
|
||||
else
|
||||
{
|
||||
$references = "System.Management.Automation"
|
||||
}
|
||||
|
||||
if ( ! ("TestHost.TestHost" -as "type" )) {
|
||||
$t = add-Type -pass $definition -ref $references
|
||||
}
|
||||
|
||||
[TestHost.TestHost]::New()
|
||||
}
|
22
test/tools/Modules/HelpersLanguage/HelpersLanguage.psd1
Normal file
22
test/tools/Modules/HelpersLanguage/HelpersLanguage.psd1
Normal file
|
@ -0,0 +1,22 @@
|
|||
#
|
||||
# Module manifest for module 'HelpersLanguage'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
RootModule = 'HelpersLanguage.psm1'
|
||||
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
GUID = 'a575af5e-2bd1-427f-b966-48640788896b'
|
||||
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
Description = 'Temporary module for language tests'
|
||||
|
||||
FunctionsToExport = 'Get-ParseResults', 'Get-RuntimeError', 'ShouldBeParseError',
|
||||
'Test-ErrorStmt', 'Test-Ast', 'Test-ErrorStmtForSwitchFlag'
|
||||
|
||||
}
|
|
@ -1,193 +1,193 @@
|
|||
|
||||
#
|
||||
# Run the new parser, return either errors or the ast
|
||||
#
|
||||
function Get-ParseResults
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
|
||||
[string]$src,
|
||||
[switch]$Ast
|
||||
)
|
||||
|
||||
$errors = $null
|
||||
$result = [System.Management.Automation.Language.Parser]::ParseInput($src, [ref]$null, [ref]$errors)
|
||||
if ($Ast) { $result } else { ,$errors }
|
||||
}
|
||||
|
||||
#
|
||||
# Run script and return errors
|
||||
#
|
||||
function Get-RuntimeError
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$True,Mandatory=$True)][string]$src
|
||||
)
|
||||
|
||||
$errors = $null
|
||||
try
|
||||
{
|
||||
[scriptblock]::Create($src).Invoke() > $null
|
||||
}
|
||||
catch
|
||||
{
|
||||
return $_.Exception.InnerException.ErrorRecord
|
||||
}
|
||||
}
|
||||
|
||||
function position_message
|
||||
{
|
||||
param($position)
|
||||
|
||||
if ($position.Line.Length -lt $position.ColumnNumber)
|
||||
{
|
||||
$position.Line + " <<<<"
|
||||
}
|
||||
else
|
||||
{
|
||||
$position.Line.Insert($position.ColumnNumber, " <<<<")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Pester friendly version of Test-Error
|
||||
#
|
||||
function ShouldBeParseError
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$src,
|
||||
[string[]]$expectedErrors,
|
||||
[int[]]$expectedOffsets,
|
||||
# This is a temporary solution after moving type creation from parse time to runtime
|
||||
[switch]$SkipAndCheckRuntimeError,
|
||||
# for test coverarage purpose, tests validate columnNumber or offset
|
||||
[switch]$CheckColumnNumber,
|
||||
# Skip this test in Travis CI nightly build
|
||||
[switch]$SkipInTravisFullBuild
|
||||
)
|
||||
|
||||
#
|
||||
# CrossGen'ed assemblies cause a hang to happen when running tests with this helper function in Linux and OSX.
|
||||
# The issue has been reported to CoreCLR team. We need to work around it for now with the following approach:
|
||||
# 1. For pull request and push commit, build without '-CrossGen' and run the parsing tests
|
||||
# 2. For nightly build, build with '-CrossGen' but don't run the parsing tests
|
||||
# In this way, we will continue to exercise these parsing tests for each CI build, and skip them for nightly
|
||||
# build to avoid a hang.
|
||||
# Note: this change should be reverted once the 'CrossGen' issue is fixed by CoreCLR. The issue is tracked by
|
||||
# https://github.com/dotnet/coreclr/issues/9745
|
||||
#
|
||||
if ($SkipInTravisFullBuild) {
|
||||
## Report that we skipped the test and return
|
||||
It "Parse error expected: <<$src>>" -Skip {}
|
||||
return
|
||||
}
|
||||
|
||||
Context "Parse error expected: <<$src>>" {
|
||||
# Test case error if this fails
|
||||
$expectedErrors.Count | Should Be $expectedOffsets.Count
|
||||
|
||||
if ($SkipAndCheckRuntimeError)
|
||||
{
|
||||
It "error should happen at parse time, not at runtime" -Skip {}
|
||||
$errors = Get-RuntimeError -Src $src
|
||||
# for runtime errors we will only get the first one
|
||||
$expectedErrors = ,$expectedErrors[0]
|
||||
$expectedOffsets = ,$expectedOffsets[0]
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors = Get-ParseResults -Src $src
|
||||
}
|
||||
|
||||
It "Error count" { $errors.Count | Should Be $expectedErrors.Count }
|
||||
for ($i = 0; $i -lt $errors.Count; ++$i)
|
||||
{
|
||||
$err = $errors[$i]
|
||||
|
||||
if ($SkipAndCheckRuntimeError)
|
||||
{
|
||||
$errorId = $err.FullyQualifiedErrorId
|
||||
}
|
||||
else
|
||||
{
|
||||
$errorId = $err.ErrorId
|
||||
}
|
||||
It "Error Id" { $errorId | Should Be $expectedErrors[$i] }
|
||||
$acutalPostion = $err.Extent.StartScriptPosition.Offset
|
||||
if ( $CheckColumnNumber ) { $acutalPostion = $err.Extent.StartScriptPosition.ColumnNumber }
|
||||
It "Error position" -Pending:$SkipAndCheckRuntimeError { $acutalPostion | Should Be $expectedOffsets[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Flatten-Ast
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param([System.Management.Automation.Language.Ast] $ast)
|
||||
|
||||
$ast
|
||||
$ast | gm -type property | ? { ($prop = $_.Name) -ne 'Parent' } | % {
|
||||
$ast.$prop | ? { $_ -is [System.Management.Automation.Language.Ast] } | % { Flatten-Ast $_ }
|
||||
}
|
||||
}
|
||||
|
||||
function Test-ErrorStmt
|
||||
{
|
||||
param([string]$src, [string]$errorStmtExtent)
|
||||
$a = $args
|
||||
Context "Error Statement expected: <<$src>>" {
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$asts = @(Flatten-Ast $ast.EndBlock.Statements[0])
|
||||
|
||||
It 'Type is ErrorStatementAst' { $asts[0] | Should BeOfType System.Management.Automation.Language.ErrorStatementAst }
|
||||
It "`$asts.count" { $asts.Count | Should Be ($a.Count + 1) }
|
||||
It "`$asts[0].Extent.Text" { $asts[0].Extent.Text | Should Be $errorStmtExtent }
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
It "`$asts[$($i + 1)].Extent.Text" { $asts[$i + 1].Extent.Text | Should Be $a[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Test-Ast
|
||||
{
|
||||
param([string]$src)
|
||||
$a = $args
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$asts = @(Flatten-Ast $ast)
|
||||
Context "Ast Validation: <<$src>>" {
|
||||
It "`$asts.count" { $asts.Count | Should Be $a.Count }
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
It "`$asts[$i].Extent.Text" { $asts[$i].Extent.Text | Should Be $a[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## ErrorStatement is special for SwitchStatement
|
||||
function Test-ErrorStmtForSwitchFlag
|
||||
{
|
||||
param([string]$src, [string]$flagName)
|
||||
$a = $args
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$ast = $ast.EndBlock.Statements[0]
|
||||
Context "Ast Validation: <<$src>>" {
|
||||
$ast | Should BeOfType System.Management.Automation.Language.ErrorStatementAst
|
||||
$ast.Flags.ContainsKey($flagName) | Should be $true
|
||||
|
||||
$asts = @(Flatten-Ast $ast.Flags[$flagName].Item2)
|
||||
|
||||
$asts.Count | Should Be $a.Count
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
$asts[$i].Extent.Text | Should Be $a[$i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Test-ErrorStmt, Test-Ast, ShouldBeParseError, Get-ParseResults, Get-RuntimeError, Test-ErrorStmtForSwitchFlag
|
||||
#
|
||||
# Run the new parser, return either errors or the ast
|
||||
#
|
||||
|
||||
function Get-ParseResults
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$True,Mandatory=$True)]
|
||||
[string]$src,
|
||||
[switch]$Ast
|
||||
)
|
||||
|
||||
$errors = $null
|
||||
$result = [System.Management.Automation.Language.Parser]::ParseInput($src, [ref]$null, [ref]$errors)
|
||||
if ($Ast) { $result } else { ,$errors }
|
||||
}
|
||||
|
||||
#
|
||||
# Run script and return errors
|
||||
#
|
||||
function Get-RuntimeError
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(ValueFromPipeline=$True,Mandatory=$True)][string]$src
|
||||
)
|
||||
|
||||
$errors = $null
|
||||
try
|
||||
{
|
||||
[scriptblock]::Create($src).Invoke() > $null
|
||||
}
|
||||
catch
|
||||
{
|
||||
return $_.Exception.InnerException.ErrorRecord
|
||||
}
|
||||
}
|
||||
|
||||
function position_message
|
||||
{
|
||||
param($position)
|
||||
|
||||
if ($position.Line.Length -lt $position.ColumnNumber)
|
||||
{
|
||||
$position.Line + " <<<<"
|
||||
}
|
||||
else
|
||||
{
|
||||
$position.Line.Insert($position.ColumnNumber, " <<<<")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Pester friendly version of Test-Error
|
||||
#
|
||||
function ShouldBeParseError
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$src,
|
||||
[string[]]$expectedErrors,
|
||||
[int[]]$expectedOffsets,
|
||||
# This is a temporary solution after moving type creation from parse time to runtime
|
||||
[switch]$SkipAndCheckRuntimeError,
|
||||
# for test coverarage purpose, tests validate columnNumber or offset
|
||||
[switch]$CheckColumnNumber,
|
||||
# Skip this test in Travis CI nightly build
|
||||
[switch]$SkipInTravisFullBuild
|
||||
)
|
||||
|
||||
#
|
||||
# CrossGen'ed assemblies cause a hang to happen when running tests with this helper function in Linux and OSX.
|
||||
# The issue has been reported to CoreCLR team. We need to work around it for now with the following approach:
|
||||
# 1. For pull request and push commit, build without '-CrossGen' and run the parsing tests
|
||||
# 2. For nightly build, build with '-CrossGen' but don't run the parsing tests
|
||||
# In this way, we will continue to exercise these parsing tests for each CI build, and skip them for nightly
|
||||
# build to avoid a hang.
|
||||
# Note: this change should be reverted once the 'CrossGen' issue is fixed by CoreCLR. The issue is tracked by
|
||||
# https://github.com/dotnet/coreclr/issues/9745
|
||||
#
|
||||
if ($SkipInTravisFullBuild) {
|
||||
## Report that we skipped the test and return
|
||||
It "Parse error expected: <<$src>>" -Skip {}
|
||||
return
|
||||
}
|
||||
|
||||
Context "Parse error expected: <<$src>>" {
|
||||
# Test case error if this fails
|
||||
$expectedErrors.Count | Should Be $expectedOffsets.Count
|
||||
|
||||
if ($SkipAndCheckRuntimeError)
|
||||
{
|
||||
It "error should happen at parse time, not at runtime" -Skip {}
|
||||
$errors = Get-RuntimeError -Src $src
|
||||
# for runtime errors we will only get the first one
|
||||
$expectedErrors = ,$expectedErrors[0]
|
||||
$expectedOffsets = ,$expectedOffsets[0]
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors = Get-ParseResults -Src $src
|
||||
}
|
||||
|
||||
It "Error count" { $errors.Count | Should Be $expectedErrors.Count }
|
||||
for ($i = 0; $i -lt $errors.Count; ++$i)
|
||||
{
|
||||
$err = $errors[$i]
|
||||
|
||||
if ($SkipAndCheckRuntimeError)
|
||||
{
|
||||
$errorId = $err.FullyQualifiedErrorId
|
||||
}
|
||||
else
|
||||
{
|
||||
$errorId = $err.ErrorId
|
||||
}
|
||||
It "Error Id" { $errorId | Should Be $expectedErrors[$i] }
|
||||
$acutalPostion = $err.Extent.StartScriptPosition.Offset
|
||||
if ( $CheckColumnNumber ) { $acutalPostion = $err.Extent.StartScriptPosition.ColumnNumber }
|
||||
It "Error position" -Pending:$SkipAndCheckRuntimeError { $acutalPostion | Should Be $expectedOffsets[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Flatten-Ast
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param([System.Management.Automation.Language.Ast] $ast)
|
||||
|
||||
$ast
|
||||
$ast | gm -type property | ? { ($prop = $_.Name) -ne 'Parent' } | % {
|
||||
$ast.$prop | ? { $_ -is [System.Management.Automation.Language.Ast] } | % { Flatten-Ast $_ }
|
||||
}
|
||||
}
|
||||
|
||||
function Test-ErrorStmt
|
||||
{
|
||||
param([string]$src, [string]$errorStmtExtent)
|
||||
$a = $args
|
||||
Context "Error Statement expected: <<$src>>" {
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$asts = @(Flatten-Ast $ast.EndBlock.Statements[0])
|
||||
|
||||
It 'Type is ErrorStatementAst' { $asts[0] | Should BeOfType System.Management.Automation.Language.ErrorStatementAst }
|
||||
It "`$asts.count" { $asts.Count | Should Be ($a.Count + 1) }
|
||||
It "`$asts[0].Extent.Text" { $asts[0].Extent.Text | Should Be $errorStmtExtent }
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
It "`$asts[$($i + 1)].Extent.Text" { $asts[$i + 1].Extent.Text | Should Be $a[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Test-Ast
|
||||
{
|
||||
param([string]$src)
|
||||
$a = $args
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$asts = @(Flatten-Ast $ast)
|
||||
Context "Ast Validation: <<$src>>" {
|
||||
It "`$asts.count" { $asts.Count | Should Be $a.Count }
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
It "`$asts[$i].Extent.Text" { $asts[$i].Extent.Text | Should Be $a[$i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
## ErrorStatement is special for SwitchStatement
|
||||
function Test-ErrorStmtForSwitchFlag
|
||||
{
|
||||
param([string]$src, [string]$flagName)
|
||||
$a = $args
|
||||
$ast = Get-ParseResults $src -Ast
|
||||
$ast = $ast.EndBlock.Statements[0]
|
||||
Context "Ast Validation: <<$src>>" {
|
||||
$ast | Should BeOfType System.Management.Automation.Language.ErrorStatementAst
|
||||
$ast.Flags.ContainsKey($flagName) | Should be $true
|
||||
|
||||
$asts = @(Flatten-Ast $ast.Flags[$flagName].Item2)
|
||||
|
||||
$asts.Count | Should Be $a.Count
|
||||
for ($i = 0; $i -lt $a.Count; ++$i)
|
||||
{
|
||||
$asts[$i].Extent.Text | Should Be $a[$i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Test-ErrorStmt, Test-Ast, ShouldBeParseError, Get-ParseResults, Get-RuntimeError, Test-ErrorStmtForSwitchFlag
|
21
test/tools/Modules/HelpersRemoting/HelpersRemoting.psd1
Normal file
21
test/tools/Modules/HelpersRemoting/HelpersRemoting.psd1
Normal file
|
@ -0,0 +1,21 @@
|
|||
#
|
||||
# Module manifest for module 'TestRemoting'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
RootModule = 'HelpersRemoting.psm1'
|
||||
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
GUID = '7acf3c68-64f4-4550-bf14-b9361bfbfea3'
|
||||
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
Description = 'Temporary module for remoting tests'
|
||||
|
||||
FunctionsToExport = 'New-RemoteRunspace', 'New-RemoteSession'
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#
|
||||
# Module manifest for module 'TestHostCS'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'TestHostCS.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '40a19c05-d765-41a1-995e-98ca5f247ee1'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Simple console host for console IO tests.'
|
||||
|
||||
# Functions to export from this module
|
||||
FunctionsToExport = 'New-TestHost'
|
||||
|
||||
# Cmdlets to export from this module
|
||||
#CmdletsToExport = '*'
|
||||
|
||||
# Variables to export from this module
|
||||
#VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module
|
||||
#AliasesToExport = '*'
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#
|
||||
# Module manifest for module 'TestRemoting'
|
||||
#
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'TestRemoting.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.0'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '7acf3c68-64f4-4550-bf14-b9361bfbfea3'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = 'Copyright (C) Microsoft Corporation, All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Temporary module for remoting tests'
|
||||
|
||||
# Functions to export from this module
|
||||
FunctionsToExport = 'New-RemoteRunspace', 'New-RemoteSession'
|
||||
|
||||
# Cmdlets to export from this module
|
||||
#CmdletsToExport = '*'
|
||||
|
||||
# Variables to export from this module
|
||||
#VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module
|
||||
#AliasesToExport = '*'
|
||||
|
||||
}
|
Loading…
Reference in a new issue