Skip to content

Commit

Permalink
test: added tests for known bugs
Browse files Browse the repository at this point in the history
Added tests for issues #224/#225 and #229. Since
these are known bugs, the tests are currently
marked as expected failures. Once the solution
is implemented, that designation can be removed
and we'll still keep the test to make sure there
aren't any regressions.
  • Loading branch information
rgalonso committed Nov 10, 2024
1 parent 30b3d43 commit 2997380
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def process_diff(diff, client=Client(), insert_issue_urls=False, parser=TodoPars
# Stagger the requests to be on the safe side.
sleep(1)

return raw_issues


if __name__ == "__main__":
client: Client | None = None
# Try to create a basic client for communicating with the remote version control server, automatically initialised with environment variables.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_comment_suffix_after_source_line.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/comment_suffix_after_source_line.c b/comment_suffix_after_source_line.c
new file mode 100644
index 0000000..d340f6a
--- /dev/null
+++ b/comment_suffix_after_source_line.c
@@ -0,0 +1,4 @@
+void some_func() {
+ int x = 0; // TODO: give this a better name
+ x++;
+}
42 changes: 41 additions & 1 deletion tests/test_process_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
import subprocess
import io
import re

from TodoParser import TodoParser
from main import process_diff
Expand Down Expand Up @@ -41,7 +42,7 @@ def _standardTest(self, expected_count):
# create object to hold output
output = io.StringIO()
# process the diffs
process_diff(diff=self.diff_file, insert_issue_urls=True, parser=self.parser, output=output)
self.raw_issues = process_diff(diff=self.diff_file, insert_issue_urls=True, parser=self.parser, output=output)
# make sure the number of issue URL comments inserted is as expected
self.assertEqual(output.getvalue().count('Issue URL successfully inserted'),
expected_count,
Expand All @@ -56,11 +57,50 @@ def test_url_insertion(self):
self._setUp('test_new.diff')
self._standardTest(80)

# There is a known bug related to this issue, so until it's resolved
# this is an expected failure.
# See #225 and #224
@unittest.expectedFailure
def test_same_title_in_same_file(self):
self._setUp('test_same_title_in_same_file.diff')
self._standardTest(5)

# There is a known bug related to this issue, so until it's resolved
# this is an expected failure.
# See #229
@unittest.expectedFailure
def test_comment_suffix_after_source_line(self):
self._setUp('test_comment_suffix_after_source_line.diff')
self._standardTest(1)
# get details about the issue and source file
issue = self.raw_issues[0]
markers, _ = self.parser._get_file_details(issue.file_name)
with open(f'{self.tempdir.name}/{issue.file_name}', 'r') as source_file:
lines = source_file.read().splitlines()
# regex search the TODO comment and issue URL lines, such that groups are:
# 2: everything from start of line up to (but excluding) comment marker
# 3: comment marker
# 4: anything after comment marker and before identifier
# 1: encompasses all of the above
source_and_todo_line = re.search(fr'^((.*?)({markers[0]["pattern"]})(.*?))(?i:{issue.identifier}).*?{issue.title}',
lines[issue.start_line-1]).groups()
issue_url_line = re.search(fr'^((.*?)({markers[0]["pattern"]})(\s*))Issue URL: N/A$',
lines[issue.start_line]).groups()
# ensure Issue URL is aligned with the TODO above it by verifying
# that length of first group is equal for both lines
self.assertEqual(len(source_and_todo_line[0]), len(issue_url_line[0]), msg='\n'
+ f'Issue URL mis-alignment. {issue.identifier} begins at column '
+ f'{len(source_and_todo_line[0])+1} but\nissue URL begins at column '
+ f'{len(issue_url_line[0])+1}.\n'
+ '-------------------------------------------------------------------\n'
+ f'{lines[issue.start_line-1]}\n'
+ f'{lines[issue.start_line]}\n')
# ensure Issue URL line has only whitespace before the comment marker
self.assertRegex(issue_url_line[1], r'^\s*$', msg='\n'
+ 'Non-whitespace detected prior to comment marker for issue URL line!\n'
+ '-------------------------------------------------------------------\n'
+ f'{lines[issue.start_line]}\n')

def tearDown(self):
# return to original working directory to ensure we don't mess up other tests
os.chdir(self.orig_cwd)
Expand Down

0 comments on commit 2997380

Please sign in to comment.