1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#!/usr/bin/env vpython3
# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import tempfile
import unittest
# vpython-provided modules.
from pyfakefs import fake_filesystem_unittest # pylint: disable=import-error
from generate_script import _parse_args
from generate_script import _generate_script
class Tests(fake_filesystem_unittest.TestCase):
def test_parse_args(self):
raw_args = [
'--script-path=./bin/run_foobar', '--exe-dir=.',
'--rust-test-executables=metadata.json'
]
parsed_args = _parse_args(raw_args)
self.assertEqual('./bin/run_foobar', parsed_args.script_path)
self.assertEqual('.', parsed_args.exe_dir)
self.assertEqual('metadata.json', parsed_args.rust_test_executables)
def test_generate_script(self):
lib_dir = os.path.dirname(__file__)
out_dir = os.path.join(lib_dir, '../../../out/rust')
args = type('', (), {})()
args.make_bat = False
args.script_path = os.path.join(out_dir, 'bin/run_foo_bar')
args.exe_dir = out_dir
# pylint: disable=unexpected-keyword-arg
with tempfile.NamedTemporaryFile(delete=False,
mode='w',
encoding='utf-8') as f:
filepath = f.name
f.write('foo\n')
f.write('bar\n')
try:
args.rust_test_executables = filepath
actual = _generate_script(args,
should_validate_if_exes_exist=False)
finally:
os.remove(filepath)
expected = """
#!/bin/bash
env vpython3 \
"$(dirname $0)/../../../testing/scripts/rust/rust_main_program.py" \\
"--rust-test-executable=$(dirname $0)/../bar" \\
"--rust-test-executable=$(dirname $0)/../foo" \\
"$@"
""".strip()
self.assertEqual(expected, actual)
def test_generate_bat(self):
lib_dir = os.path.dirname(__file__)
out_dir = os.path.join(lib_dir, '../../../out/rust')
args = type('', (), {})()
args.make_bat = True
args.script_path = os.path.join(out_dir, 'bin/run_foo_bar')
args.exe_dir = out_dir
# pylint: disable=unexpected-keyword-arg
with tempfile.NamedTemporaryFile(delete=False,
mode='w',
encoding='utf-8') as f:
filepath = f.name
f.write('foo\n')
f.write('bar\n')
try:
args.rust_test_executables = filepath
actual = _generate_script(args,
should_validate_if_exes_exist=False)
finally:
os.remove(filepath)
expected = """
@echo off
vpython3 "%~dp0\\../../../testing/scripts/rust\\rust_main_program.py" ^
"--rust-test-executable=%~dp0\\..\\bar.exe" ^
"--rust-test-executable=%~dp0\\..\\foo.exe" ^
%*
""".strip()
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()
|