Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "PowerShell",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/powershell:lts-ubuntu-22.04",

"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/sshd:1": {},
Expand All @@ -20,10 +20,10 @@
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"settings": {
"terminal.integrated.defaultProfile.linux": "pwsh"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.powershell",
Expand Down
6 changes: 3 additions & 3 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function Test_AddIncludeToWorkspace {
# Arrange - Setup test data and mocks
Import-Module -Name TestingHelper
New-ModuleV3 -Name TestModule

# Act - Execute the function being tested
Add-IncludeToWorkspace -Name "getHashCode.ps1" -FolderName "Include" -DestinationModulePath "TestModule"

# Assert - Verify results
Assert-ItemExist -path (Join-Path $folderPath "getHashCode.ps1")
}
Expand All @@ -81,4 +81,4 @@ function Test_AddIncludeToWorkspace {
- `./test.ps1` - Run all unit tests
- `./sync.ps1` - Sync includes to workspace/module
- `./deploy.ps1` - Deploy module
- `./release.ps1` - Release module version
- `./release.ps1` - Release module version
4 changes: 1 addition & 3 deletions .github/copilot-pull-request-description-instructions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pull Request Code Instructions

## PR TITLE
## PR TITLE

Follow this guidelines to construct the title of your pull request.

Expand Down Expand Up @@ -39,5 +39,3 @@ References:

- Add a summery of the intention of the PR. Use the title and the messages of the commits to create a summary.
- Add a list with all the commit messages in the PR.


2 changes: 1 addition & 1 deletion .github/workflows/deploy_module_on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
EVENT_REF: ${{ github.event.ref }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_NAME: ${{ github.event.release.name }}
run: |
run: |
$env:EVENT_REF = $env:REF

If ([string]::IsNullOrEmpty($env:EVENT_REF)) {
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name: PSScriptAnalyzer
on:
workflow_dispatch:
pull_request:

permissions:
contents: read

Expand All @@ -21,7 +21,7 @@ jobs:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: PSScriptAnalyzer
runs-on: ubuntu-latest
steps:
Expand All @@ -33,12 +33,12 @@ jobs:
# Check https://github.com/microsoft/action-psscriptanalyzer for more info about the options.
# The below set up runs PSScriptAnalyzer to your entire repository and runs some basic security rules.
path: .\
recurse: true
recurse: true
severity: 'Error'
# Include your own basic security rules. Removing this option will run all the rules
# Include your own basic security rules. Removing this option will run all the rules
# includeRule: '"PSAvoidGlobalAliases", "PSAvoidUsingConvertToSecureStringWithPlainText"'
output: results.sarif

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_with_TestingHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
# Runs a single command using the runners shell
- name: Run test.ps1
shell: pwsh
run: |
run: |
$result = ./test.ps1 -ShowTestErrors
$result

Expand All @@ -40,6 +40,6 @@ jobs:
# $passed = $result.Tests -eq $result.Pass

if($passed)
{ "All test passed" | Write-Verbose -verbose ; exit 0 }
else
{ "All test passed" | Write-Verbose -verbose ; exit 0 }
else
{ "Not all tests passed" | Write-Verbose -verbose ; exit 1 }
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,3 @@ ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog

# exclude vscode settings folder
.vscode/settings.json
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
//
// Module V2 - https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.vscode/launch.json

"version": "0.2.0",
"configurations": [
{
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"terminal.integrated.profiles.osx": {
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell",
"args": ["-NoExit", "-Command", "if (Test-Path './tools/Test_Helper') { Import-Module './tools/Test_Helper' -Force }"]
}
}
}
1 change: 0 additions & 1 deletion IncludeHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,3 @@ PrivateData = @{
# DefaultCommandPrefix = ''

}

1 change: 0 additions & 1 deletion Test/Test.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,3 @@ PrivateData = @{
# DefaultCommandPrefix = ''

}

121 changes: 70 additions & 51 deletions Test/helper/module.helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Find-ModuleRootPath{
$path = $path | Split-Path -Parent
continue
}

# foudn module
return $path
}
Expand All @@ -36,8 +36,45 @@ $MODULE_NAME = (Get-ChildItem -Path $MODULE_ROOT_PATH -Filter *.psd1 | Select-Ob

# Helper for module variables


$VALID_FOLDER_NAMES = @('Include', 'Private', 'Public', 'Root', 'TestInclude', 'TestPrivate', 'TestPublic', 'TestRoot', 'Tools', 'DevContainer', 'WorkFlows', 'GitHub', 'Helper', 'Config', 'TestHelper', 'TestConfig')
# Folders names that IncludeHelper may add content to
$VALID_INCLUDE_FOLDER_NAMES = @(
'Root',
'Include',
'DevContainer',
'WorkFlows',
'GitHub',
# 'Config',
'Helper',
# 'Private',
# 'Public',
'Tools',

'TestRoot',
# 'TestConfig'
'TestInclude',
'TestHelper',
# 'TestPrivate',
# 'TestPublic',

"TestHelperRoot",
"TestHelperPrivate",
"TestHelperPublic"

"VsCode"
)

# Folders names that IncludeHelper should not add content to.
# In this folders is the module code itself
$VALID_MODULE_FOLDER_NAMES = @(
'Config',
'Private',
'Public',
'TestConfig'
'TestPrivate',
'TestPublic'
)

$VALID_FOLDER_NAMES = $VALID_INCLUDE_FOLDER_NAMES + $VALID_MODULE_FOLDER_NAMES

class ValidFolderNames : System.Management.Automation.IValidateSetValuesGenerator {
[String[]] GetValidValues() {
Expand Down Expand Up @@ -113,56 +150,38 @@ function Get-ModuleFolder{

# TestRootPath
$testRootPath = $ModuleRootPath | Join-Path -ChildPath "Test"
$testHelperRootPath = $ModuleRootPath | Join-Path -ChildPath "tools/Test_Helper"

switch ($FolderName){
'Public'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public"
}
'Private'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private"
}
'Include'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include"
}
'TestInclude'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "include"
}
'TestPrivate'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "private"
}
'TestPublic'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "public"
}
'Root'{
$moduleFolder = $ModuleRootPath
}
'TestRoot'{
$moduleFolder = $testRootPath
}
'Tools'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools"
}
'DevContainer'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer"
}
'WorkFlows'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows"
}
'GitHub'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github"
}
'Helper'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper"
}
'Config'{
$moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config"
}
'TestHelper'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "helper"
}
'TestConfig'{
$moduleFolder = $testRootPath | Join-Path -ChildPath "config"
}

# VALID_INCLUDE_FOLDER_NAMES
'Root' { $moduleFolder = $ModuleRootPath }
'Include' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "include" }
'DevContainer'{ $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".devcontainer" }
'WorkFlows' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github/workflows" }
'GitHub' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".github" }
'Helper' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "helper" }
'Tools' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "tools" }

'TestRoot' { $moduleFolder = $testRootPath }
'TestInclude' { $moduleFolder = $testRootPath | Join-Path -ChildPath "include" }
'TestHelper' { $moduleFolder = $testRootPath | Join-Path -ChildPath "helper" }

'TestHelperRoot' { $moduleFolder = $testHelperRootPath }
'TestHelperPrivate' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "private" }
'TestHelperPublic' { $moduleFolder = $testHelperRootPath | Join-Path -ChildPath "public" }

"VsCode" { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath ".vscode" }

# VALID_MODULE_FOLDER_NAMES
'Config' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "config" }
'Private' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "private" }
'Public' { $moduleFolder = $ModuleRootPath | Join-Path -ChildPath "public" }
'TestConfig' { $moduleFolder = $testRootPath | Join-Path -ChildPath "config" }
'TestPrivate' { $moduleFolder = $testRootPath | Join-Path -ChildPath "private" }
'TestPublic' { $moduleFolder = $testRootPath | Join-Path -ChildPath "public" }


default{
throw "Folder [$FolderName] is unknown"
}
Expand Down
4 changes: 2 additions & 2 deletions Test/include/callPrivateContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function Invoke-PrivateContext {
if ([string]::IsNullOrEmpty($ModulePath)) {
$modulePath = $MODULE_PATH | Split-Path -Parent
}

$module = Import-Module -Name $modulePath -PassThru

if ($null -eq $module) {
throw "Failed to import the main module."
}

& $module $ScriptBlock
& $module $ScriptBlock
} Export-ModuleMember -Function Invoke-PrivateContext
6 changes: 3 additions & 3 deletions Test/include/config.mock.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# CONFIG MOCK
# CONFIG MOCK
#
# This file is used to mock the config path and the config file
# for the tests. It creates a mock config path and a mock config file
Expand Down Expand Up @@ -38,8 +38,8 @@ function Mock_Config{

if([string]::IsNullOrWhiteSpace($ModuleName)){
$moduleName = $MODULE_NAME
}
}

$invokefunction = $CONFIG_INVOKE_GET_ROOT_PATH_CMD -replace "{modulename}", $moduleName

# Mock invoke call
Expand Down
2 changes: 1 addition & 1 deletion Test/include/database.mock.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DATABASE MOCK
# DATABASE MOCK
#
# This file is used to mock the database path and the database file
# for the tests. It creates a mock database path and a mock database file
Expand Down
4 changes: 0 additions & 4 deletions Test/include/invokeCommand.mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,3 @@ function Assert-MockFileNotfound{
throw "File not found or wrong case name. Expected[ $filename ] - Found[$( $file.name )]"
}
}




2 changes: 1 addition & 1 deletion Test/include/parameter.test.helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Scope='function')]
$WarningParameters = @{
WarningAction = 'SilentlyContinue'
WarningAction = 'SilentlyContinue'
WarningVariable = 'warningVar'
}

Expand Down
2 changes: 1 addition & 1 deletion Test/include/run_BeforeAfter.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Run Before and After any test
#
#
# Supported by TestingHelper 4.1.0 we can specify code that will run :
# - Before each test
# - After each test
Expand Down
4 changes: 2 additions & 2 deletions Test/include/transcriptHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Start-MyTranscript {
}

function Stop-MyTranscript {

$null = Stop-Transcript

$transcriptContent = Get-Content -Path $TEST_TRANSCRIPT_FILE
Expand All @@ -41,6 +41,6 @@ function Export-MyTranscript {
$lastLine = $i[2] - 1

$retlist = $transcriptContent[$firstLine..$lastLine]

return $retlist
}
2 changes: 1 addition & 1 deletion Test/public/MyWrite.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Test_WriteMyHost_Singleline {
Invoke-PrivateContext {
Write-MyHost -Message "This is a test transcript."
}

$result = Stop-MyTranscript

Assert-AreEqual -Expected "This is a test transcript." -Presented $result
Expand Down
Loading
Loading