Skip to content

Commit

Permalink
Merge pull request #16 from brunoerg/2025-02-improve-json
Browse files Browse the repository at this point in the history
report: improve the way it displays the diffs
  • Loading branch information
brunoerg authored Feb 14, 2025
2 parents 4c0bf41 + b9d7f23 commit 62090ed
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/report.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import os
import re
import json
import subprocess
from datetime import datetime

def parse_diffs_to_json(diffs_list):
result = {}

for diff in diffs_list:
match = re.search(r'@@ -(\d+),', diff)
if match:
line_num = str(int(match.group(1)) + 3)
if line_num not in result:
result[line_num] = []

result[line_num].append({
"id": len(result[line_num]) + 1,
"diff": diff[diff.index("@@"):],
"status": "alive"
})

return result

def generate_report(not_killed_mutants=[], folder="", original_file="", score=0, just_append=True):
# Skips creating a report file if mutation score is 100%
if len(not_killed_mutants) == 0:
Expand Down Expand Up @@ -39,6 +58,8 @@ def generate_report(not_killed_mutants=[], folder="", original_file="", score=0,
# Append the diff output to the diffs list
report_data["diffs"].append(result.stdout)

report_data["diffs"] = parse_diffs_to_json(report_data["diffs"])

# Check if we should append to an existing file or create a new one
json_file = 'diff_not_killed.json' if just_append else f'diff_not_killed-{original_file.replace(".cpp", "").replace(".py", "").replace("/", "-")}.json'

Expand Down

0 comments on commit 62090ed

Please sign in to comment.