App-Project-Doctor

 view release on metacpan or  search on metacpan

t/function.t  view on Meta::CPAN

		_make_finding(
			severity   => $INFO_SEV,
			message    => 'note',
			check_name => 'Meta',
			fix        => sub {},
		),
	);
	my $json = $r->render_json;
	returns_ok($json, { type => 'scalar' }, 'render_json returns a scalar');
	require JSON::MaybeXS;
	my $decoded = JSON::MaybeXS->new->decode($json);
	is ref $decoded, 'ARRAY', 'decodes to arrayref';
	ok !exists $decoded->[0]{fix}, 'fix not serialised';
	is $decoded->[0]{check_name}, 'Meta', 'check_name present';
};

subtest 'Report::render_tap -- plan and ok/not-ok lines' => sub {
	my $r = _make_report(
		_make_finding(severity => $PASS_SEV, message => 'good', check_name => 'A'),
		_make_finding(severity => $INFO_SEV, message => 'info', check_name => 'B'),
		_make_finding(severity => $ERR_SEV,  message => 'bad',  check_name => 'C'),
		_make_finding(severity => $WARN_SEV, message => 'warn', check_name => 'D'),
	);
	my $tap = $r->render_tap;

t/integration.t  view on Meta::CPAN

		message    => 'A JSON finding',
		detail     => 'some detail',
		check_name => 'TestCheck',
		file       => 'lib/T.pm',
		line       => 42,
		fix        => sub { 1 },
	));

	require JSON::MaybeXS;
	my $json_str = $report->render_json;
	my $decoded  = JSON::MaybeXS->new->decode($json_str);

	ok( ref $decoded eq 'ARRAY',            'decoded JSON is an array' );
	is( scalar @{$decoded}, 1,              'one element in array' );
	is( $decoded->[0]{severity},   'error', 'severity key correct' );
	is( $decoded->[0]{message}, 'A JSON finding', 'message key correct' );
	is( $decoded->[0]{check_name}, 'TestCheck',   'check_name key correct' );
	is( $decoded->[0]{file},       'lib/T.pm',    'file key correct' );
	is( $decoded->[0]{line},       42,             'line key correct' );
	ok( !exists $decoded->[0]{fix},                'fix coderef excluded from JSON output' );

	diag $json_str if $ENV{TEST_VERBOSE};
};

# ─────────────────────────────────────────────────────────────────────────────
# 3. OPTIONAL DEPENDENCY: JSON::MaybeXS
# Strategy: mock_scoped replaces JSON::MaybeXS::new with a sub that throws,
# simulating the module being unavailable. This is more portable than
# Test::Without::Module + INC manipulation, which behaves differently across
# Perl versions (runtime eval of 'use' does not reliably install the @INC hook).

t/unit.t  view on Meta::CPAN

	my $r = App::Project::Doctor::Report->new;
	$r->add_findings(_f(
		severity   => $SEV_INFO,
		message    => 'noted',
		check_name => 'Meta',
		fix        => sub {},
	));
	my $json = $r->render_json;
	returns_ok($json, { type => 'scalar' }, 'render_json returns scalar');
	require JSON::MaybeXS;
	my $decoded = JSON::MaybeXS->new->decode($json);
	is ref $decoded, 'ARRAY', 'decodes to arrayref';
	ok !exists $decoded->[0]{fix},        'fix key absent from JSON';
	is $decoded->[0]{severity},   'info', 'severity in JSON';
	is $decoded->[0]{check_name}, 'Meta', 'check_name in JSON';
};

subtest 'Report::render_tap -- plan line; pass/info = ok, error/warning = not ok' => sub {
	# POD: "Returns a TAP-format string for CI pipeline consumption."
	my $r = App::Project::Doctor::Report->new;
	$r->add_findings(
		_f(severity => $SEV_PASS,  message => 'p', check_name => 'A'),
		_f(severity => $SEV_INFO,  message => 'i', check_name => 'B'),
		_f(severity => $SEV_WARN,  message => 'w', check_name => 'C'),
		_f(severity => $SEV_ERROR, message => 'e', check_name => 'D'),



( run in 0.476 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )