Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed Apr 16, 2021
1 parent 8b8cedf commit b77f68c
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions split-minimal-tests.py
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()

0 comments on commit b77f68c

Please sign in to comment.