Skip to content

Commit

Permalink
feat: watch mode for test
Browse files Browse the repository at this point in the history
  • Loading branch information
nullishamy committed Oct 28, 2023
1 parent 6ab33da commit c013564
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def make_parser():

parser.add_argument('--verbose', '-v', action='store_true')
parser.add_argument('--filter', '-f', default=".*")
parser.add_argument('--watch', '-w', action='store_true')

return parser

Expand Down Expand Up @@ -136,34 +137,43 @@ async def run_for_source(source_location):

async def main():
args = make_parser().parse_args()
print(f'{Colours.GREEN}building...{Colours.END}')
build = await run_cmd("cargo build", args.verbose)
build = await build.wait()
if build != 0:
await display_failure(build, "build")
return

print(f'{Colours.GREEN}cleaning...{Colours.END}')
clean = await run_cmd(f'rm -rf {TEMP_DIR}', args.verbose)
clean = await clean.wait()
if clean != 0:
await display_failure(clean, "clean")
return

print(f'{Colours.GREEN}pre-run steps ok{Colours.END}')
print()
print(f'{Colours.GREEN}running...{Colours.END}')
print()

start = time.time()
passes, fails = await run_tests(filter_sources(get_sources(['java']), args.filter), args)
end = time.time()
duration = end - start

print()
print()
print(f'{Colours.PEACH}testing concluded{Colours.END} ({round(duration, 3)}s)')
print(f'{Colours.GREEN}pass:{Colours.END} {len(passes)} - {Colours.RED}fail:{Colours.END} {len(fails)}')
while True:
print(f'{Colours.GREEN}building...{Colours.END}')
build = await run_cmd("cargo build", args.verbose)
build = await build.wait()
if build != 0:
await display_failure(build, "build")
return

print(f'{Colours.GREEN}cleaning...{Colours.END}')
clean = await run_cmd(f'rm -rf {TEMP_DIR}', args.verbose)
clean = await clean.wait()
if clean != 0:
await display_failure(clean, "clean")
return

print(f'{Colours.GREEN}pre-run steps ok{Colours.END}')
print()
print(f'{Colours.GREEN}running...{Colours.END}')
print()

start = time.time()
passes, fails = await run_tests(filter_sources(get_sources(['java']), args.filter), args)
end = time.time()
duration = end - start

print()
print()
print(f'{Colours.PEACH}testing concluded{Colours.END} ({round(duration, 3)}s)')
print(f'{Colours.GREEN}pass:{Colours.END} {len(passes)} - {Colours.RED}fail:{Colours.END} {len(fails)}')

input("Press any key to rerun: ")
# Do-while emulation
if not args.watch:
break

if __name__ == '__main__':
asyncio.run(main())
try:
asyncio.run(main())
except KeyboardInterrupt:
exit(0)

0 comments on commit c013564

Please sign in to comment.