Compare commits

..

1 Commits

Author SHA1 Message Date
SirBroccoli
64a6bb0ff6 test: capture help output 2025-06-06 00:01:37 +02:00
2 changed files with 20 additions and 15 deletions

View File

@@ -106,6 +106,8 @@ def parse_line(line: str):
global FINAL_JSON, C_SECTION, C_MAIN_SECTION, C_2_SECTION, C_3_SECTION global FINAL_JSON, C_SECTION, C_MAIN_SECTION, C_2_SECTION, C_3_SECTION
if "Cron jobs" in line:
a=1
if is_section(line, TITLE1_PATTERN): if is_section(line, TITLE1_PATTERN):
title = parse_title(line) title = parse_title(line)
@@ -143,23 +145,14 @@ def parse_line(line: str):
def parse_peass(outputpath: str, jsonpath: str = ""): def parse_peass(outputpath: str, jsonpath: str = ""):
global OUTPUT_PATH, JSON_PATH, FINAL_JSON, C_SECTION, C_MAIN_SECTION, C_2_SECTION, C_3_SECTION global OUTPUT_PATH, JSON_PATH
OUTPUT_PATH = outputpath OUTPUT_PATH = outputpath
JSON_PATH = jsonpath JSON_PATH = jsonpath
# Reset globals to avoid data leaking between executions for line in open(OUTPUT_PATH, 'r', encoding="utf8").readlines():
FINAL_JSON = {}
C_SECTION = FINAL_JSON
C_MAIN_SECTION = FINAL_JSON
C_2_SECTION = FINAL_JSON
C_3_SECTION = FINAL_JSON
with open(OUTPUT_PATH, 'r', encoding="utf8") as f:
for line in f.readlines():
line = line.strip() line = line.strip()
# Remove empty lines or lines containing only color codes if not line or not clean_colors(line): #Remove empty lines or lines just with colors hex
if not line or not clean_colors(line):
continue continue
parse_line(line) parse_line(line)

View File

@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using System; using System;
using System.IO;
namespace winPEAS.Tests namespace winPEAS.Tests
{ {
@@ -25,17 +26,28 @@ namespace winPEAS.Tests
[TestMethod] [TestMethod]
public void ShouldDisplayHelp() public void ShouldDisplayHelp()
{ {
var originalOut = Console.Out;
var sw = new StringWriter();
try try
{ {
Console.SetOut(sw);
string[] args = new string[] { string[] args = new string[] {
"help", "help",
}; };
Program.Main(args); Program.Main(args);
string output = sw.ToString();
Assert.IsTrue(output.Contains("WinPEAS is a binary"),
"Help output did not contain expected text.");
} }
catch (Exception e) catch (Exception e)
{ {
Assert.Fail($"Exception thrown: {e.Message}"); Assert.Fail($"Exception thrown: {e.Message}");
} }
finally
{
Console.SetOut(originalOut);
}
} }
} }
} }