-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""split-minimal-tests | ||
This script splits HTML minimal-tests, produced by a software called | ||
`json-minimal-tests`, into distinct directories depending on metric differences. | ||
Usage: | ||
./split-minimal-tests.py -i INPUT_DIR -o OUTPUT_DIR_NAME [-t MT_THRESHOLD] | ||
NOTE: OUTPUT_DIR_NAME is the name of the output directory. | ||
This directory could contain either a series of directories, called as | ||
the metrics that presents differences, or be empty if no metric differences | ||
are found. | ||
MT_THRESHOLD determines the maximum number of considered minimal tests | ||
for a metric. | ||
""" | ||
|
||
import argparse | ||
import pathlib | ||
import shutil | ||
import typing as T | ||
|
||
# List of metrics | ||
# TODO: Implement a command into rust-code-analysis-cli that returns all | ||
# computed metrics https://github.com/mozilla/rust-code-analysis/issues/478 | ||
METRICS = [ | ||
"cognitive", | ||
"sloc", | ||
"ploc", | ||
"lloc", | ||
"cloc", | ||
"blank", | ||
"cyclomatic", | ||
"halstead", | ||
"nom", | ||
"nexits", | ||
"nargs", | ||
] | ||
|
||
|
||
# Retrieve HTML minimal-tests containing differences for a determined metric | ||
def retrieve_metric_mt(args: argparse.Namespace) -> T.List[pathlib.Path]: | ||
return [] | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser( | ||
prog="split-minimal-tests", | ||
description="This tool splits HTML minimal-tests, produced by " | ||
"a software called `json-minimal-tests`, into distinct directories " | ||
"depending on metric differences.", | ||
epilog="The source code of this program can be found on " | ||
"GitHub at https://github.com/mozilla/rust-code-analysis", | ||
) | ||
|
||
# Arguments | ||
parser.add_argument( | ||
"--input", | ||
"-i", | ||
type=lambda value: pathlib.Path(value), | ||
required=True, | ||
help="Input directory containing HTML minimal tests.", | ||
) | ||
|
||
parser.add_argument( | ||
"--output-name", | ||
"-o", | ||
type=str, | ||
required=True, | ||
help="Name of the output directory.", | ||
) | ||
|
||
# Optional arguments | ||
parser.add_argument( | ||
"--threshold", | ||
"-t", | ||
type=int, | ||
required=True, | ||
help="Maximum number of considered minimal tests for a metric.", | ||
) | ||
|
||
# Parse arguments | ||
args = parser.parse_args() | ||
|
||
# Create output directory | ||
output_dir = pathlib.Path(args.output_name) | ||
output_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Iterate over metrics | ||
for metric in METRICS: | ||
|
||
# Minimal tests containing differences for the analyzed metric | ||
minimal_tests = retrieve_metric_mt(args) | ||
|
||
# Create metric directory | ||
metric_dir = output_dir / metric | ||
metric_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Copy minimal tests in the relative metric directory | ||
for minimal_test in minimal_tests: | ||
shutil.copy(minimal_test, metric_dir) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |