Merge branch 'develop' into dev/259-new-variable

This commit is contained in:
Zachary Folwick 2015-10-02 13:48:54 -07:00
commit 2088eaea5a
30 changed files with 689 additions and 269 deletions

3
.gitignore vendored
View file

@ -1,4 +1,6 @@
.idea
.config/
.nuget\\packages\\/
CMakeCache.txt
CMakeFiles/
Makefile
@ -6,3 +8,4 @@ Makefile
cmake_install.cmake
externals
scripts/xunittests.xml
/scripts/powershell.inc

1
docs/Native Tests.md Normal file
View file

@ -0,0 +1 @@
# Native Code Testing Guide

116
docs/Pester Tests.md Normal file
View file

@ -0,0 +1,116 @@
#Pester Testing Test Guide
## Who this is for
Cmdlet behavior is validated using the Pester testing framework. The purpose of this document is to create a single standard to maximize unit test coverage while minimizing confusion on expectations. What follows is a working document intended to guide those writing Pester unit tests for PSL.
Unit testing is done not only to validate that the block of code works as expected, but also to assist the developer to know precisely where in the code to look; in some cases, seeing the source code may inspire better unit tests. In many cases, a unit test *is* the only documented specification. Fortunately, the MSDN is a great source of information about Cmdlets.
Test suites need to be created and many cmdlets added and unit-tested. The following list is to be used to guide the thought process of the developer in writing a suite in minimal time, while enhancing quality.
Test suites should proceed as functional and system tests of the cmdlets, and the code treated as a black box for the purpose of test suite design.
### Use of Mocks
It is often necessary for the code to interact with the system or other components. When possible, use Mock objects to facilitate this in order to minimize external dependencies. Note: creating a Mock in PSL causes PowerShell to look at the Mock, never actually hitting any C# code. Cmdlets cannot be tested using Mocks.
### Aliases
Each cmdlet with an alias must be tested with all of its aliases at least once to verify the code path calls the original function.
## Testing Standards
### Readability
Every effort should be made to maximize readability of code. Code is written for the developer in the future to debug- not for the developer writing the code.
1) When assertions are on consecutive lines, the pipes should line up:
```sh
MyFirstCondition | Should Be 0
MySecondCondition | Should Be 1
```
This is less readable than:
```sh
MyFirstCondition | Should Be 0
MySecondCondition | Should Be 1
```
So the second section of code should instead be used. The same style should be followed for assignments of variables on consecutive lines:
```sh
$var1 = <expression 1>
$variable2 = <expression 2>
$var3 = <expression 3>
$typeCollection1 = <expression 4>
$object1 = <expression>
... etc
```
is much less readable than
```sh
$var1 = <expression 1>
$variable2 = <expression 2>
$var3 = <expression 3>
$typeCollection1 = <expression 4>
$object1 = <expression 5>
... etc
```
So all assignment statements must be aligned.
Other style standards are no less important to readability of the code:
2) Use readable and meaningful variable name when assigning variables.
3) Do not make large functions. Tests should be simple: define -> manipulate -> assert
4) Do not use tabs. Tabs are rendered differently depending upon the machine. This greatly affects readability.
5) Remove the first 3 auto-generated lines of each .Tests.ps1 file. This is created automatically by Pester and is unnecessary. Each .Test.ps1 file should begin with a Describe block.
6) Discard the auto-generated function file that is generated in tandem with the .Tests.ps1 file
7) Name the test file "Test-<cmdlet name > when you create a new test fixture.
8) Each test describes a behavior- use the word "Should" at the beginning of each test description- so it reads "It 'Should..."
### Basic Unit Tests
The following table should suffice to inspire in the developer sufficient content to create a suite of tests.
test # | test name | entry criteria/setup | exit criteria/assertion
-------|-----------|----------------------|------------------------
01 | Should be able to be called | without params (if applicable) | no throw
02 | Should be able to be called | minimal required params | no throw, expected output
03 | Should be able to use the X alias | minimal required params | no throw, expected output
04 | Should return the proper data type | required params | no throw, proper data type
05 | Should be able to accept piped input | piped input | expected output
06 | Should be able to call using the X parameter | use X parameter | no throw, expected output
07 | Should be able to call using the Y parameter | use Y parameter | no throw, expected output
08 | Should be able to call using the Z parameter | use Z parameter | no throw, expected output
09 | Should throw under condition X | create condition X | Throw error x
10 | Should throw under condition Y | create condition Y | Throw error y
11 | Should throw under condition Z | create condition Z | Throw error z
These are the **basic** unit tests required to verify the functionality of any Cmdlet. If the above questions cannot be answered for each Cmdlet, then they cannot be verified to work.
Look at the existing suites of pester tests located within `monad-linux/src/pester-test/` and use that as inspiration.
##Running Pester Tests
Pester tests may be run from outside of PowerShell via the command line. Build PowerShell and Pester using (assuming you're in the build folder) `./build.sh make ../src/pester-test/<filename>` or `./build.sh make pester-tests`

34
docs/Testing.md Normal file
View file

@ -0,0 +1,34 @@
# PowerShell for Linux
This readme is targeted at PowerShell for Linux users looking to write test suites to ensure quality of PowerShell products.
## Getting started
These instructions assume Ubuntu 14.04 LTS. It is assumed that PowerShell for Linux is currently installed on the system.
### Obtain PowerShell
PowerShell is required to enable and run the test suites.
### Testing technology
Technology | Purpose
-------|------
Pester | default cmdlet test framework
xUnit | default C# test framework
cppUnit | default C/C++ testing framework
### Running the test suite
Tests can be run from the `scripts` folder. If you are currently in `monad-linux/scripts`, then run `./build.sh make test` to run the complete tests suite. The table below shows the commands to run for the various test products bundled with Powershell for Linux (the table assumes the current working directory is `monad-linux/scripts`).
It is strongly recommended that before major changes are tested, that users run `./build.sh make clean cleanall prepare` to ensure the environment is completely clean.
Technology | Run Method
------|---------
Pester | ./build.sh make pester-tests
xUnit | ./build.sh make xunit-tests
cppunit | ./build.sh make native-tests
hashbang tests | ./build.sh make hashbang-tests
within the `scripts` directory, you may also wish to run Pester tests on a single file. This can be done easily using `./build.sh make {path/from/scripts/to/pester/test}` (E.g, `./build.sh make ../src/pester-test/Test-TESTFILE.Test.ps1`).

1
docs/xUnit Tests.md Normal file
View file

@ -0,0 +1 @@
#xUnit Testing Guide

View file

@ -92,10 +92,21 @@ MPATH=/usr/lib/mono/4.5/Facades
buildtemp/TypeCatalogGen.exe: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs buildtemp/System.Reflection.Metadata.dll buildtemp/System.Collections.Immutable.dll
$(MCS) -out:$@ -target:exe $(NUGETREF) -pkg:dotnet -r:$(MPATH)/System.Runtime.dll -r:$(MPATH)/System.Reflection.Primitives.dll -r:$(MPATH)/System.IO.dll $<
# this generates the necessary file of CoreCLR references that is an artifact of the Windows build process
# since we don't have Make 4.1, we can't use $(file), and using @echo makes the escaping tricky
# the list of references MUST be line-by-line, to match '^\$\(PS_PROFILE_REF_PATH\)\\(.+);\s*\\$'
REFERENCE_ASSEMBLIES=$(notdir $(shell ls $(TARGETING_PACK)/*.dll))
PROFILE_REFERENCES=$(addsuffix ;\\\n, $(addprefix $$(PS_PROFILE_REF_PATH)\, $(REFERENCE_ASSEMBLIES)))
powershell.inc:
@echo 'PROFILE_REF_PATH=$$(SDK_REF_PATH)\Profiles' > $@
@echo 'PS_PROFILE_REF_PATH=$$(PROFILE_REF_PATH)\PowerShell' >> $@
@echo 'PROFILE_REFERENCES=\\' >> $@
@echo '$(PROFILE_REFERENCES)' >> $@
# generate the Core PS type catalog
# this comes from: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/makefile.inc
CorePsTypeCatalog.cs: powershell-linux.inc buildtemp/TypeCatalogGen.exe buildtemp/System.Reflection.Metadata.dll buildtemp/System.Collections.Immutable.dll
LD_LIBRARY_PATH=. mono buildtemp/TypeCatalogGen.exe powershell-linux.inc $@ $(MONAD_EXT)/coreclr/TargetingPack
CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe buildtemp/System.Reflection.Metadata.dll buildtemp/System.Collections.Immutable.dll
LD_LIBRARY_PATH=. mono buildtemp/TypeCatalogGen.exe $< $@ $(MONAD_EXT)/coreclr/TargetingPack
# the pinvoke library libps.so
@ -221,7 +232,7 @@ clean:
rm -rf exec_env
rm -rf buildtemp/libps-build
rm -rf dotnetlibs/*
rm -f xunittests.xml
rm -f xunittests.xml powershell.inc
# clean built stuff + prepare step
cleanall: clean

28
scripts/build-run.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
CUID=$(id -u)
CUSER=$(id -un)
CGID=$(id -g)
CGROUP=$(id -gn)
DIR=/opt/monad-linux
VOLUME=$(dirname $(pwd))/:$DIR
# creates new user in container matching the local user so that
# artifacts will be owned by the local user; set IMPERSONATE to false
# to disable and run as root, defaults to true
if [[ ! $IMPERSONATE ]]; then IMPERSONATE=true; fi
impersonate()
{
if ! $IMPERSONATE; then return; fi
echo \
groupadd -g $CGID $CGROUP '&&' \
useradd -u $CUID -g $CGID -d $DIR $CUSER '&&' \
sudo --set-home -u $CUSER -g $CGROUP
}
docker run --rm \
--volume $VOLUME \
--workdir $DIR/scripts \
$DOCKERFLAGS \
andschwa/magrathea:latest \
bash -c "$(impersonate) $*"

5
scripts/build-tty.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Runs with a pseudo tty so that interactive shells can be opened
export DOCKERFLAGS="--interactive --tty"
./build-run.sh "$*"

View file

@ -1,9 +1,5 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
# Docker requires the volume path to be absolute... so we resolve it ourselves.
docker run --rm --interactive --tty \
--volume $(dirname $(pwd))/:/opt/monad \
--workdir /opt/monad/scripts \
andschwa/magrathea:latest \
bash -c "/opt/fakelogin; $*"
# we use $* over $@ so that multi-word parameters aren't split up
# Runs by non-interactively, just attaches output
export DOCKERFLAGS="--attach STDOUT --attach STDERR"
./build-run.sh "$*"

View file

@ -54,6 +54,7 @@ COMMANDS_UTILITY_SRCS_WIN=\
../../../jws/pswin/admin/monad/src/commands/utility/WriteProgressCmdlet.cs \
../../../jws/pswin/admin/monad/src/commands/utility/Update-Data.cs \
../../../jws/pswin/admin/monad/src/commands/utility/Update-TypeData.cs \
../../../jws/pswin/admin/monad/src/commands/utility/AddAssembly.cs \
../../../jws/pswin/admin/monad/src/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs \
../../../jws/pswin/admin/monad/src/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs \
../../../jws/pswin/admin/monad/src/commands/utility/FormatAndOutput/format-list/Format-List.cs \
@ -126,6 +127,7 @@ COMMANDS_UTILITY_SRCS=\
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/WriteProgressCmdlet.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/Update-Data.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/Update-TypeData.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/AddAssembly.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/FormatAndOutput/common/GetFormatDataCommand.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/FormatAndOutput/common/WriteFormatDataCommand.cs \
$(ADMIN_GIT_ROOT)/monad/src/commands/utility/FormatAndOutput/format-list/Format-List.cs \
@ -171,6 +173,7 @@ COMMANDS_UTILITY_RESX_SRCS=\
../../../jws/pswin/admin/monad/src/commands/utility/resources/UpdateDataStrings.resx \
../../../jws/pswin/admin/monad/src/commands/utility/resources/ImportLocalizedDataStrings.resx \
../../../jws/pswin/admin/monad/src/commands/utility/resources/WriteProgressResourceStrings.resx \
../../../jws/pswin/admin/monad/src/commands/utility/resources/AddAssemblyStrings.resx \
../../../jws/pswin/admin/monad/src/commands/utility/resources/AliasCommandStrings.resx \
@ -195,6 +198,7 @@ COMMANDS_UTILITY_RES_SRCS=\
gen/COMMANDS_UTILITY/UpdateDataStrings.resources \
gen/COMMANDS_UTILITY/ImportLocalizedDataStrings.resources \
gen/COMMANDS_UTILITY/WriteProgressResourceStrings.resources \
gen/COMMANDS_UTILITY/AddAssemblyStrings.resources \
gen/COMMANDS_UTILITY/AliasCommandStrings.resources \
@ -219,6 +223,7 @@ COMMANDS_UTILITY_RES_CS_SRCS=\
gen/COMMANDS_UTILITY/UpdateDataStrings.cs \
gen/COMMANDS_UTILITY/ImportLocalizedDataStrings.cs \
gen/COMMANDS_UTILITY/WriteProgressResourceStrings.cs \
gen/COMMANDS_UTILITY/AddAssemblyStrings.cs \
gen/COMMANDS_UTILITY/AliasCommandStrings.cs \
@ -243,6 +248,7 @@ COMMANDS_UTILITY_RES_REF=\
-resource:gen/COMMANDS_UTILITY/UpdateDataStrings.resources \
-resource:gen/COMMANDS_UTILITY/ImportLocalizedDataStrings.resources \
-resource:gen/COMMANDS_UTILITY/WriteProgressResourceStrings.resources \
-resource:gen/COMMANDS_UTILITY/AddAssemblyStrings.resources \
-resource:gen/COMMANDS_UTILITY/AliasCommandStrings.resources \

View file

@ -0,0 +1,72 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class AddAssemblyStrings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal AddAssemblyStrings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AddAssemblyStrings", typeof(AddAssemblyStrings).GetTypeInfo().Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Cannot load the assembly because path &apos;{0}&apos; referred to a &apos;{1}&apos; provider path. Change the path to a file system path..
/// </summary>
internal static string SupportFileSystemOnly {
get {
return ResourceManager.GetString("SupportFileSystemOnly", resourceCulture);
}
}
}

Binary file not shown.

View file

@ -196,6 +196,15 @@ internal class FileSystemProviderStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Destination folder &apos;{0}&apos; does not exist..
/// </summary>
internal static string CopyItemDirectoryNotFound {
get {
return ResourceManager.GetString("CopyItemDirectoryNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Destination path {0} is a file that already exists on the target destination..
/// </summary>
@ -206,7 +215,7 @@ internal class FileSystemProviderStrings {
}
/// <summary>
/// Looks up a localized string similar to Cannot copy a directory &apos;{0}&apos; to file {0}&apos;.
/// Looks up a localized string similar to Cannot copy a directory &apos;{0}&apos; to file &apos;{0}&apos;.
/// </summary>
internal static string CopyItemRemotelyDestinationIsFile {
get {

View file

@ -764,6 +764,15 @@ internal class Modules {
}
}
/// <summary>
/// Looks up a localized string similar to The module to process &apos;{0}&apos;, listed in field &apos;{1}&apos; of module manifest &apos;{2}&apos; was not processed. {3}.
/// </summary>
internal static string ManifestMemberNotValid {
get {
return ResourceManager.GetString("ManifestMemberNotValid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The specified MaximumVersion &apos;{0}&apos; was incorrect. If you are using &apos;*&apos;, MaximumVersion only supports one &apos;*&apos; and should always be placed at the end of MaximumVersion..
/// </summary>

View file

@ -342,6 +342,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot create type. Only core types are supported in this language mode..
/// </summary>
internal static string CannotCreateTypeConstrainedLanguage {
get {
return ResourceManager.GetString("CannotCreateTypeConstrainedLanguage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot find an appropriate constructor to instantiate the custom attribute object for type &apos;{0}&apos;..
/// </summary>
@ -676,6 +685,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to PartialConfiguration &apos;{0}&apos; has a Refresh Mode set to Disabled which is not a valid mode for Partial Configurations. Use Pull or Push refresh mode. .
/// </summary>
internal static string DisabledRefreshModeNotValidForPartialConfig {
get {
return ResourceManager.GetString("DisabledRefreshModeNotValidForPartialConfig", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot find an overload for &quot;{0}&quot; and the argument count: &quot;{1}&quot;.
/// </summary>
@ -1289,6 +1307,15 @@ internal class ParserStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The PartialConfiguration &apos;{0}&apos; is set to pull mode which requires a ConfigurationSource property..
/// </summary>
internal static string GetPullModeNeedConfigurationSource {
get {
return ResourceManager.GetString("GetPullModeNeedConfigurationSource", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to There is no Runspace available to get and run the SteppablePipeline in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The script block you attempted to get SteppablePipeline from was: {0}.
/// </summary>

View file

@ -1001,15 +1001,6 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Role Capabilities to apply to this session configuration. This role capability must be defined as a PowerShell Role Capability (.psrc) file named after that role capability within a &apos;RoleCapabilities&apos; directory in a module in the current module path..
/// </summary>
internal static string DISCRoleCapabilitiesToLoadComment {
get {
return ResourceManager.GetString("DISCRoleCapabilitiesToLoadComment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User roles (security groups), and the role capabilities that should be applied to them when applied to a session.
/// </summary>
@ -1028,6 +1019,15 @@ internal class RemotingErrorIdStrings {
}
}
/// <summary>
/// Looks up a localized string similar to Groups associated with machine&apos;s (virtual) administrator account.
/// </summary>
internal static string DISCRunAsVirtualAccountGroupsComment {
get {
return ResourceManager.GetString("DISCRunAsVirtualAccountGroupsComment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Version number of the schema used for this document.
/// </summary>

View file

@ -376,15 +376,6 @@ internal class SessionStateStrings {
}
}
/// <summary>
/// Looks up a localized string similar to The remote path &apos;{0}&apos; is not valid..
/// </summary>
internal static string CopyItemRemotelyPathIsNotValid {
get {
return ResourceManager.GetString("CopyItemRemotelyPathIsNotValid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; parameter cannot be null or empty..
/// </summary>

View file

@ -1,136 +0,0 @@
#
# This file includes OneCore powershell CoreCLR references. Do not import this file directly. It is automatically imported
# when MANAGED_PROFILE=PowerShell is specified in sources file.
#
# This file is also depended on by the tool 'TypeCatalogGen.exe'. The tool tries to parse this file to get the list of reference
# assemblies used by OneCore powershell, and then use that list to generate the CSharp code for initializing the CoreCLR type
# catalog cache. That CSharp code will be compiled into 'Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll' during the build.
# For more information about 'TypeCatalogGen.exe', see its source code under 'PSAssemblyLoadContext\TypeCatalogGen'.
#
# The parsing rule of this file in 'TypeCatalogGen.exe' is very simple:
# - Read each line of this file and trim it;
# - Skip comment lines;
# - Match the line with the regular expression pattern '^\$\(PS_PROFILE_REF_PATH\)\\(.+);\s*\\$'
# So when adding new reference assembly entries, please make sure the new lines match the above pattern.
#
PROFILE_REF_PATH=$(SDK_REF_PATH)\Profiles
PS_PROFILE_REF_PATH=$(PROFILE_REF_PATH)\PowerShell
PROFILE_REFERENCES=\
$(PS_PROFILE_REF_PATH)\Microsoft.CSharp.dll;\
$(PS_PROFILE_REF_PATH)\Microsoft.VisualBasic.dll;\
$(PS_PROFILE_REF_PATH)\Microsoft.Win32.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\Microsoft.Win32.Registry.AccessControl.dll;\
$(PS_PROFILE_REF_PATH)\Microsoft.Win32.Registry.dll;\
$(PS_PROFILE_REF_PATH)\System.AppContext.dll;\
$(PS_PROFILE_REF_PATH)\System.Collections.Concurrent.dll;\
$(PS_PROFILE_REF_PATH)\System.Collections.dll;\
$(PS_PROFILE_REF_PATH)\System.Collections.NonGeneric.dll;\
$(PS_PROFILE_REF_PATH)\System.Collections.Specialized.dll;\
$(PS_PROFILE_REF_PATH)\System.ComponentModel.Annotations.dll;\
$(PS_PROFILE_REF_PATH)\System.ComponentModel.dll;\
$(PS_PROFILE_REF_PATH)\System.ComponentModel.EventBasedAsync.dll;\
$(PS_PROFILE_REF_PATH)\System.ComponentModel.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.ComponentModel.TypeConverter.dll;\
$(PS_PROFILE_REF_PATH)\System.Console.dll;\
$(PS_PROFILE_REF_PATH)\System.Data.Common.dll;\
$(PS_PROFILE_REF_PATH)\System.Data.SqlClient.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Contracts.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Debug.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.FileVersionInfo.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Process.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.TextWriterTraceListener.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Tools.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.TraceSource.dll;\
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Tracing.dll;\
$(PS_PROFILE_REF_PATH)\System.Dynamic.Runtime.dll;\
$(PS_PROFILE_REF_PATH)\System.Globalization.Calendars.dll;\
$(PS_PROFILE_REF_PATH)\System.Globalization.dll;\
$(PS_PROFILE_REF_PATH)\System.Globalization.Extensions.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.Compression.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.Compression.ZipFile.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.AccessControl.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.DriveInfo.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.Watcher.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.MemoryMappedFiles.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.Pipes.dll;\
$(PS_PROFILE_REF_PATH)\System.IO.UnmanagedMemoryStream.dll;\
$(PS_PROFILE_REF_PATH)\System.Linq.dll;\
$(PS_PROFILE_REF_PATH)\System.Linq.Expressions.dll;\
$(PS_PROFILE_REF_PATH)\System.Linq.Parallel.dll;\
$(PS_PROFILE_REF_PATH)\System.Linq.Queryable.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Http.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Http.WinHttpHandler.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.NameResolution.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.NetworkInformation.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Security.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Sockets.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.Utilities.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.WebHeaderCollection.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.WebSockets.Client.dll;\
$(PS_PROFILE_REF_PATH)\System.Net.WebSockets.dll;\
$(PS_PROFILE_REF_PATH)\System.ObjectModel.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.DispatchProxy.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.Emit.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.Emit.ILGeneration.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.Emit.Lightweight.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.Extensions.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.Reflection.TypeExtensions.dll;\
$(PS_PROFILE_REF_PATH)\System.Resources.ReaderWriter.dll;\
$(PS_PROFILE_REF_PATH)\System.Resources.ResourceManager.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.CompilerServices.VisualC.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Extensions.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Handles.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.InteropServices.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.InteropServices.WindowsRuntime.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Loader.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Numerics.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Serialization.Json.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Serialization.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.Runtime.Serialization.Xml.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.AccessControl.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Claims.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.DeriveBytes.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Encoding.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Encryption.Aes.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Encryption.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Hashing.Algorithms.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Hashing.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.RandomNumberGenerator.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.RSA.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.X509Certificates.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Principal.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.Principal.Windows.dll;\
$(PS_PROFILE_REF_PATH)\System.Security.SecureString.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceModel.Duplex.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceModel.Http.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceModel.NetTcp.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceModel.Primitives.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceModel.Security.dll;\
$(PS_PROFILE_REF_PATH)\System.ServiceProcess.ServiceController.dll;\
$(PS_PROFILE_REF_PATH)\System.Text.Encoding.CodePages.dll;\
$(PS_PROFILE_REF_PATH)\System.Text.Encoding.dll;\
$(PS_PROFILE_REF_PATH)\System.Text.Encoding.Extensions.dll;\
$(PS_PROFILE_REF_PATH)\System.Text.RegularExpressions.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.AccessControl.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.Overlapped.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.Tasks.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.Tasks.Parallel.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.Thread.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.ThreadPool.dll;\
$(PS_PROFILE_REF_PATH)\System.Threading.Timer.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.ReaderWriter.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XDocument.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XmlDocument.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XmlSerializer.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XPath.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XPath.XDocument.dll;\
$(PS_PROFILE_REF_PATH)\System.Xml.XPath.XmlDocument.dll;\

View file

@ -1,86 +0,0 @@
#
# This file includes OneCore powershell CoreCLR references. Do not import this file directly. It is automatically imported
# when MANAGED_PROFILE=PowerShell is specified in sources file.
#
# This file is also depended on by the tool 'TypeCatalogGen.exe'. The tool tries to parse this file to get the list of reference
# assemblies used by OneCore powershell, and then use that list to generate the CSharp code for initializing the CoreCLR type
# catalog cache. That CSharp code will be compiled into 'Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll' during the build.
# For more information about 'TypeCatalogGen.exe', see its source code under 'PSAssemblyLoadContext\TypeCatalogGen'.
#
# The parsing rule of this file in 'TypeCatalogGen.exe' is very simple:
# - Read each line of this file and trim it;
# - Skip comment lines;
# - Match the line with the regular expression pattern '^\$\(PS_PROFILE_REF_PATH\)\\(.+);\s*\\$'
# So when adding new reference assembly entries, please make sure the new lines match the above pattern.
#
PROFILE_REF_PATH=$(SDK_REF_PATH)\Profiles
PS_PROFILE_REF_PATH=$(PROFILE_REF_PATH)\PowerShell
PROFILE_REFERENCES=\
$(PS_PROFILE_REF_PATH)\Microsoft.CSharp.metadata_dll; \
$(PS_PROFILE_REF_PATH)\Microsoft.Win32.Registry.metadata_dll; \
$(PS_PROFILE_REF_PATH)\Microsoft.Win32.Primitives.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.collections.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Collections.NonGeneric.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.collections.concurrent.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Collections.Specialized.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.ComponentModel.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.ComponentModel.EventBasedAsync.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.ComponentModel.TypeConverter.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.dynamic.runtime.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.globalization.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.diagnostics.debug.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Diagnostics.FileVersionInfo.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.diagnostics.tools.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Diagnostics.TraceSource.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.diagnostics.contracts.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Diagnostics.Process.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.io.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.IO.Pipes.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.io.filesystem.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.DriveInfo.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.io.filesystem.primitives.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.IO.FileSystem.Watcher.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.linq.expressions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.linq.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.net.primitives.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.reflection.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.reflection.primitives.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.reflection.emit.lightweight.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Reflection.Emit.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.reflection.extensions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Reflection.TypeExtensions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.reflection.emit.ilgeneration.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.resources.resourcemanager.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.runtime.interopservices.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Runtime.Handles.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Runtime.Loader.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.runtime.numerics.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.runtime.serialization.primitives.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Runtime.Serialization.Xml.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.runtime.extensions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Runtime.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.text.encoding.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Text.Encoding.Extensions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.text.regularexpressions.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.tasks.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.tasks.parallel.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.timer.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.thread.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.threading.threadpool.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.xml.readerwriter.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Xml.XmlDocument.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Xml.XmlSerializer.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Xml.XPath.XmlDocument.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Xml.XPath.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Encoding.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.RandomNumberGenerator.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.X509Certificates.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Security.Cryptography.Encryption.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.security.securestring.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.security.principal.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.objectmodel.metadata_dll; \
$(PS_PROFILE_REF_PATH)\system.console.metadata_dll; \
$(PS_PROFILE_REF_PATH)\System.Net.NetworkInformation.metadata_dll;\
$(PS_PROFILE_REF_PATH)\mscorlib.metadata_dll;\

@ -1 +1 @@
Subproject commit 3a92ed01b568e427b613469542f459047a5985f8
Subproject commit a4db8beb6ee35b667351ada3cdc6766fa5407dc7

@ -1 +1 @@
Subproject commit ea31eca6223992fa9729af67518930b6b45829d3
Subproject commit 8b2027617092bc93c4f2977b218145e9b93ec3f3

@ -1 +1 @@
Subproject commit 5693da6a46e8c4d63a49a6dbc6be3081ce7d0d08
Subproject commit d1de7e28c52a87a0804b76445a07b1d122417436

View file

@ -1,26 +1,104 @@
Describe "Test-Get-Content" {
$testString = "This is a test content for a file"
$nl = "`n"
$firstline = "Here's a first line "
$secondline = " here's a second line"
$thirdline = "more text"
$fourthline = "just to make sure"
$fifthline = "there's plenty to work with"
$testString2 = $firstline + $nl + $secondline + $nl + $thirdline + $nl + $fourthline + $nl + $fifthline
$testPath = "/tmp/testfile1"
$testPath2 = "/tmp/testfile2"
BeforeEach {
New-Item -Path $testPath -Force -Value $testString
New-Item -Path $testPath2 -Force -Value $testString2
}
It "Should throw an error on a directory " {
# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
cat . -ErrorAction SilentlyContinue | Should Throw
gc . -ErrorAction SilentlyContinue | Should Throw
type . -ErrorAction SilentlyContinue | Should Throw
}
It "Should deliver an array object when listing a file" {
(Get-Content -Path ./Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(Get-Content -Path ./Test-Get-Content.Tests.ps1)[0] |Should be "Describe `"Test-Get-Content`" `{"
It "Should return an Object when listing only a single line" {
(Get-Content -Path $testPath).GetType().BaseType.Name | Should Be "Object"
}
(gc -Path ./Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(gc -Path ./Test-Get-Content.Tests.ps1)[0] |Should be "Describe `"Test-Get-Content`" `{"
It "Should deliver an array object when listing a file with multiple lines" {
(Get-Content -Path $testPath2).GetType().BaseType.Name | Should Be "Array"
}
(type -Path ./Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(type -Path ./Test-Get-Content.Tests.ps1)[0] |Should be "Describe `"Test-Get-Content`" `{"
It "Should return the correct information from a file" {
(Get-Content -Path $testPath) | Should Be $testString
}
(cat -Path ./Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(cat -Path ./Test-Get-Content.Tests.ps1)[0] |Should be "Describe `"Test-Get-Content`" `{"
It "Should be able to call using the cat alias" {
{ cat -Path $testPath } | Should Not Throw
}
It "Should be able to call using the gc alias" {
{ gc -Path $testPath } | Should Not Throw
}
It "Should be able to call using the type alias" {
{ type -Path $testPath } | Should Not Throw
}
It "Should return the same values for aliases" {
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$catAlias = cat -Path $testPath
$typeAlias = type -Path $testPath
$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $catAlias
$getContentAlias | Should Be $typeAlias
}
It "Should be able to return a specific line from a file" {
(Get-Content -Path $testPath2)[1] | Should be $secondline
}
It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
$returnArray = (cat -Path $testPath2 -TotalCount 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the Head switch" {
$returnArray = (cat -Path $testPath2 -Head 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should be able to specify the number of lines to get the content of using the First switch" {
$returnArray = (cat -Path $testPath2 -First 2)
$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}
It "Should return the last line of a file using the Tail switch" {
Get-Content -Path $testPath -Tail 1 | Should Be $testString
}
It "Should return the last lines of a file using the Last alias" {
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
}
It "Should be able to get content within a different drive" {
pushd env:
$expectedoutput = [Environment]::GetEnvironmentVariable("PATH");
{ Get-Content PATH } | Should Not Throw
Get-Content PATH | Should Be $expectedoutput
popd
}
}

View file

@ -0,0 +1,82 @@
Describe "Test-Get-Random" {
It "Should return a random number greater than -1 " {
Get-Random | Should BeGreaterThan -1
}
It "Should return a random number less than 100 " {
Get-Random -Maximum 100 | Should BeLessThan 100
Get-Random -Maximum 100 | Should BeGreaterThan 0
}
It "Should return a random number less than 100 and greater than -100 " {
$randomNumber = Get-Random -Minimum -100 -Maximum 100
$randomNumber | Should BeLessThan 100
$randomNumber | Should BeGreaterThan -100
}
It "Should return a random number less than 20.93 and greater than 10.7 " {
$randomNumber = Get-Random -Minimum 10.7 -Maximum 20.93
$randomNumber | Should BeLessThan 20.93
$randomNumber | Should BeGreaterThan 10.7
}
It "Should return same number for both Get-Random when switch SetSeed is used " {
$firstRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$secondRandomNumber = Get-Random -Maximum 100 -SetSeed 23
$firstRandomNumber | Should be $secondRandomNumber
}
It "Should return a number from 1,2,3,5,8,13 " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13
$randomNumber | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
}
It "Should return an array " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber.GetType().BaseType | Should Be array
}
It "Should return three random numbers for array of 1,2,3,5,8,13 " {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count 3
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should BeNullOrEmpty
}
It "Should return all the numbers for array of 1,2,3,5,8,13 in no particular order" {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Count ([int]::MaxValue)
$randomNumber[0] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[1] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[2] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[3] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[4] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[5] | Should Be (1 -or 2 -or 3 -or 5 -or 8 -or 13)
$randomNumber[6] | Should BeNullOrEmpty
}
It "Should return for a string collection " {
$randomNumber = Get-Random -InputObject "red", "yellow", "blue"
$randomNumber | Should Be ("red" -or "yellow" -or "blue")
}
It "Should return a number for hexdecimal " {
$randomNumber = Get-Random 0x07FFFFFFFFF
$randomNumber | Should BeLessThan 549755813887
$randomNumber | Should BeGreaterThan 0
}
It "Should return false, check two random numbers are not equal when not using the SetSeed switch " {
$firstRandomNumber = Get-Random
$secondRandomNumber = Get-Random
$firstRandomNumber | Should Not Be $secondRandomNumber
}
It "Should return the same number for hexidemical number and regular number when the switch SetSeed it used " {
$firstRandomNumber = Get-Random 0x07FFFFFFFF -SetSeed 20
$secondRandomNumber = Get-Random 34359738367 -SetSeed 20
$firstRandomNumber | Should Be @secondRandomNumber
}
It "Should throw an error because the hexidecial number is to large " {
{ Get-Random 0x07FFFFFFFFFFFFFFFF } | Should Throw "Value was either too large or too small for a UInt32"
}
}

View file

@ -0,0 +1,173 @@
Describe "Test-Select-String" {
Context "String actions" {
$testinputone = "hello","Hello","goodbye"
$testinputtwo = "hello","Hello"
it "Should be called without errors" {
{ $testinputone | Select-String -Pattern "hello" } | Should Not Throw
}
it "Should be called without error using the sls alias" {
{ $testinputone | sls -Pattern "hello" } | Should Not Throw
}
it "Should return an array data type when multiple matches are found" {
( $testinputtwo | Select-String -Pattern "hello").gettype().basetype | Should Be Array
}
it "Should return the same result for the alias sls and Select-String " {
$firstMatch = $testinputone | Select-String -Pattern "hello"
$secondMatch = $testinputone | sls -Pattern "hello"
$equal = @(compare-object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
it "Should return an object type when one match is found" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().basetype | Should Be System.Object
}
it "Should return matchinfo type" {
( $testinputtwo | Select-String -Pattern "hello" -CaseSensitive).gettype().name | Should Be MatchInfo
}
it "Should be called without an error using ca for casesensitive " {
{$testinputone | Select-String -Pattern "hello" -ca } | Should Not Throw
}
it "Should use the ca alias for casesenstive" {
$firstMatch = $testinputtwo | Select-String -Pattern "hello" -CaseSensitive
$secondMatch = $testinputtwo | Select-String -Pattern "hello" -ca
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
it "Should only return the case sensitive match when the casesensitive switch is used" {
$testinputtwo | Select-String -Pattern "hello" -CaseSensitive | Should Be "hello"
}
it "Should accept a collection of strings from the input object" {
{ Select-String -InputObject "some stuff", "other stuff" -Pattern "other" } | Should Not Throw
}
it "Should return system.object when the input object switch is used on a collection" {
( Select-String -InputObject "some stuff", "other stuff" -pattern "other" ).gettype().basetype | Should Be System.Object
}
it "Should return null or empty when the input object switch is used on a collection and the pattern does not exist" {
Select-String -InputObject "some stuff", "other stuff" -Pattern "neither" | Should BeNullOrEmpty
}
it "Should return a bool type when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive).gettype() | Should Be Bool
}
it "Should be true when select string returns a positive result when the quiet switch is used" {
($testinputtwo | Select-String -Quiet "hello" -CaseSensitive) | Should Be $True
}
it "Should be empty when select string does not return a result when the quiet switch is used" {
$testinputtwo | Select-String -Quiet "goodbye" | Should BeNullOrEmpty
}
it "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" {
$testinputone | Select-String -Pattern "goodbye" -NotMatch | Should Be "hello", "hello"
}
it "Should return the same as NotMatch" {
$firstMatch = $testinputone | Select-String -pattern "goodbye" -NotMatch
$secondMatch = $testinputone | Select-String -pattern "goodbye" -n
$equal = @(Compare-Object $firstMatch $secondMatch).Length -eq 0
$equal | Should Be True
}
}
Context "Filesytem actions" {
$testInputFile = "/tmp/testfile1.txt"
BeforeEach {
New-Item $testInputFile -Itemtype "file" -Force -Value "This is a text string, and another string`nThis is the second line`nThis is the third line`nThis is the fourth line`nNo matches"
}
It "Should return an object when a match is found is the file on only one line" {
(Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object
}
It "Should return an array when a match is found is the file on several lines" {
(Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array
(Select-String $testInputFile -Pattern "in")[0].GetType().Name | Should Be MatchInfo
}
It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" {
$expected = $testInputFile + ":1:This is a text string, and another string"
Select-String $testInputFile -Pattern "string" | Should Be $expected
}
It "Should return all strings where 'second' is found in testfile1 if there is only one lines that has a match" {
$expected = $testInputFile + ":2:This is the second line"
Select-String $testInputFile -Pattern "second"| Should Be $expected
}
It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" {
$expected1 = "This is a text string, and another string"
$expected2 = "This is the second line"
$expected3 = "This is the third line"
$expected4 = "This is the fourth line"
(Select-String in $testInputFile)[0].Line | Should Be $expected1
(Select-String in $testInputFile)[1].Line | Should Be $expected2
(Select-String in $testInputFile)[2].Line | Should Be $expected3
(Select-String in $testInputFile)[3].Line | Should Be $expected4
(Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty
}
It "Should return empty because 'for' is not found in testfile1 " {
Select-String for $testInputFile | Should BeNullOrEmpty
}
It "Should return the third line in testfile1 and the lines above and below it " {
$expectedLine = "testfile1.txt:2:This is the second line"
$expectedLineBefore = "testfile1.txt:3:This is the third line"
$expectedLineAfter = "/tmp/testfile1.txt:4:This is the fourth line"
Select-String third $testInputFile -Context 1 | Should Match $expectedLine
Select-String third $testInputFile -Context 1 | Should Match $expectedLineBefore
Select-String third $testInputFile -Context 1 | Should Match $expectedLineAfter
}
It "Should return the number of matches for 'is' in textfile1 " {
(Select-String is $testInputFile -CaseSensitive).count| Should Be 4
}
It "Should return the third line in testfile1 when a relative path is used" {
$expected = "/tmp/testfile1.txt:3:This is the third line"
Select-String third /tmp/../tmp/testfile1.txt | Should Match $expected
}
It "Should return the fourth line in testfile1 when a relative path is used" {
$testDirectory = "/tmp/"
$expected = "/tmp/testfile1.txt:5:No matches"
pushd $testDirectory
Select-String matches $testDirectory/testfile1.txt | Should Match $expected
popd
}
It "Should return the fourth line in testfile1 when a regular expression is used" {
$expected = "/tmp/testfile1.txt:5:No matches"
Select-String 'matc*' $testInputFile -CaseSensitive | Should Match $expected
}
It "Should return the fourth line in testfile1 when a regular expression is used, using the alias for casesensitive" {
$expected = "/tmp/testfile1.txt:5:No matches"
Select-String 'matc*' $testInputFile -ca | Should Match $expected
}
}
}