Skip to content

Commit b77f68c

Browse files
committed
Wip
1 parent 8b8cedf commit b77f68c

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

split-minimal-tests.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python3
2+
3+
"""split-minimal-tests
4+
This script splits HTML minimal-tests, produced by a software called
5+
`json-minimal-tests`, into distinct directories depending on metric differences.
6+
7+
Usage:
8+
9+
./split-minimal-tests.py -i INPUT_DIR -o OUTPUT_DIR_NAME [-t MT_THRESHOLD]
10+
11+
NOTE: OUTPUT_DIR_NAME is the name of the output directory.
12+
This directory could contain either a series of directories, called as
13+
the metrics that presents differences, or be empty if no metric differences
14+
are found.
15+
MT_THRESHOLD determines the maximum number of considered minimal tests
16+
for a metric.
17+
"""
18+
19+
import argparse
20+
import pathlib
21+
import shutil
22+
import typing as T
23+
24+
# List of metrics
25+
# TODO: Implement a command into rust-code-analysis-cli that returns all
26+
# computed metrics https://github.com/mozilla/rust-code-analysis/issues/478
27+
METRICS = [
28+
"cognitive",
29+
"sloc",
30+
"ploc",
31+
"lloc",
32+
"cloc",
33+
"blank",
34+
"cyclomatic",
35+
"halstead",
36+
"nom",
37+
"nexits",
38+
"nargs",
39+
]
40+
41+
42+
# Retrieve HTML minimal-tests containing differences for a determined metric
43+
def retrieve_metric_mt(args: argparse.Namespace) -> T.List[pathlib.Path]:
44+
return []
45+
46+
47+
def main() -> None:
48+
parser = argparse.ArgumentParser(
49+
prog="split-minimal-tests",
50+
description="This tool splits HTML minimal-tests, produced by "
51+
"a software called `json-minimal-tests`, into distinct directories "
52+
"depending on metric differences.",
53+
epilog="The source code of this program can be found on "
54+
"GitHub at https://github.com/mozilla/rust-code-analysis",
55+
)
56+
57+
# Arguments
58+
parser.add_argument(
59+
"--input",
60+
"-i",
61+
type=lambda value: pathlib.Path(value),
62+
required=True,
63+
help="Input directory containing HTML minimal tests.",
64+
)
65+
66+
parser.add_argument(
67+
"--output-name",
68+
"-o",
69+
type=str,
70+
required=True,
71+
help="Name of the output directory.",
72+
)
73+
74+
# Optional arguments
75+
parser.add_argument(
76+
"--threshold",
77+
"-t",
78+
type=int,
79+
required=True,
80+
help="Maximum number of considered minimal tests for a metric.",
81+
)
82+
83+
# Parse arguments
84+
args = parser.parse_args()
85+
86+
# Create output directory
87+
output_dir = pathlib.Path(args.output_name)
88+
output_dir.mkdir(parents=True, exist_ok=True)
89+
90+
# Iterate over metrics
91+
for metric in METRICS:
92+
93+
# Minimal tests containing differences for the analyzed metric
94+
minimal_tests = retrieve_metric_mt(args)
95+
96+
# Create metric directory
97+
metric_dir = output_dir / metric
98+
metric_dir.mkdir(parents=True, exist_ok=True)
99+
100+
# Copy minimal tests in the relative metric directory
101+
for minimal_test in minimal_tests:
102+
shutil.copy(minimal_test, metric_dir)
103+
104+
105+
if __name__ == "__main__":
106+
main()

0 commit comments

Comments
 (0)