Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include filename and line number (closes #10) #11

Closed
wants to merge 1 commit into from

Conversation

dmavrommatis
Copy link

@dmavrommatis dmavrommatis commented Oct 8, 2024

Addressing #10

The failed tests usually have the filename and the line number at the start of the printed message.

This PR uses a regex matcher to find that information and add it to the generated CTRF json.

cat ctrf-report.json 
{
  "results": {
    "tool": {
      "name": "gotest"
    },
    "summary": {
      "tests": 1,
      "passed": 0,
      "failed": 1,
      "pending": 0,
      "skipped": 0,
      "other": 0,
      "start": 1728408248844,
      "stop": 1728408248844
    },
    "tests": [
      {
        "name": "Test",
        "status": "failed",
        "duration": 0,
        "suite": "command-line-arguments",
        "message": "=== RUN   Test\n    whatever_test.go:156: \n        \tError Trace:\t/home/dmavrommatis/workspace/whatever_test.go:156\n        \tError:      \tWomp womp\n        \tTest:       \tTest\n--- FAIL: Test (0.00s)\n",
        "trace": "whatever_test.go:156",
        "filepath": "whatever_test.go:156"
      }
    ]
  }
}

@dmavrommatis
Copy link
Author

I see the trace and path being set correctly but I still do not see the annotation being created correctly. which field is passed to the annotation? trace or filepath?

and does it do any glob find in the repository to find the file or not?

@Ma11hewThomas Ma11hewThomas requested a review from asherf October 8, 2024 18:41
@@ -20,6 +21,8 @@ type TestEvent struct {
Output string
}

var filenameMatcher = regexp.MustCompile(`([a-zA-Z0-9_/]+\.go):(\d+)`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using a regex named group capture here will make the code more readable and easier to maintain over time.

@asherf
Copy link
Collaborator

asherf commented Oct 8, 2024

readme needs to be updated to indicate we populate this new field.
https://github.com/ctrf-io/go-ctrf-json-reporter/blob/main/README.md#test-object-properties

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11241118650

Details

  • 0 of 10 (0.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-1.1%) to 36.131%

Changes Missing Coverage Covered Lines Changed/Added Lines %
reporter/reporter.go 0 10 0.0%
Files with Coverage Reduction New Missed Lines %
reporter/reporter.go 1 0.0%
Totals Coverage Status
Change from base Build 10888553733: -1.1%
Covered Lines: 99
Relevant Lines: 274

💛 - Coveralls

@dmavrommatis
Copy link
Author

will address the comments when I find some time

@dmavrommatis
Copy link
Author

I tested this and the annotations created by the CTRF reporter afterwards are still not working correctly (maybe it will work with -fullpath but haven't tried).

Unfortunately I do not have much time to work on this so I will close the PR for now until someone else picks it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants