App-Test-Generator

 view release on metacpan or  search on metacpan

bin/test-generator-index  view on Meta::CPAN


	if($config{lcsaj_hits_file} && -f $config{lcsaj_hits_file}) {
		open my $lfh, '<', $config{lcsaj_hits_file};
		$lcsaj_hits = decode_json(do { local $/; <$lfh> });
		close $lfh;
	}

	my $files = _group_by_file($mutation_db);

	push @html, @{_mutation_index($mutation_db, $files, $cover_db, $config{lcsaj_root}, $lcsaj_hits)};

	# Pre-sort files worst-first so navigation order matches index order
	my @sorted_files = sort { _file_score($files->{$a}) <=> _file_score($files->{$b}) || $a cmp $b } keys %$files;

	for my $i (0 .. $#sorted_files) {
		my $file = $sorted_files[$i];

		# Only assign previous if this is NOT the first file
		my $prev = $i > 0 ? $sorted_files[$i - 1] : undef;

		# Only assign next if this is NOT the last file
		my $next = $i < $#sorted_files ? $sorted_files[$i + 1] : undef;

		_mutant_file_report($config{mutation_output_dir}, $file, $files->{$file}, $prev, $next, $cover_db, $config{lcsaj_root}, $lcsaj_hits);
	}
}

my $timestamp = 'Unknown';
if(my $stat = stat($config{cover_db})) {
	$timestamp = strftime('%Y-%m-%d %H:%M:%S', localtime($stat->mtime));
}

# Get ATG version for dashboard footer — search @INC for the installed module
my $atg_version = 'unknown';
my $module_file = $INC{'App/Test/Generator.pm'};
unless($module_file) {
	# Module not yet loaded; search @INC directly
	for my $dir (@INC) {
		my $candidate = "$dir/App/Test/Generator.pm";
		if(-f $candidate) {
			$module_file = $candidate;
			last;
		}
	}
}

# Fall back to the source tree path for ATG's own development environment
$module_file //= $config{module_file};
if($module_file && open(my $fh, '<', $module_file)) {
	while(<$fh>) {
		if(/our\s+\$VERSION\s*=\s*['"]([^'"]+)['"]/) {
			$atg_version = $1;
			last;
		}
	}
	close $fh;
}

push @html, '<footer>',
	"\t<p>Project: <a href=\"https://github.com/$config{github_user}/$config{github_repo}\">$config{github_repo}</a></p>",
	"\t<p><em>Last updated: $timestamp - <a href=\"$commit_url\">commit <code>$short_sha</code></a></em></p>",
	"\t<p style=\"float: right; font-size: 0.85em; color: #999;\">Powered by <a href=\"https://metacpan.org/dist/App-Test-Generator\">App::Test::Generator $atg_version</a></p>",
	'</footer>';

push @html, '</body>', '</html>';

# Write to index.html
print "Writing output to $config{output}\n" if($config{verbose});
write_file($config{output}, join("\n", @html));

# Generate mutant test stubs only if --generate_mutant_tests=dir was given.
# This is opt-in to avoid surprising existing pipelines with new files.
if($mutation_db && $mutant_test_dir) {
	_generate_mutant_tests($mutation_db, $cover_db, $mutant_test_dir, $generate_test);
}

# Generate fuzz schema augmentations from surviving mutants
# if --generate_fuzz was passed on the command line
if($mutation_db && $generate_fuzz) {
	_generate_fuzz_schemas($mutation_db, 't');
}

# --------------------------------------------------
# run_git
#
# Purpose:    Execute a git command safely and return
#             its stdout, or undef on failure.
#
# Entry:      @cmd - list of git subcommand and args
#             to pass directly to git.
#
# Exit:       Returns the chomped stdout string on
#             success, or undef if the command exits
#             non-zero.
#
# Side effects: Forks a child process. Discards stderr.
#
# Notes:      Uses IPC::Run3 to capture output without
#             a shell, avoiding injection risks from
#             user-supplied filenames.
# --------------------------------------------------
sub run_git {
	my @cmd = @_;
	my ($out, $err);
	run3 ['git', @cmd], \undef, \$out, \$err;
	return unless $? == 0;
	chomp $out;
	return $out;
}

# --------------------------------------------------
# js_escape
#
# Purpose:    Escape a string for safe embedding in a
#             JavaScript double-quoted string literal
#             in generated HTML.
#
# Entry:      $str - the string to escape.
#
# Exit:       Returns the escaped string. Backslashes
#             are doubled, double quotes are escaped,



( run in 0.386 second using v1.01-cache-2.11-cpan-bbe5e583499 )