-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
2,243 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: CI Job to Generate JUnit Report | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
generate-report: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Make Shell Script Executable | ||
run: chmod +x scripts/generate_input.sh | ||
|
||
- name: Run Shell Script to Generate Input File | ||
run: | | ||
./scripts/run_commit_tests.sh | ||
- name: Run JUnit Report Generation Script | ||
run: | | ||
python scripts/into_junit.py /tmp/SHARED.UNITS > junit.xml | ||
- name: Upload JUnit Report | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: junit-report | ||
path: junit.xml | ||
|
||
- name: Display JUnit Test Results | ||
uses: dorny/test-reporter@v1 | ||
with: | ||
name: 'JUnit Results' | ||
path: 'junit.xml' | ||
reporter: 'junit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import xml.etree.ElementTree as ET | ||
import sys | ||
import re | ||
|
||
def create_testcase_element(testclass, testname, stdout, identifier, got, expected, status, url): | ||
testcase = ET.Element("testcase", classname=testclass, name=testname) | ||
|
||
description = f"Test {identifier} with URL: {url}" | ||
|
||
if status == "PASS": | ||
system_out = ET.SubElement(testcase, "system-out") | ||
system_out.text = f"<![CDATA[\n<a href=\"{url}\">Test Report</a>\n\nAssertion: {stdout}\nExpected: {expected}\nActual: {got}\n]]>" | ||
else: # status == "FAIL" | ||
failure_message = f"Test failed: Expected '{expected}' but got '{got}'" | ||
failure = ET.SubElement(testcase, "failure", message=failure_message, type="AssertionError") | ||
failure.text = f"<![CDATA[\nAssertionError: {failure_message}\n]]>" | ||
system_out = ET.SubElement(testcase, "system-out") | ||
system_out.text = f"<![CDATA[\n<a href=\"{url}\">Test Report</a>\n\nAssertion: {stdout}\nExpected: {expected}\nActual: {got}\n]]>" | ||
|
||
return testcase | ||
|
||
def parse_test_line(line): | ||
parts = re.split(r'\s*\|\s*(?![^()]*\))', line.strip()) | ||
if len(parts) < 7: | ||
raise ValueError(f"Line does not have the expected number of parts: {len(parts)} found") | ||
|
||
full_identifier = parts[1].strip() # The second field contains the test class and name | ||
status = parts[2].strip() # The third field contains the pass/fail status | ||
url = re.search(r'\((.*?)\)', parts[3]).group(1).strip() # Extract the URL inside the parentheses | ||
stdout = parts[4].strip() # The fifth field contains the assertion | ||
got = parts[5].strip() | ||
expected = parts[6].strip() | ||
|
||
try: | ||
testclass, testname = full_identifier.rsplit('.', 1) | ||
if '.' in testclass: | ||
testname = f"{testclass.split('.')[-1]}.{testname}" # Combine to form the correct testname | ||
if not testclass or not testname: | ||
raise ValueError("Test class or test name is empty after splitting.") | ||
except ValueError as e: | ||
raise ValueError(f"Identifier does not contain the expected format: {full_identifier}. Error: {str(e)}") | ||
|
||
return testclass, testname, stdout, full_identifier, got, expected, status, url | ||
|
||
def generate_junit_xml(input_file): | ||
testsuites = ET.Element("testsuites") | ||
testsuite = ET.Element("testsuite", name="Metta Tests") | ||
testsuites.append(testsuite) | ||
|
||
with open(input_file, 'r') as file: | ||
for line in file: | ||
parts = None | ||
if line.startswith("|"): | ||
try: | ||
parts = re.split(r'\s*\|\s*(?![^()]*\))', line.strip()) | ||
testclass, testname, stdout, full_identifier, got, expected, status, url = parse_test_line(line) | ||
testcase = create_testcase_element(testclass, testname, stdout, full_identifier, got, expected, status, url) | ||
testsuite.append(testcase) | ||
print(f"Processing {testclass}.{testname}: {status}", file=sys.stderr) | ||
except ValueError as e: | ||
print(f"Skipping line due to error: {e}\nLine: {line}\nParts: {parts}", file=sys.stderr) | ||
|
||
tree = ET.ElementTree(testsuites) | ||
return ET.tostring(testsuites, encoding="utf-8", xml_declaration=True).decode("utf-8") | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 2: | ||
print("Usage: python generate_junit.py <input_file>") | ||
sys.exit(1) | ||
|
||
input_file = sys.argv[1] | ||
junit_xml = generate_junit_xml(input_file) | ||
print(junit_xml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Windows Registry Editor Version 5.00 | ||
|
||
; Associate .metta files with run-metta.cmd | ||
[HKEY_CLASSES_ROOT\.metta] | ||
@="MettaFile" | ||
|
||
[HKEY_CLASSES_ROOT\MettaFile] | ||
@="Metta Script File" | ||
|
||
; Set a system icon for .metta files | ||
[HKEY_CLASSES_ROOT\MettaFile\DefaultIcon] | ||
@="%SystemRoot%\\regedit.exe,0" | ||
|
||
[HKEY_CLASSES_ROOT\MettaFile\shell] | ||
@="open" | ||
|
||
; Default action (open) | ||
[HKEY_CLASSES_ROOT\MettaFile\shell\open] | ||
@="Run with Metta" | ||
|
||
[HKEY_CLASSES_ROOT\MettaFile\shell\open\command] | ||
@="\"H:\\opt\\hyperon\\metta-wam\\mettalog.cmd\" \"%1\"" | ||
|
||
; Add 'Edit with Notepad' to the context menu | ||
[HKEY_CLASSES_ROOT\MettaFile\shell\edit] | ||
@="Edit with Notepad" | ||
|
||
[HKEY_CLASSES_ROOT\MettaFile\shell\edit\command] | ||
@="notepad.exe \"%1\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# This script generates the input file used by the Python script. | ||
# Replace the following lines with the actual commands to generate the input file. | ||
|
||
echo "| ANTI-REGRESSION.BC-COMP.01 | PASS |(https://example.com/test-report) | (assertEqualToResult (add-atom &kb (: axiom (nums 2 3)))) | (()) | (()) |" > /tmp/SHARED.UNITS | ||
|
||
# You can add more lines or commands to generate additional input data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.