Skip to content

Commit b0ef46e

Browse files
🩹 [Patch]: Add test for module without named folder and files (#21)
## Description - Add test for module without named folder and files ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 8132c54 commit b0ef46e

23 files changed

+459
-4
lines changed

.github/workflows/Auto-Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Auto-Release
22

3-
run-name: "Auto-Release - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
3+
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
44

55
on:
66
pull_request_target:

.github/workflows/Linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Linter
22

3-
run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
3+
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
44

55
on: [pull_request]
66

.github/workflows/Workflow-Test.yml renamed to .github/workflows/Workflow-Test-Default.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: Workflow-Test
1+
name: Workflow-Test [Default]
22

3-
run-name: "Workflow-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"
3+
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
44

55
on: [pull_request]
66

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Workflow-Test [UnnamedFolder]
2+
3+
run-name: "${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }} by @${{ github.actor }}"
4+
5+
on: [pull_request]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
statuses: write
15+
16+
jobs:
17+
WorkflowTestUnnamedFolder:
18+
uses: ./.github/workflows/workflow.yml
19+
secrets: inherit
20+
with:
21+
Name: PSModuleTest
22+
Path: tests/srcNo
23+
ModulesOutputPath: tests/outputs/modules
24+
DocsOutputPath: tests/outputs/docs
25+
TestProcess: true

tests/srcNo/assemblies/LsonLib.dll

42.5 KB
Binary file not shown.

tests/srcNo/classes/Book.ps1

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
class Book {
2+
# Class properties
3+
[string] $Title
4+
[string] $Author
5+
[string] $Synopsis
6+
[string] $Publisher
7+
[datetime] $PublishDate
8+
[int] $PageCount
9+
[string[]] $Tags
10+
# Default constructor
11+
Book() { $this.Init(@{}) }
12+
# Convenience constructor from hashtable
13+
Book([hashtable]$Properties) { $this.Init($Properties) }
14+
# Common constructor for title and author
15+
Book([string]$Title, [string]$Author) {
16+
$this.Init(@{Title = $Title; Author = $Author })
17+
}
18+
# Shared initializer method
19+
[void] Init([hashtable]$Properties) {
20+
foreach ($Property in $Properties.Keys) {
21+
$this.$Property = $Properties.$Property
22+
}
23+
}
24+
# Method to calculate reading time as 2 minutes per page
25+
[timespan] GetReadingTime() {
26+
if ($this.PageCount -le 0) {
27+
throw 'Unable to determine reading time from page count.'
28+
}
29+
$Minutes = $this.PageCount * 2
30+
return [timespan]::new(0, $Minutes, 0)
31+
}
32+
# Method to calculate how long ago a book was published
33+
[timespan] GetPublishedAge() {
34+
if (
35+
$null -eq $this.PublishDate -or
36+
$this.PublishDate -eq [datetime]::MinValue
37+
) { throw 'PublishDate not defined' }
38+
39+
return (Get-Date) - $this.PublishDate
40+
}
41+
# Method to return a string representation of the book
42+
[string] ToString() {
43+
return "$($this.Title) by $($this.Author) ($($this.PublishDate.Year))"
44+
}
45+
}
46+
47+
class BookList {
48+
# Static property to hold the list of books
49+
static [System.Collections.Generic.List[Book]] $Books
50+
# Static method to initialize the list of books. Called in the other
51+
# static methods to avoid needing to explicit initialize the value.
52+
static [void] Initialize() { [BookList]::Initialize($false) }
53+
static [bool] Initialize([bool]$force) {
54+
if ([BookList]::Books.Count -gt 0 -and -not $force) {
55+
return $false
56+
}
57+
58+
[BookList]::Books = [System.Collections.Generic.List[Book]]::new()
59+
60+
return $true
61+
}
62+
# Ensure a book is valid for the list.
63+
static [void] Validate([book]$Book) {
64+
$Prefix = @(
65+
'Book validation failed: Book must be defined with the Title,'
66+
'Author, and PublishDate properties, but'
67+
) -join ' '
68+
if ($null -eq $Book) { throw "$Prefix was null" }
69+
if ([string]::IsNullOrEmpty($Book.Title)) {
70+
throw "$Prefix Title wasn't defined"
71+
}
72+
if ([string]::IsNullOrEmpty($Book.Author)) {
73+
throw "$Prefix Author wasn't defined"
74+
}
75+
if ([datetime]::MinValue -eq $Book.PublishDate) {
76+
throw "$Prefix PublishDate wasn't defined"
77+
}
78+
}
79+
# Static methods to manage the list of books.
80+
# Add a book if it's not already in the list.
81+
static [void] Add([Book]$Book) {
82+
[BookList]::Initialize()
83+
[BookList]::Validate($Book)
84+
if ([BookList]::Books.Contains($Book)) {
85+
throw "Book '$Book' already in list"
86+
}
87+
88+
$FindPredicate = {
89+
param([Book]$b)
90+
91+
$b.Title -eq $Book.Title -and
92+
$b.Author -eq $Book.Author -and
93+
$b.PublishDate -eq $Book.PublishDate
94+
}.GetNewClosure()
95+
if ([BookList]::Books.Find($FindPredicate)) {
96+
throw "Book '$Book' already in list"
97+
}
98+
99+
[BookList]::Books.Add($Book)
100+
}
101+
# Clear the list of books.
102+
static [void] Clear() {
103+
[BookList]::Initialize()
104+
[BookList]::Books.Clear()
105+
}
106+
# Find a specific book using a filtering scriptblock.
107+
static [Book] Find([scriptblock]$Predicate) {
108+
[BookList]::Initialize()
109+
return [BookList]::Books.Find($Predicate)
110+
}
111+
# Find every book matching the filtering scriptblock.
112+
static [Book[]] FindAll([scriptblock]$Predicate) {
113+
[BookList]::Initialize()
114+
return [BookList]::Books.FindAll($Predicate)
115+
}
116+
# Remove a specific book.
117+
static [void] Remove([Book]$Book) {
118+
[BookList]::Initialize()
119+
[BookList]::Books.Remove($Book)
120+
}
121+
# Remove a book by property value.
122+
static [void] RemoveBy([string]$Property, [string]$Value) {
123+
[BookList]::Initialize()
124+
$Index = [BookList]::Books.FindIndex({
125+
param($b)
126+
$b.$Property -eq $Value
127+
}.GetNewClosure())
128+
if ($Index -ge 0) {
129+
[BookList]::Books.RemoveAt($Index)
130+
}
131+
}
132+
}

tests/srcNo/data/Config.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
RandomKey = 'RandomValue'
3+
}

tests/srcNo/data/Settings.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
RandomSetting = 'RandomSettingValue'
3+
}

tests/srcNo/finally.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Write-Verbose '------------------------------' -Verbose
2+
Write-Verbose '--- THIS IS A LAST LOADER ---' -Verbose
3+
Write-Verbose '------------------------------' -Verbose
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>System.Globalization.CultureInfo</Name>
6+
<ViewSelectedBy>
7+
<TypeName>System.Globalization.CultureInfo</TypeName>
8+
</ViewSelectedBy>
9+
<TableControl>
10+
<TableHeaders>
11+
<TableColumnHeader>
12+
<Width>16</Width>
13+
</TableColumnHeader>
14+
<TableColumnHeader>
15+
<Width>16</Width>
16+
</TableColumnHeader>
17+
<TableColumnHeader />
18+
</TableHeaders>
19+
<TableRowEntries>
20+
<TableRowEntry>
21+
<TableColumnItems>
22+
<TableColumnItem>
23+
<PropertyName>LCID</PropertyName>
24+
</TableColumnItem>
25+
<TableColumnItem>
26+
<PropertyName>Name</PropertyName>
27+
</TableColumnItem>
28+
<TableColumnItem>
29+
<PropertyName>DisplayName</PropertyName>
30+
</TableColumnItem>
31+
</TableColumnItems>
32+
</TableRowEntry>
33+
</TableRowEntries>
34+
</TableControl>
35+
</View>
36+
</ViewDefinitions>
37+
</Configuration>

0 commit comments

Comments
 (0)