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

Formatter for Github Actions - help #894

Open
sidey79 opened this issue Apr 24, 2022 · 1 comment
Open

Formatter for Github Actions - help #894

sidey79 opened this issue Apr 24, 2022 · 1 comment

Comments

@sidey79
Copy link

sidey79 commented Apr 24, 2022

I have a question with the formatter.

Because my tests are getting big and are running in a github action workflow, i was thinking about to optimise the way, they are displayed in github actions.

One thing i was thinking, is using github actions workflow commands to optimise output. Even subtests are a good option for grouping:

https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-setting-a-value

But till now, i was not realy able to extend the existing formater to extend the output.

The other thing i was thinking about is, having the error message in the review section linked to the line where the error occured.
There is a tool, named reviewdog which is capable of doing this. I think it shoud be possible to define the errorformat correctly to the tap output, but till now i had no luck specifying a multiline error format which captures the relevant things.

https://github.com/reviewdog/reviewdog

I found no other aproaches, which confuses me. Are there any other ways to go.

@sidey79
Copy link
Author

sidey79 commented Oct 23, 2022

@exodist

I'am still struggeling with grouping the output.

I was able to extend the TAP formatter, which is a good point to start.

package Test2::Formatter::gha;
use strict;
use warnings;
use strict;
use parent 'Test2::Formatter::TAP';
use Test2::Util::HashBase qw{
    no_numbers handles _encoding _last_fh
    -made_assertion
};

my $groupOpen = 0;

sub terminate { 
    $groupOpen ? _closeGroup() : undef;
    return shift->SUPER::terminate(@_);
}
 
sub finalize { 
    
    $groupOpen ? _closeGroup() : undef;
    return shift->SUPER::finalize(@_);
}

sub write {
    my ($self, $e, $num, $f) = @_;
    
    $f ||= $e->facet_data;
    use Data::Dumper;
    print Dumper ($e);

    $groupOpen ? undef : _openGroup() ; 
    my $handles = $self->{+HANDLES};

    # call the original write method
    return shift->SUPER::write(@_);
}

sub _closeGroup
{
    print q[::endgroup::] . "\n";
    $groupOpen = 0;
}

sub _openGroup
{
    $groupOpen = 1 ;
    print q[::group::<groupname>] . "\n"
}

1;

Overall this adds ::group::<groupname> at the beginning of the tests.
At the end, it brings in ::endgroup::.

What i sill need, is a name of a group. I have some ideas, but don't know how to solve them:

  1. get the name of a testfile and use this as the groupname
  2. Introduce some new event type or similar, to specify the grouping. This needs modifications for all tests :(
  3. similar as one but extended with informations from the summary. So we need to store all output and print it, as soon we have the summary.

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

No branches or pull requests

1 participant