diff --git a/.gitignore b/.gitignore index 7d710e83e..1bebec4e5 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/scripts/Makefile b/scripts/Makefile index 30125c6bb..5a07abe9d 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -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 diff --git a/scripts/build-run.sh b/scripts/build-run.sh new file mode 100755 index 000000000..625dc12c3 --- /dev/null +++ b/scripts/build-run.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +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) $*" diff --git a/scripts/build-tty.sh b/scripts/build-tty.sh new file mode 100755 index 000000000..d6dfcbea6 --- /dev/null +++ b/scripts/build-tty.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +# Runs with a pseudo tty so that interactive shells can be opened +export DOCKERFLAGS="--interactive --tty" +./build-run.sh "$*" diff --git a/scripts/build.sh b/scripts/build.sh index 72b1f2272..abf252cc2 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,9 +1,5 @@ #!/usr/bin/env sh -# 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 "$*" diff --git a/scripts/commands-utility.mk b/scripts/commands-utility.mk index 9b0ffc20f..1ddd09eeb 100644 --- a/scripts/commands-utility.mk +++ b/scripts/commands-utility.mk @@ -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 \ diff --git a/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.cs b/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.cs new file mode 100755 index 000000000..22b8cb136 --- /dev/null +++ b/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + + + +/// +/// A strongly-typed resource class, for looking up localized strings, etc. +/// +// 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() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [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; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Cannot load the assembly because path '{0}' referred to a '{1}' provider path. Change the path to a file system path.. + /// + internal static string SupportFileSystemOnly { + get { + return ResourceManager.GetString("SupportFileSystemOnly", resourceCulture); + } + } +} diff --git a/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.resources b/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.resources new file mode 100755 index 000000000..7716dbae2 Binary files /dev/null and b/scripts/gen/COMMANDS_UTILITY/AddAssemblyStrings.resources differ diff --git a/scripts/gen/SYS_AUTO/FileSystemProviderStrings.cs b/scripts/gen/SYS_AUTO/FileSystemProviderStrings.cs index 4572fb948..0fc7314b6 100644 --- a/scripts/gen/SYS_AUTO/FileSystemProviderStrings.cs +++ b/scripts/gen/SYS_AUTO/FileSystemProviderStrings.cs @@ -196,6 +196,15 @@ internal class FileSystemProviderStrings { } } + /// + /// Looks up a localized string similar to Destination folder '{0}' does not exist.. + /// + internal static string CopyItemDirectoryNotFound { + get { + return ResourceManager.GetString("CopyItemDirectoryNotFound", resourceCulture); + } + } + /// /// Looks up a localized string similar to Destination path {0} is a file that already exists on the target destination.. /// @@ -206,7 +215,7 @@ internal class FileSystemProviderStrings { } /// - /// Looks up a localized string similar to Cannot copy a directory '{0}' to file {0}'. + /// Looks up a localized string similar to Cannot copy a directory '{0}' to file '{0}'. /// internal static string CopyItemRemotelyDestinationIsFile { get { diff --git a/scripts/gen/SYS_AUTO/FileSystemProviderStrings.resources b/scripts/gen/SYS_AUTO/FileSystemProviderStrings.resources index 4c9458ea8..0a31ab34a 100644 Binary files a/scripts/gen/SYS_AUTO/FileSystemProviderStrings.resources and b/scripts/gen/SYS_AUTO/FileSystemProviderStrings.resources differ diff --git a/scripts/gen/SYS_AUTO/Modules.cs b/scripts/gen/SYS_AUTO/Modules.cs index 1698dd5e6..89a618ff2 100644 --- a/scripts/gen/SYS_AUTO/Modules.cs +++ b/scripts/gen/SYS_AUTO/Modules.cs @@ -764,6 +764,15 @@ internal class Modules { } } + /// + /// Looks up a localized string similar to The module to process '{0}', listed in field '{1}' of module manifest '{2}' was not processed. {3}. + /// + internal static string ManifestMemberNotValid { + get { + return ResourceManager.GetString("ManifestMemberNotValid", resourceCulture); + } + } + /// /// Looks up a localized string similar to The specified MaximumVersion '{0}' was incorrect. If you are using '*', MaximumVersion only supports one '*' and should always be placed at the end of MaximumVersion.. /// diff --git a/scripts/gen/SYS_AUTO/Modules.resources b/scripts/gen/SYS_AUTO/Modules.resources index e21385a99..496f83d23 100644 Binary files a/scripts/gen/SYS_AUTO/Modules.resources and b/scripts/gen/SYS_AUTO/Modules.resources differ diff --git a/scripts/gen/SYS_AUTO/ParserStrings.cs b/scripts/gen/SYS_AUTO/ParserStrings.cs index 82d51f4f3..4873d9a3b 100644 --- a/scripts/gen/SYS_AUTO/ParserStrings.cs +++ b/scripts/gen/SYS_AUTO/ParserStrings.cs @@ -342,6 +342,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to Cannot create type. Only core types are supported in this language mode.. + /// + internal static string CannotCreateTypeConstrainedLanguage { + get { + return ResourceManager.GetString("CannotCreateTypeConstrainedLanguage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot find an appropriate constructor to instantiate the custom attribute object for type '{0}'.. /// @@ -676,6 +685,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to PartialConfiguration '{0}' has a Refresh Mode set to Disabled which is not a valid mode for Partial Configurations. Use Pull or Push refresh mode. . + /// + internal static string DisabledRefreshModeNotValidForPartialConfig { + get { + return ResourceManager.GetString("DisabledRefreshModeNotValidForPartialConfig", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cannot find an overload for "{0}" and the argument count: "{1}". /// @@ -1289,6 +1307,15 @@ internal class ParserStrings { } } + /// + /// Looks up a localized string similar to The PartialConfiguration '{0}' is set to pull mode which requires a ConfigurationSource property.. + /// + internal static string GetPullModeNeedConfigurationSource { + get { + return ResourceManager.GetString("GetPullModeNeedConfigurationSource", resourceCulture); + } + } + /// /// 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}. /// diff --git a/scripts/gen/SYS_AUTO/ParserStrings.resources b/scripts/gen/SYS_AUTO/ParserStrings.resources index c84df64b1..116a84359 100644 Binary files a/scripts/gen/SYS_AUTO/ParserStrings.resources and b/scripts/gen/SYS_AUTO/ParserStrings.resources differ diff --git a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs index 1bb3258f9..381664387 100644 --- a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs +++ b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.cs @@ -1001,15 +1001,6 @@ internal class RemotingErrorIdStrings { } } - /// - /// 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 'RoleCapabilities' directory in a module in the current module path.. - /// - internal static string DISCRoleCapabilitiesToLoadComment { - get { - return ResourceManager.GetString("DISCRoleCapabilitiesToLoadComment", resourceCulture); - } - } - /// /// 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. /// @@ -1028,6 +1019,15 @@ internal class RemotingErrorIdStrings { } } + /// + /// Looks up a localized string similar to Groups associated with machine's (virtual) administrator account. + /// + internal static string DISCRunAsVirtualAccountGroupsComment { + get { + return ResourceManager.GetString("DISCRunAsVirtualAccountGroupsComment", resourceCulture); + } + } + /// /// Looks up a localized string similar to Version number of the schema used for this document. /// diff --git a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources index de3571e7f..bff6014c3 100644 Binary files a/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources and b/scripts/gen/SYS_AUTO/RemotingErrorIdStrings.resources differ diff --git a/scripts/gen/SYS_AUTO/SessionStateStrings.cs b/scripts/gen/SYS_AUTO/SessionStateStrings.cs index effe05b52..19d2bbafa 100644 --- a/scripts/gen/SYS_AUTO/SessionStateStrings.cs +++ b/scripts/gen/SYS_AUTO/SessionStateStrings.cs @@ -376,15 +376,6 @@ internal class SessionStateStrings { } } - /// - /// Looks up a localized string similar to The remote path '{0}' is not valid.. - /// - internal static string CopyItemRemotelyPathIsNotValid { - get { - return ResourceManager.GetString("CopyItemRemotelyPathIsNotValid", resourceCulture); - } - } - /// /// Looks up a localized string similar to '{0}' parameter cannot be null or empty.. /// diff --git a/scripts/gen/SYS_AUTO/SessionStateStrings.resources b/scripts/gen/SYS_AUTO/SessionStateStrings.resources index 3ae06c1d4..eb1db39f5 100644 Binary files a/scripts/gen/SYS_AUTO/SessionStateStrings.resources and b/scripts/gen/SYS_AUTO/SessionStateStrings.resources differ diff --git a/scripts/powershell-linux.inc b/scripts/powershell-linux.inc deleted file mode 100644 index 49f140467..000000000 --- a/scripts/powershell-linux.inc +++ /dev/null @@ -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;\ diff --git a/scripts/powershell.inc b/scripts/powershell.inc deleted file mode 100644 index 094806d3f..000000000 --- a/scripts/powershell.inc +++ /dev/null @@ -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;\ diff --git a/src/monad b/src/monad index 3a92ed01b..a4db8beb6 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 3a92ed01b568e427b613469542f459047a5985f8 +Subproject commit a4db8beb6ee35b667351ada3cdc6766fa5407dc7 diff --git a/src/monad-ext b/src/monad-ext index ea31eca62..8b2027617 160000 --- a/src/monad-ext +++ b/src/monad-ext @@ -1 +1 @@ -Subproject commit ea31eca6223992fa9729af67518930b6b45829d3 +Subproject commit 8b2027617092bc93c4f2977b218145e9b93ec3f3 diff --git a/src/monad-native b/src/monad-native index 5693da6a4..d1de7e28c 160000 --- a/src/monad-native +++ b/src/monad-native @@ -1 +1 @@ -Subproject commit 5693da6a46e8c4d63a49a6dbc6be3081ce7d0d08 +Subproject commit d1de7e28c52a87a0804b76445a07b1d122417436 diff --git a/src/pester-tests/Test-Get-Content.Tests.ps1 b/src/pester-tests/Test-Get-Content.Tests.ps1 index 244377003..3bcdcab93 100644 --- a/src/pester-tests/Test-Get-Content.Tests.ps1 +++ b/src/pester-tests/Test-Get-Content.Tests.ps1 @@ -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 } } diff --git a/src/pester-tests/Test-Get-Random.Tests.ps1 b/src/pester-tests/Test-Get-Random.Tests.ps1 new file mode 100644 index 000000000..004e2dcbf --- /dev/null +++ b/src/pester-tests/Test-Get-Random.Tests.ps1 @@ -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" + } +} diff --git a/src/pester-tests/Test-Select-String.Tests.ps1 b/src/pester-tests/Test-Select-String.Tests.ps1 new file mode 100644 index 000000000..54a21ac72 --- /dev/null +++ b/src/pester-tests/Test-Select-String.Tests.ps1 @@ -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 + } + } +}