mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Merge branch 'develop' into dev/208-select-string-pester
This commit is contained in:
commit
e31b3b5f3b
67 files changed
+805
-3953
No files matched your search
@@ -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}")
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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_
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "pal.h"
|
||||
|
||||
DWORD WINAPI ExpandEnvironmentStringsW(
|
||||
PCWSTR lpSrc,
|
||||
PWSTR lpDst,
|
||||
DWORD nSize
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
+1
-1
Submodule src/monad updated: 9aecfb12f6...a4db8beb6e.
+1
-1
Submodule src/monad-ext updated: ea31eca622...8b20276170.
+1
-1
Submodule src/monad-native updated: 5693da6a46...d1de7e28c5.
@@ -0,0 +1,99 @@
|
||||
function Clean-State
|
||||
{
|
||||
if (Test-Path $FullyQualifiedFile)
|
||||
{
|
||||
Remove-Item $FullyQualifiedFile -Force
|
||||
}
|
||||
|
||||
if (Test-Path $FullyQualifiedFolder)
|
||||
{
|
||||
Remove-Item $FullyQualifiedFolder -Recurse -Force
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Test-New-Item" {
|
||||
$tmpDirectory = "/tmp"
|
||||
$testfile = "testfile.txt"
|
||||
$testfolder = "newDirectory"
|
||||
$FullyQualifiedFile = $tmpDirectory + "/" + $testfile
|
||||
$FullyQualifiedFolder = $tmpDirectory + "/" + $testfolder
|
||||
|
||||
BeforeEach {
|
||||
Clean-State
|
||||
}
|
||||
|
||||
It "should call the function without error" {
|
||||
{ New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should create a file without error" {
|
||||
New-Item -Name $testfile -Path $tmpDirectory -ItemType file
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
}
|
||||
|
||||
It "Should create a folder without an error" {
|
||||
New-Item -Name newDirectory -Path $tmpDirectory -ItemType directory
|
||||
|
||||
Test-Path $FullyQualifiedFolder | Should Be $true
|
||||
}
|
||||
|
||||
It "Should create a file using the ni alias" {
|
||||
ni -Name $testfile -Path $tmpDirectory -ItemType file
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
}
|
||||
|
||||
It "Should create a file using the Type alias instead of ItemType" {
|
||||
New-Item -Name $testfile -Path $tmpDirectory -Type file
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
}
|
||||
|
||||
It "Should create a file with sample text inside the file using the Value switch" {
|
||||
$expected = "This is test string"
|
||||
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Value $expected
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
|
||||
Get-Content $FullyQualifiedFile | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should not create a file when the Name switch is not used and only a directory specified" {
|
||||
#errorAction used because permissions issue in windows
|
||||
New-Item -Path $tmpDirectory -ItemType file -ErrorAction SilentlyContinue
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $false
|
||||
|
||||
}
|
||||
|
||||
It "Should create a file when the Name switch is not used but a fully qualified path is specified" {
|
||||
New-Item -Path $FullyQualifiedFile -ItemType file
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to create a multiple items in different directories" {
|
||||
$FullyQualifiedFile2 = $tmpDirectory + "/" + "test2.txt"
|
||||
New-Item -ItemType file -Path $FullyQualifiedFile, $FullyQualifiedFile2
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $true
|
||||
Test-Path $FullyQualifiedFile2 | Should Be $true
|
||||
|
||||
Remove-Item $FullyQualifiedFile2
|
||||
}
|
||||
|
||||
It "Should be able to call the whatif switch without error" {
|
||||
{ New-Item -Name testfile.txt -Path /tmp -ItemType file -WhatIf } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not create a new file when the whatif switch is used" {
|
||||
New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf
|
||||
|
||||
Test-Path $FullyQualifiedFile | Should Be $false
|
||||
}
|
||||
|
||||
It "Should produce an error when the credentials switch is thrown" {
|
||||
{ New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Credential domain/USER } | Should Throw "not implemented"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
Describe "Test-Out-File" {
|
||||
$expectedContent = "some test text"
|
||||
$inputObject = New-Object psobject -Property @{text=$expectedContent}
|
||||
$testfile = "/tmp/outfileTest.txt"
|
||||
|
||||
AfterEach {
|
||||
Remove-Item -Path $testfile -Force
|
||||
}
|
||||
|
||||
It "Should be able to be called without error" {
|
||||
{ Out-File -FilePath $testfile } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to accept string input via piping" {
|
||||
{ $expectedContent | Out-File -FilePath $testfile } | Should Not Throw
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual | Should Be $expectedContent
|
||||
}
|
||||
|
||||
It "Should be able to accept string input via the InputObject swictch" {
|
||||
{ Out-File -FilePath $testfile -InputObject $expectedContent } | Should Not Throw
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual | Should Be $expectedContent
|
||||
}
|
||||
|
||||
It "Should be able to accept object input" {
|
||||
{ $inputObject | Out-File -FilePath $testfile } | Should Not Throw
|
||||
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should not overwrite when the noclobber switch is used" {
|
||||
|
||||
Out-File -FilePath $testfile -InputObject $inputObject
|
||||
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject -NoClobber -ErrorAction SilentlyContinue } | Should Throw "already exists."
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject -NoOverWrite -ErrorAction SilentlyContinue } | Should Throw "already exists."
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual[0] | Should Be ""
|
||||
$actual[1] | Should Match "text"
|
||||
$actual[2] | Should Match "----"
|
||||
$actual[3] | Should Match "some test text"
|
||||
}
|
||||
|
||||
It "Should Append a new line when the append switch is used" {
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject -Append } | Should Not Throw
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual[0] | Should Be ""
|
||||
$actual[1] | Should Match "text"
|
||||
$actual[2] | Should Match "----"
|
||||
$actual[3] | Should Match "some test text"
|
||||
$actual[4] | Should Be ""
|
||||
$actual[5] | Should Be ""
|
||||
$actual[6] | Should Be ""
|
||||
$actual[7] | Should Match "text"
|
||||
$actual[8] | Should Match "----"
|
||||
$actual[9] | Should Match "some test text"
|
||||
$actual[10] | Should Be ""
|
||||
$actual[11] | Should Be ""
|
||||
|
||||
}
|
||||
|
||||
It "Should limit each line to the specified number of characters when the width switch is used on objects" {
|
||||
|
||||
Out-File -FilePath $testfile -Width 10 -InputObject $inputObject
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual[0] | Should Be ""
|
||||
$actual[1] | Should Be "text "
|
||||
$actual[2] | Should Be "---- "
|
||||
$actual[3] | Should Be "some te..."
|
||||
|
||||
}
|
||||
|
||||
It "Should allow the cmdlet to overwrite an existing read-only file" {
|
||||
# create a read-only text file
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject } | Should Not Throw
|
||||
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $true
|
||||
|
||||
# write information to the RO file
|
||||
{ Out-File -FilePath $testfile -InputObject $inputObject -Append -Force } | Should Not Throw
|
||||
|
||||
$actual = Get-Content $testfile
|
||||
|
||||
$actual[0] | Should Be ""
|
||||
$actual[1] | Should Match "text"
|
||||
$actual[2] | Should Match "----"
|
||||
$actual[3] | Should Match "some test text"
|
||||
$actual[4] | Should Be ""
|
||||
$actual[5] | Should Be ""
|
||||
$actual[6] | Should Be ""
|
||||
$actual[7] | Should Match "text"
|
||||
$actual[8] | Should Match "----"
|
||||
$actual[9] | Should Match "some test text"
|
||||
$actual[10] | Should Be ""
|
||||
$actual[11] | Should Be ""
|
||||
|
||||
# reset to not read only so it can be deleted
|
||||
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
Describe "Test-Test-Path" {
|
||||
$testdirectory = "/usr/bin"
|
||||
$testfilename = "vi" # use /usr/bin/vi since that's bundled with all linux
|
||||
$testfile = $testdirectory + "/" + $testfilename
|
||||
It "Should be called on an existing path without error" {
|
||||
{ Test-Path $testdirectory } | Should Not Throw
|
||||
{ Test-Path -Path $testdirectory } | Should Not Throw
|
||||
{ Test-Path -LiteralPath $testdirectory } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should allow piping objects to it" {
|
||||
{ $testdirectory | Test-Path } | Should Not Throw
|
||||
|
||||
$testdirectory | Test-Path | Should Be $true
|
||||
"/usr/bin/totallyFakeDirectory" | Test-Path | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return a boolean data type" {
|
||||
{ Test-Path -Path $testdirectory } | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be called on a nonexistant path without error" {
|
||||
{ Test-Path -Path "aNonexistant/path/that/should/error" } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should return false for a nonexistant path" {
|
||||
Test-Path -Path "aNonexistant/path/that/should/error" | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true for an existing path" {
|
||||
Test-Path -Path $testdirectory | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to accept a regular expression" {
|
||||
{ Test-Path -Path "/u*" } | Should Not Throw
|
||||
{ Test-Path -Path "/u[a-z]r" } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to return the correct result when a regular expression is used" {
|
||||
Test-Path -Path "/u*" | Should Be $true
|
||||
Test-Path -Path "/u[a-z]*" | Should Be $true
|
||||
|
||||
Test-Path -Path "/aoeu*" | Should Be $false
|
||||
Test-Path -Path "/u[A-Z]" | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return false when the Leaf pathtype is used on a directory" {
|
||||
Test-Path -Path $testdirectory -PathType Leaf | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true when the Leaf pathtype is used on an existing endpoint" {
|
||||
Test-Path -Path $testfile -PathType Leaf | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return false when the Leaf pathtype is used on a nonexistant file" {
|
||||
Test-Path -Path "aoeu" -PathType Leaf | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true when the Leaf pathtype is used on a file using the Type alias instead of PathType" {
|
||||
Test-Path -Path $testfile -Type Leaf | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to search multiple regular expressions using the include switch" {
|
||||
Test-Path -Path "/usr/bin/*" -Include vi* | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to exclude a regular expression using the exclude switch" {
|
||||
Test-Path -Path "/usr/bin/" -Exclude vi* | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to exclude multiple regular expressions using the exclude switch" {
|
||||
# tests whether there's any files in the /usr directory that don't start with 'd' or 'g'
|
||||
Test-Path -Path "/usr" -Exclude d*, g* | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return true if the syntax of the path is correct when using the IsValid switch" {
|
||||
Test-Path -Path /this/is/a/valid/path -IsValid | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return false if the syntax of the path is incorrect when using the IsValid switch" {
|
||||
Test-Path -Path C:/usr/bin -IsValid | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true on paths containing spaces when the path is surrounded in quotes" {
|
||||
Test-Path -Path "/totally a valid/path" -IsValid | Should Be $true
|
||||
}
|
||||
|
||||
It "Should throw on paths containing spaces when the path is not surrounded in quotes" {
|
||||
{ Test-Path -Path /a path/without quotes/around/it -IsValid } | Should Throw
|
||||
}
|
||||
|
||||
It "Should return true if a directory leads or trails with a space when surrounded by quotes" {
|
||||
Test-Path -Path "/a path / with/funkyspaces" -IsValid | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return true on a valid path when the LiteralPath switch is used" {
|
||||
Test-Path -LiteralPath "/usr/bin" | Should Be $true
|
||||
}
|
||||
|
||||
It "Should return false if regular expressions are used with the LiteralPath switch" {
|
||||
Test-Path -LiteralPath /*sr/bin | Should Be $false
|
||||
Test-Path -LiteralPath /[usth]sr/bin | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return false if regular expressions are used with the LiteralPath alias PSPath switch" {
|
||||
Test-Path -PSPath /*sr/bin | Should Be $false
|
||||
Test-Path -PSPath /[aoeu]sr/bin | Should Be $false
|
||||
}
|
||||
|
||||
It "Should return true if used on components other than filesystem objects" {
|
||||
Test-Path Alias:\gci | Should Be $true
|
||||
Test-Path Env:\HOSTNAME | Should Be $true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user