diff --git a/src/suppression_study/evolution/AccidentalSuppressionFinder.py b/src/suppression_study/evolution/AccidentalSuppressionFinder.py index 8d7e420..52afa23 100644 --- a/src/suppression_study/evolution/AccidentalSuppressionFinder.py +++ b/src/suppression_study/evolution/AccidentalSuppressionFinder.py @@ -7,10 +7,8 @@ import ast import os from os.path import join, exists -import subprocess from typing import List from suppression_study.evolution.ExtractHistory import read_histories_from_json -from suppression_study.evolution.MapWarningLines import MapWarningLines from suppression_study.utils.FunctionsCommon import get_commit_list from suppression_study.warnings.WarningSuppressionMapper import main as compute_warning_suppression_mapping from suppression_study.warnings.WarningSuppressionUtil import read_mapping_from_csv @@ -113,7 +111,6 @@ def get_suppression_warning_pairs(repo_dir, commit, relevant_files, results_dir, def check_for_accidental_suppressions(repo_dir, history, relevant_commits, relevant_files, results_dir, is_file_specific): accidentally_suppressed_warnings = [] previous_commit = None - previous_suppression = None warnings_suppressed_at_previous_commit = None add_event = history[0] @@ -162,44 +159,22 @@ def check_for_accidental_suppressions(repo_dir, history, relevant_commits, relev # at the previous commit, create an AccidentallySuppressedWarning if warnings_suppressed_at_previous_commit is not None: if suppression is not None: - new_warning_hinder = None - num_new_warning = 0 - current_len = len(warnings_suppressed_at_commit) - previous_len = len(warnings_suppressed_at_previous_commit) - if previous_len > current_len: - pass - elif previous_len == current_len and warnings_suppressed_at_previous_commit != warnings_suppressed_at_commit: # - backup_warnings_suppressed_at_previous_commit = [w for w in warnings_suppressed_at_previous_commit] - backup_warnings_suppressed_at_commit = [w for w in warnings_suppressed_at_commit] - # the warnings may different, run diff to check the line number maps - new_warning_hinder, num_new_warning = MapWarningLines(repo_dir, previous_commit, commit, \ - backup_warnings_suppressed_at_previous_commit, backup_warnings_suppressed_at_commit ).check_warning_mapping() - elif previous_len < current_len: - num_new_warning = current_len - previous_len - - if num_new_warning > 0: + if len(warnings_suppressed_at_commit) > len(warnings_suppressed_at_previous_commit): # there's a new warning suppressed by this suppression - summary = f"from {previous_len} to {current_len}, new warnings: {num_new_warning}" accidentally_suppressed_warnings.append( - AccidentallySuppressedWarning(summary, - previous_commit, + AccidentallySuppressedWarning(previous_commit, commit, - previous_suppression, suppression, warnings_suppressed_at_previous_commit, - warnings_suppressed_at_commit, - new_warning_hinder)) + warnings_suppressed_at_commit)) previous_commit = commit - previous_suppression = suppression warnings_suppressed_at_previous_commit = warnings_suppressed_at_commit else: warnings_suppressed_at_previous_commit = None previous_commit = None - previous_suppression = None else: warnings_suppressed_at_previous_commit = None previous_commit = None - previous_suppression = None return accidentally_suppressed_warnings @@ -234,4 +209,4 @@ def main(repo_dir, commits_file, history_file, results_dir, is_file_specific): if __name__ == "__main__": args = parser.parse_args() - main(args.repo_dir, args.commits_file, args.history_file, args.results_dir, args.file_name_specific) + main(args.repo_dir, args.commits_file, args.history_file, args.results_dir, args.file_name_specific) \ No newline at end of file diff --git a/src/suppression_study/evolution/AccidentallySuppressedWarning.py b/src/suppression_study/evolution/AccidentallySuppressedWarning.py index dafeccc..fabec60 100644 --- a/src/suppression_study/evolution/AccidentallySuppressedWarning.py +++ b/src/suppression_study/evolution/AccidentallySuppressedWarning.py @@ -2,16 +2,12 @@ class AccidentallySuppressedWarning: - def __init__(self, summary, previous_commit, commit, previous_suppression, suppression, \ - previous_warnings, warnings, new_warning_hinder): - self.summary = summary + def __init__(self, previous_commit, commit, suppression, previous_warnings, warnings): self.previous_commit = previous_commit self.commit = commit - self.previous_suppression = previous_suppression self.suppression = suppression self.previous_warnings = previous_warnings self.warnings = warnings - self.new_warning_hinder = new_warning_hinder def __lt__(self, other): """Sort based on attributes. Useful for getting a deterministic order when writing to a file.""" @@ -19,8 +15,6 @@ def __lt__(self, other): return self.previous_commit < other.previous_commit elif self.commit != other.commit: return self.commit < other.commit - elif self.previous_suppression != other.previous_suppression: - return self.previous_suppression < other.previous_suppression elif self.suppression != other.suppression: return self.suppression < other.suppression elif self.previous_warnings != other.previous_warnings: @@ -30,22 +24,15 @@ def __lt__(self, other): def to_dict(self): d = { - "summary": self.summary, "previous_commit": self.previous_commit, "commit": self.commit, - "previous_suppression": { - "path": self.previous_suppression.path, - "text": self.previous_suppression.text, - "line": self.previous_suppression.line - }, "suppression": { "path": self.suppression.path, "text": self.suppression.text, "line": self.suppression.line }, "previous_warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.previous_warnings)], - "warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.warnings)], - "new_warning_hinder": self.new_warning_hinder + "warnings": [{"path": w.path, "kind": w.kind, "line": w.line} for w in sorted(self.warnings)] } return d @@ -53,4 +40,4 @@ def to_dict(self): def write_accidentally_suppressed_warnings(accidentally_suppressed_warnings, output_file): with open(output_file, "w") as f: list_of_dicts = [w.to_dict() for w in accidentally_suppressed_warnings] - json.dump(list_of_dicts, f, indent=4) + json.dump(list_of_dicts, f, indent=4) \ No newline at end of file diff --git a/src/suppression_study/evolution/MapWarningLines.py b/src/suppression_study/evolution/MapWarningLines.py index 9a88d6c..fa2024b 100644 --- a/src/suppression_study/evolution/MapWarningLines.py +++ b/src/suppression_study/evolution/MapWarningLines.py @@ -1,6 +1,5 @@ import subprocess -from suppression_study.warnings.Warning import Warning - +# Sept. 12, just keep the file here, but this is not necessary for old experiment setting. class MapWarningLines(): def __init__(self, repo_dir, pre_c, c, pre_warnings, warnings):