]> Witch of Git - ivy/blob - tools/test.py
[tools] Add tools/test.py as the project test runner
[ivy] / tools / test.py
1 #!/usr/bin/env python3
2 import argparse
3 import os
4 import subprocess
5 import sys
6 from pathlib import Path
7
8 from fmt import blue, yellow
9
10 ROOT = Path(__file__).parent.parent
11
12
13 def header(msg):
14 print(blue(msg))
15
16
17 def label(msg):
18 print(yellow(msg))
19
20
21 def cmd(*args):
22 print(" ".join(args))
23 subprocess.run(args, check=True)
24
25
26 def main():
27 parser = argparse.ArgumentParser(
28 description="""Run tests for the project
29
30 If no flags are specified, run all tests.
31 """
32 )
33 parser.add_argument("--compiler", action="store_true")
34 parser.add_argument("--runtime", action="store_true")
35 parser.add_argument("--filetest", action="store_true")
36 parser.add_argument("--python", action="store_true")
37 args = parser.parse_args()
38
39 do_all = not any(vars(args).values())
40 if do_all:
41 for k in vars(args):
42 vars(args)[k] = True
43
44 os.chdir(ROOT)
45
46 # Building and testing the compiler
47 if args.compiler:
48 header("Compiler...")
49
50 label("Format...")
51 cmd("cargo", "fmt", "--", "--check")
52
53 label("Test...")
54 cmd("cargo", "test", "--quiet")
55
56 if args.filetest:
57 label("Build...")
58 cmd("cargo", "build", "--release", "--all")
59 elif args.filetest:
60 header("Build compiler...")
61 cmd("cargo", "build", "--release", "--all")
62
63 # Building and testing the runtime
64 os.chdir("rt")
65 if args.runtime:
66 header("Runtime...")
67
68 label("Format...")
69 cmd("cargo", "fmt", "--", "--check")
70
71 label("Test...")
72 cmd("cargo", "test", "--quiet")
73
74 if args.filetest:
75 label("Build...")
76 cmd("cargo", "build", "--release", "--all")
77 elif args.filetest:
78 header("Build runtime...")
79 cmd("cargo", "build", "--release", "--all")
80 os.chdir(ROOT)
81
82 # Filetests
83 if args.filetest:
84 header("Filetests...")
85
86 label("Lit...")
87 cmd("tools/lit.py", "ivy-examples/", "test/")
88
89 # Linting the Python scripts
90 if args.python:
91 header("Python...")
92
93 label("Black...")
94 cmd("black", "test/", "--check", "--diff", "--color")
95
96 label("isort...")
97 cmd("isort", "test/", "--check", "--diff", "--color")
98
99
100 if __name__ == "__main__":
101 try:
102 main()
103 except Exception as e:
104 print(e)
105 sys.exit(1)