Merge branch 'develop' into dev/188-get-content-add-tests

This commit is contained in:
Andrew Schwartzmeyer
2015-10-01 20:30:54 -07:00
56 changed files with 504 additions and 3848 deletions
-37
View File
@@ -1,37 +0,0 @@
cmake_minimum_required(VERSION 2.8.4)
project(linux)
set(CMAKE_CXX_COMPILER /usr/bin/clang++)
# generic settings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
# include folders from PS for Linux
include_directories(${PROJECT_SOURCE_DIR}/stubs)
# add coreclr
# - PLATFORM_UNIX is for pal headers
# - PAL_IMPLEMENTATION is for pal headers to define required function implementations (required for coreclr)
# - __LINUX__ defines the pal headers correctly define stuff for linux
# - COM_NO_WINDOWS_H defines that coreclr headers are not used on windows
# - CORECRL required for PowerShell code to enable CoreCRL support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPLATFORM_UNIX -DPAL_IMPLEMENTATION -D__LINUX__ -DCOM_NO_WINDOWS_H -DCORECLR")
include_directories(${PROJECT_SOURCE_DIR}/../coreclr/src/pal/inc)
#include_directories(${PROJECT_SOURCE_DIR}/../coreclr/src/pal/prebuilt/inc)
# include folders from PS
include_directories(${PROJECT_SOURCE_DIR}/../monad/monad/nttargets/assemblies/nativemsh/pwrshcommon)
set(SOURCE_FILES main.cpp
test/test_pal.cpp
#../monad/monad/nttargets/assemblies/nativemsh/pwrshexe/CssMainEntry.cpp
)
add_executable(linux ${SOURCE_FILES})
# add cppunit
include_directories(${PROJECT_SOURCE_DIR}/../../externals/cppunit/include)
find_library(LIB_CPPUNIT cppunit ${PROJECT_SOURCE_DIR}/../../externals/cppunit/lib)
target_link_libraries(linux ${LIB_CPPUNIT})
message(STATUS "cppunit lib: ${LIB_CPPUNIT}")
-38
View File
@@ -1,38 +0,0 @@
#include <iostream>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
int runTests()
{
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that collects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener(&result);
// Add a listener that prints status update dots while the tests run
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener(&progress);
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
runner.run(controller);
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter(&result,CPPUNIT_NS::stdCOut());
outputter.write();
return result.wasSuccessful() ? 0 : 1;
}
int main(int, char**) {
std::cout << "Hello, World!" << std::endl;
return runTests();
}
-17
View File
@@ -1,17 +0,0 @@
// pal.h will provide everything windows.h otherwise would
#include "pal.h"
#include "rt/palrt.h"
// SAL annotations
#define _In_
#define _Reserved_
#define _Out_
#define _In_opt_
#define __deref_out_opt
#define __deref_out_ecount(COUNT)
#define __inout_ecount(COUNT)
#define __out_ecount(COUNT)
#define _Success_(VALUE)
#define _In_z_
-175
View File
@@ -1,175 +0,0 @@
#pragma once
#include "pal.h"
#include "rt/palrt.h"
//!
//! This header pulls in actual items from the original mscoree.h and also
//! defines stub classes and functions.
//!
typedef /* [public][public] */
enum __MIDL___MIDL_itf_mscoree_0000_0000_0002
{
STARTUP_CONCURRENT_GC = 0x1,
STARTUP_LOADER_OPTIMIZATION_MASK = ( 0x3 << 1 ) ,
STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN = ( 0x1 << 1 ) ,
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN = ( 0x2 << 1 ) ,
STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST = ( 0x3 << 1 ) ,
STARTUP_LOADER_SAFEMODE = 0x10,
STARTUP_LOADER_SETPREFERENCE = 0x100,
STARTUP_SERVER_GC = 0x1000,
STARTUP_HOARD_GC_VM = 0x2000,
STARTUP_SINGLE_VERSION_HOSTING_INTERFACE = 0x4000,
STARTUP_LEGACY_IMPERSONATION = 0x10000,
STARTUP_DISABLE_COMMITTHREADSTACK = 0x20000,
STARTUP_ALWAYSFLOW_IMPERSONATION = 0x40000,
STARTUP_TRIM_GC_COMMIT = 0x80000,
STARTUP_ETW = 0x100000,
STARTUP_ARM = 0x400000,
STARTUP_SINGLE_APPDOMAIN = 0x800000,
STARTUP_APPX_APP_MODEL = 0x1000000,
STARTUP_DISABLE_RANDOMIZED_STRING_HASHING = 0x2000000
} STARTUP_FLAGS;
// other datatypes
typedef HRESULT ( __stdcall *FExecuteInAppDomainCallback )(
void *cookie);
// interfaces
class IUnknown
{
public:
ULONG AddRef()
{
return 0;
}
ULONG Release()
{
return 0;
}
HRESULT QueryInterface(
REFIID riid,
void **ppvObject
)
{
return S_OK;
}
};
struct IActivationFactory
{};
class IHostControl : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetHostManager(
/* [in] */ REFIID riid,
/* [out] */ void **ppObject) = 0;
virtual HRESULT STDMETHODCALLTYPE SetAppDomainManager(
/* [in] */ DWORD dwAppDomainID,
/* [in] */ IUnknown *pUnkAppDomainManager) = 0;
};
class ICLRControl : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetCLRManager(
/* [in] */ REFIID riid,
/* [out] */ void **ppObject) = 0;
virtual HRESULT STDMETHODCALLTYPE SetAppDomainManagerType(
/* [in] */ LPCWSTR pwzAppDomainManagerAssembly,
/* [in] */ LPCWSTR pwzAppDomainManagerType) = 0;
};
class ICLRRuntimeHost : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Start( void) = 0;
virtual HRESULT STDMETHODCALLTYPE Stop( void) = 0;
virtual HRESULT STDMETHODCALLTYPE SetHostControl(
/* [in] */ IHostControl *pHostControl) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCLRControl(
/* [out] */ ICLRControl **pCLRControl) = 0;
virtual HRESULT STDMETHODCALLTYPE UnloadAppDomain(
/* [in] */ DWORD dwAppDomainId,
/* [in] */ BOOL fWaitUntilDone) = 0;
virtual HRESULT STDMETHODCALLTYPE ExecuteInAppDomain(
/* [in] */ DWORD dwAppDomainId,
/* [in] */ FExecuteInAppDomainCallback pCallback,
/* [in] */ void *cookie) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentAppDomainId(
/* [out] */ DWORD *pdwAppDomainId) = 0;
virtual HRESULT STDMETHODCALLTYPE ExecuteApplication(
/* [in] */ LPCWSTR pwzAppFullName,
/* [in] */ DWORD dwManifestPaths,
/* [in] */ LPCWSTR *ppwzManifestPaths,
/* [in] */ DWORD dwActivationData,
/* [in] */ LPCWSTR *ppwzActivationData,
/* [out] */ int *pReturnValue) = 0;
virtual HRESULT STDMETHODCALLTYPE ExecuteInDefaultAppDomain(
/* [in] */ LPCWSTR pwzAssemblyPath,
/* [in] */ LPCWSTR pwzTypeName,
/* [in] */ LPCWSTR pwzMethodName,
/* [in] */ LPCWSTR pwzArgument,
/* [out] */ DWORD *pReturnValue) = 0;
};
class ICLRRuntimeHost2 : public ICLRRuntimeHost
{
public:
virtual HRESULT STDMETHODCALLTYPE CreateAppDomainWithManager(
/* [in] */ LPCWSTR wszFriendlyName,
/* [in] */ DWORD dwFlags,
/* [in] */ LPCWSTR wszAppDomainManagerAssemblyName,
/* [in] */ LPCWSTR wszAppDomainManagerTypeName,
/* [in] */ int nProperties,
/* [in] */ LPCWSTR *pPropertyNames,
/* [in] */ LPCWSTR *pPropertyValues,
/* [out] */ DWORD *pAppDomainID) = 0;
virtual HRESULT STDMETHODCALLTYPE CreateDelegate(
/* [in] */ DWORD appDomainID,
/* [in] */ LPCWSTR wszAssemblyName,
/* [in] */ LPCWSTR wszClassName,
/* [in] */ LPCWSTR wszMethodName,
/* [out] */ INT_PTR *fnPtr) = 0;
virtual HRESULT STDMETHODCALLTYPE Authenticate(
/* [in] */ ULONGLONG authKey) = 0;
virtual HRESULT STDMETHODCALLTYPE RegisterMacEHPort( void) = 0;
virtual HRESULT STDMETHODCALLTYPE SetStartupFlags(
/* [in] */ STARTUP_FLAGS dwFlags) = 0;
virtual HRESULT STDMETHODCALLTYPE DllGetActivationFactory(
/* [in] */ DWORD appDomainID,
/* [in] */ LPCWSTR wszTypeName,
/* [out] */ IActivationFactory **factory) = 0;
virtual HRESULT STDMETHODCALLTYPE ExecuteAssembly(
/* [in] */ DWORD dwAppDomainId,
/* [in] */ LPCWSTR pwzAssemblyPath,
/* [in] */ int argc,
/* [in] */ LPCWSTR *argv,
/* [out] */ DWORD *pReturnValue) = 0;
};
View File
View File
-10
View File
@@ -1,10 +0,0 @@
#pragma once
#include "pal.h"
DWORD WINAPI ExpandEnvironmentStringsW(
PCWSTR lpSrc,
PWSTR lpDst,
DWORD nSize
);
-89
View File
@@ -1,89 +0,0 @@
#include "pal.h"
#include "test_pal.h"
// pull in some more headers
#include "NativeMshConstants.h"
#include "ClrHostWrapper.h"
#include "IPwrshCommonOutput.h"
#include "ConfigFileReader.h"
#include "NativeMsh.h"
#include "SystemCallFacade.h"
#include "WinSystemCallFacade.h"
namespace Microsoft {
CPPUNIT_TEST_SUITE_REGISTRATION(PalTestSuite);
// this unit test is used to test if stuff from different headers was pulled in correctly
// this is for porting compatbility tests, not really functional tests
void PalTestSuite::testHeaders() {
// check NativeMshConstants.h
CPPUNIT_ASSERT_EQUAL(NativeMsh::g_MISSING_COMMAND_LINE_ARGUMENT,1);
// check ClrHostWrapper.h
NativeMsh::ICLRRuntimeHost2Wrapper clrHostWrapper;
}
void PalTestSuite::testDatatypes() {
// check basic pointer lengths
CPPUNIT_ASSERT_EQUAL(sizeof(void*), sizeof(PVOID));
// windows datatypes
CPPUNIT_ASSERT_EQUAL(sizeof(WORD),(std::size_t)2);
CPPUNIT_ASSERT_EQUAL(sizeof(DWORD),(std::size_t)4);
CPPUNIT_ASSERT_EQUAL(sizeof(HANDLE),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HWND),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HMODULE),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HINSTANCE),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HGLOBAL),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HLOCAL),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HRSRC),sizeof(void*));
CPPUNIT_ASSERT_EQUAL(sizeof(HRESULT),sizeof(LONG));
CPPUNIT_ASSERT_EQUAL(sizeof(NTSTATUS),sizeof(LONG));
// windows integer datatypes
CPPUNIT_ASSERT_EQUAL(sizeof(INT),(std::size_t)4);
CPPUNIT_ASSERT_EQUAL(sizeof(INT8),(std::size_t)1);
CPPUNIT_ASSERT_EQUAL(sizeof(INT16),(std::size_t)2);
CPPUNIT_ASSERT_EQUAL(sizeof(INT32),(std::size_t)4);
CPPUNIT_ASSERT_EQUAL(sizeof(INT64),(std::size_t)8);
CPPUNIT_ASSERT_EQUAL(sizeof(UINT),(std::size_t)4);
CPPUNIT_ASSERT_EQUAL(sizeof(UINT8),(std::size_t)1);
CPPUNIT_ASSERT_EQUAL(sizeof(UINT16),(std::size_t)2);
CPPUNIT_ASSERT_EQUAL(sizeof(UINT32),(std::size_t)4);
CPPUNIT_ASSERT_EQUAL(sizeof(UINT64),(std::size_t)8);
// windows integer max and min size constants
CPPUNIT_ASSERT_EQUAL(CHAR_BIT,8);
CPPUNIT_ASSERT_EQUAL(SCHAR_MIN,-127-1);
CPPUNIT_ASSERT_EQUAL(SCHAR_MAX,127);
CPPUNIT_ASSERT_EQUAL(UCHAR_MAX,0xff);
CPPUNIT_ASSERT_EQUAL(SHRT_MIN,-32767-1);
CPPUNIT_ASSERT_EQUAL(SHRT_MAX,32767);
CPPUNIT_ASSERT_EQUAL(USHRT_MAX,0xffff);
CPPUNIT_ASSERT_EQUAL(INT_MIN,-2147483647-1);
CPPUNIT_ASSERT_EQUAL(INT_MAX,2147483647);
CPPUNIT_ASSERT_EQUAL(UINT_MAX,0xffffffff);
// TODO: these are part of limits.h and will never fit windows values
// CPPUNIT_ASSERT_EQUAL(LONG_MIN,-2147483647L-1);
// CPPUNIT_ASSERT_EQUAL(LONG_MAX,2147483647L);
// CPPUNIT_ASSERT_EQUAL(ULONG_MAX,0xffffffffUL);
CPPUNIT_ASSERT_EQUAL(MAXSHORT,0x7fff);
CPPUNIT_ASSERT_EQUAL(MAXLONG,0x7fffffff);
CPPUNIT_ASSERT_EQUAL(MAXCHAR,0x7f);
CPPUNIT_ASSERT_EQUAL(MAXDWORD,0xffffffff);
// character data types
CPPUNIT_ASSERT_EQUAL(sizeof(CHAR),(std::size_t)1);
CPPUNIT_ASSERT_EQUAL(sizeof(TCHAR),(std::size_t)1);
}
}
-17
View File
@@ -1,17 +0,0 @@
#include <cppunit/extensions/HelperMacros.h>
namespace Microsoft {
class PalTestSuite : public CPPUNIT_NS::TestFixture {
CPPUNIT_TEST_SUITE(PalTestSuite);
CPPUNIT_TEST(testHeaders);
CPPUNIT_TEST(testDatatypes);
CPPUNIT_TEST_SUITE_END();
public:
void testHeaders();
void testDatatypes();
};
}
@@ -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"
}
}
@@ -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
}
}
}