Skip to content

Commit 3a7e8df

Browse files
committed
Install Rubberduck and run tests
1 parent b53c0d0 commit 3a7e8df

File tree

6 files changed

+391
-1
lines changed

6 files changed

+391
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: ./
2222
with:
2323
sourceDir: "./tests"
24-
timeout-minutes: 10
24+
timeout-minutes: 15
2525
- name: "Display Chocolatey logs in case of Office install failure"
2626
if: failure() && steps.build_vba.outcome == 'failure'
2727
run: |

Main.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Write-Host "Open and close Office applications"
5454
. "$PSScriptRoot/scripts/Open-Close-Office.ps1" $officeApps
5555
Write-Host "========================="
5656

57+
Write-Host "Install Rubberduck"
58+
. "$PSScriptRoot/scripts/Install-Ruberduck-VBA.ps1" $officeApps
59+
5760
# Enable VBOM for each Office application
5861
foreach ($app in $officeApps) {
5962
Write-Host "Enabling VBOM for $app"

scripts/Build-VBA.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ try {
293293
}
294294
}
295295

296+
# Generic test
296297
# Call the WriteToFile macro to check if the module was imported correctly
297298
try {
298299

@@ -331,7 +332,62 @@ try {
331332
} catch {
332333
Take-Screenshot -OutputPath "${screenshotDir}Screenshot_${fileNameNoExt}_{{timestamp}}.png"
333334
Write-Host "🟡 Warning: Could not execute macro ${macroName}: $($_.Exception.Message)"
335+
}
336+
337+
# Create a function for Rubberduck testing
338+
function Test-WithRubberduck {
339+
param (
340+
[Parameter(Mandatory=$true)]
341+
$officeApp
342+
)
334343

344+
$rubberduckAddin = $null
345+
$rubberduck = $null
346+
try {
347+
$rubberduckAddin = $officeApp.COMAddIns.Item("Rubberduck")
348+
if ($null -eq $rubberduckAddin) {
349+
Write-Host "🔴 Error: Rubberduck add-in not found. Please install it first."
350+
return $false
351+
}
352+
$rubberduck = $rubberduckAddin.Object
353+
if ($null -eq $rubberduck) {
354+
Write-Host "🔴 Error: Rubberduck object not found. Please ensure it is properly installed."
355+
return $false
356+
}
357+
358+
Write-Host "Rubberduck add-in found. Proceeding with tests..."
359+
# Run all tests in the active VBA project
360+
$rubberduck.RunAllTests()
361+
Write-Host "All tests executed successfully."
362+
363+
# Wait for tests to complete (optional: add a timeout)
364+
Start-Sleep -Seconds 10
365+
366+
# Retrieve test results
367+
$results = $rubberduck.GetTestResults()
368+
foreach ($result in $results) {
369+
Write-Host "Test: $($result.Name) - Outcome: $($result.Outcome)"
370+
}
371+
372+
# Make sure to release the COM object
373+
if ($null -ne $rubberduck) {
374+
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($rubberduck) | Out-Null
375+
Write-Host "Released Rubberduck COM object"
376+
}
377+
378+
return $true
379+
}
380+
catch {
381+
Write-Host "🔴 Error: Could not access Rubberduck add-in: $($_.Exception.Message)"
382+
return $false
383+
}
384+
}
385+
386+
# Now perform all tests using Rubberduck
387+
# Replace the existing Rubberduck test block with this:
388+
$rubberduckTestResult = Test-WithRubberduck -officeApp $officeApp
389+
if (-not $rubberduckTestResult) {
390+
Write-Host "Rubberduck tests were not completed successfully, but continuing with the script..."
335391
}
336392

337393
# Close the document

scripts/Install-Rubberduck-VBA.ps1

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# # Summary:
2+
# # This PowerShell installs Rubberduck for the VBE and runs all tests in the active VBA project.
3+
#
4+
5+
# Installer location: https://github.com/rubberduck-vba/Rubberduck/releases/latest
6+
7+
# Options to run the installer:
8+
# ---------------------------
9+
# Setup
10+
# ---------------------------
11+
# The Setup program accepts optional command line parameters.
12+
#
13+
#
14+
#
15+
# /HELP, /?
16+
#
17+
# Shows this information.
18+
#
19+
# /SP-
20+
#
21+
# Disables the This will install... Do you wish to continue? prompt at the beginning of Setup.
22+
#
23+
# /SILENT, /VERYSILENT
24+
#
25+
# Instructs Setup to be silent or very silent.
26+
#
27+
# /SUPPRESSMSGBOXES
28+
#
29+
# Instructs Setup to suppress message boxes.
30+
#
31+
# /LOG
32+
#
33+
# Causes Setup to create a log file in the user's TEMP directory.
34+
#
35+
# /LOG="filename"
36+
#
37+
# Same as /LOG, except it allows you to specify a fixed path/filename to use for the log file.
38+
#
39+
# /NOCANCEL
40+
#
41+
# Prevents the user from cancelling during the installation process.
42+
#
43+
# /NORESTART
44+
#
45+
# Prevents Setup from restarting the system following a successful installation, or after a Preparing to Install failure that requests a restart.
46+
#
47+
# /RESTARTEXITCODE=exit code
48+
#
49+
# Specifies a custom exit code that Setup is to return when the system needs to be restarted.
50+
#
51+
# /CLOSEAPPLICATIONS
52+
#
53+
# Instructs Setup to close applications using files that need to be updated.
54+
#
55+
# /NOCLOSEAPPLICATIONS
56+
#
57+
# Prevents Setup from closing applications using files that need to be updated.
58+
#
59+
# /FORCECLOSEAPPLICATIONS
60+
#
61+
# Instructs Setup to force close when closing applications.
62+
#
63+
# /FORCENOCLOSEAPPLICATIONS
64+
#
65+
# Prevents Setup from force closing when closing applications.
66+
#
67+
# /LOGCLOSEAPPLICATIONS
68+
#
69+
# Instructs Setup to create extra logging when closing applications for debugging purposes.
70+
#
71+
# /RESTARTAPPLICATIONS
72+
#
73+
# Instructs Setup to restart applications.
74+
#
75+
# /NORESTARTAPPLICATIONS
76+
#
77+
# Prevents Setup from restarting applications.
78+
#
79+
# /LOADINF="filename"
80+
#
81+
# Instructs Setup to load the settings from the specified file after having checked the command line.
82+
#
83+
# /SAVEINF="filename"
84+
#
85+
# Instructs Setup to save installation settings to the specified file.
86+
#
87+
# /LANG=language
88+
#
89+
# Specifies the internal name of the language to use.
90+
#
91+
# /DIR="x:\dirname"
92+
#
93+
# Overrides the default directory name.
94+
#
95+
# /GROUP="folder name"
96+
#
97+
# Overrides the default folder name.
98+
#
99+
# /NOICONS
100+
#
101+
# Instructs Setup to initially check the Don't create a Start Menu folder check box.
102+
#
103+
# /TYPE=type name
104+
#
105+
# Overrides the default setup type.
106+
#
107+
# /COMPONENTS="comma separated list of component names"
108+
#
109+
# Overrides the default component settings.
110+
#
111+
# /TASKS="comma separated list of task names"
112+
#
113+
# Specifies a list of tasks that should be initially selected.
114+
#
115+
# /MERGETASKS="comma separated list of task names"
116+
#
117+
# Like the /TASKS parameter, except the specified tasks will be merged with the set of tasks that would have otherwise been selected by default.
118+
#
119+
# /PASSWORD=password
120+
#
121+
# Specifies the password to use.
122+
#
123+
#
124+
#
125+
# For more detailed information, please visit https://jrsoftware.org/ishelp/index.php?topic=setupcmdline
126+
# ---------------------------
127+
# OK
128+
# ---------------------------
129+
#
130+
131+
132+
# This script installs Rubberduck for the VBE and runs all tests in the active VBA project.
133+
# It uses the Inno Setup installer for Rubberduck, which is a popular open-source VBA add-in for unit testing and code inspection.
134+
# The script is designed to be run in a PowerShell environment and requires administrative privileges to install the add-in.
135+
136+
# The script performs the following steps:
137+
# 1. Downloads the latest version of Rubberduck from GitHub.
138+
# 2. Installs Rubberduck using the Inno Setup installer with specified command line options to suppress prompts and run silently.
139+
# ======
140+
141+
# Step 1:
142+
143+
# Download the latest version of Rubberduck from GitHub
144+
# The URL is constructed using the latest release version from the Rubberduck GitHub repository.
145+
# The script uses the Invoke-WebRequest cmdlet to download the installer to a temporary location.
146+
$rubberduckUrl = "https://github.com/rubberduck-vba/Rubberduck/releases/download/v2.5.91/Rubberduck.Setup.2.5.9.6316.exe"
147+
148+
149+
$tempInstallerPath = "$env:TEMP\Rubberduck.Setup.exe"
150+
Invoke-WebRequest -Uri $rubberduckUrl -OutFile $tempInstallerPath
151+
152+
# Step 2:
153+
# Install Rubberduck using the Inno Setup installer with specified command line options
154+
# The script uses the Start-Process cmdlet to run the installer with the /SILENT and /NORESTART options to suppress prompts and prevent automatic restarts.
155+
$installerArgs = "/SILENT /NORESTART /SUPPRESSMSGBOXES /LOG=$env:TEMP\RubberduckInstall.log"
156+
Start-Process -FilePath $tempInstallerPath -ArgumentList $installerArgs -Wait
157+
# The -Wait parameter ensures that the script waits for the installation to complete before proceeding.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Attribute VB_Name = "FunctionCollection"
2+
Option Explicit
3+
4+
'Source: https://www.youtube.com/watch?v=sR8ZM0XUXdk
5+
6+
'@Description("This will make a valid constant name according to covention")
7+
'@Dependency("IsCapitalLetter function")
8+
'@ExampleCall : MakeValidConstName("SettingsTable") >> SETTINGS_TABLE
9+
'@Date : 14 October 2021 08:05:41 PM
10+
Public Function MakeValidConstName(ByVal GivenName As String) As String
11+
12+
If Trim(GivenName) = vbNullString Then
13+
Err.Raise 13, "MakeValidConstName Function", "Constant Name can't be Nullstring"
14+
ElseIf Not (Left(GivenName, 1) Like "[A-Za-z]") Then
15+
Err.Raise 13, "MakeValidConstName Function", "Constant Name Should be start with A-Z or a-z"
16+
End If
17+
18+
Dim Result As String
19+
If UCase(GivenName) = GivenName Then
20+
MakeValidConstName = GivenName
21+
Exit Function
22+
End If
23+
Dim Counter As Long
24+
Dim CurrentCharacter As String
25+
Const WORD_SEPARATOR As String = "_"
26+
Result = Left(GivenName, 1)
27+
For Counter = 2 To Len(GivenName)
28+
CurrentCharacter = Mid(GivenName, Counter, 1)
29+
If IsCapitalLetter(CurrentCharacter) Then
30+
Result = Result & WORD_SEPARATOR
31+
End If
32+
Result = Result & CurrentCharacter
33+
Next Counter
34+
Result = UCase(Result)
35+
MakeValidConstName = Result
36+
37+
End Function
38+
39+
40+
'@Description("This will check if a given character is Capital letter > A-Z..It will throw error if length of the letter is more than 1")
41+
'@Dependency("No Dependency")
42+
'@ExampleCall : IsCapitalLetter(CurrentCharacter)
43+
'@Date : 14 October 2021 10:23:19 PM
44+
Public Function IsCapitalLetter(ByVal GivenLetter As String) As Boolean
45+
If Len(GivenLetter) > 1 Then
46+
Err.Raise 13, "IsCapitalLetter Function", "Given Letter need to be one character String"
47+
End If
48+
If GivenLetter = vbNullString Then
49+
Err.Raise 5, "IsCapitalLetter Function", "Given Letter can't be nullstring"
50+
End If
51+
52+
Const ASCII_CODE_FOR_A As Integer = 65
53+
Const ASCII_CODE_FOR_Z As Integer = 90
54+
Dim ASCIICodeForGivenLetter As Integer
55+
ASCIICodeForGivenLetter = Asc(GivenLetter)
56+
IsCapitalLetter = (ASCIICodeForGivenLetter >= ASCII_CODE_FOR_A And ASCIICodeForGivenLetter <= ASCII_CODE_FOR_Z)
57+
58+
End Function
59+

0 commit comments

Comments
 (0)