-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert wrapper test binary to Python.
This removes a dependency on the non-builtin Go rules.
- Loading branch information
Showing
4 changed files
with
105 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Copyright 2020, 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Binary wrap is a test helper program for //elisp:binary_test, which see.""" | ||
|
||
import argparse | ||
import json | ||
import os | ||
import pathlib | ||
import unittest | ||
import sys | ||
from typing import Any, Dict, List | ||
|
||
from phst_rules_elisp.elisp import runfiles | ||
|
||
def _main() -> None: | ||
print('Args:', sys.argv) | ||
print('Environment:', os.environ) | ||
parser = argparse.ArgumentParser(allow_abbrev=False) | ||
parser.add_argument('--manifest', type=pathlib.Path, required=True) | ||
parser.add_argument('rest', nargs='+') | ||
args = parser.parse_args() | ||
run_files = runfiles.Runfiles() | ||
output_file = pathlib.PurePath( | ||
r'C:\Temp\output.dat' if os.name == 'nt' else '/tmp/output.dat') | ||
|
||
class Test(unittest.TestCase): | ||
"""Unit tests for the command line and manifest.""" | ||
|
||
maxDiff = 5000 | ||
|
||
def test_args(self) -> None: | ||
"""Test that the Emacs command line is as expected.""" | ||
got = args.rest | ||
want = ['--quick', '--batch'] | ||
# The load path setup depends on whether we use manifest-based or | ||
# directory-based runfiles. | ||
try: | ||
directory = run_files.resolve( | ||
pathlib.PurePosixPath('phst_rules_elisp')) | ||
except FileNotFoundError: | ||
# Manifest-based runfiles. | ||
want += [ | ||
'--load=' + str(run_files.resolve(pathlib.PurePosixPath( | ||
'phst_rules_elisp/elisp/runfiles/runfiles.elc'))), | ||
'--funcall=elisp/runfiles/install-handler', | ||
'--directory=/bazel-runfile:phst_rules_elisp', | ||
] | ||
else: | ||
# Directory-based runfiles. | ||
want.append('--directory=' + str(directory)) | ||
want += [ | ||
'--option', | ||
str(run_files.resolve(pathlib.PurePosixPath( | ||
'phst_rules_elisp/elisp/binary.cc'))), | ||
' \t\n\r\f äα𝐴🐈\'\\"', | ||
'/:' + str(output_file), | ||
] | ||
self.assertListEqual(got, want) | ||
|
||
def test_manifest(self) -> None: | ||
"""Test the manifest.""" | ||
got = json.loads(args.manifest.read_text(encoding='utf-8')) | ||
want = { | ||
'root': 'RUNFILES_ROOT', | ||
'tags': ['local', 'mytag'], | ||
'loadPath': ['phst_rules_elisp'], | ||
'inputFiles': ['phst_rules_elisp/elisp/binary.cc', | ||
'phst_rules_elisp/elisp/binary.h'], | ||
'outputFiles': [str(output_file)], | ||
} # type: Dict[str, Any] | ||
for var in (got, want): | ||
files = var.get('inputFiles', []) # type: List[str] | ||
for i, file in enumerate(files): | ||
file = pathlib.PurePosixPath(file) | ||
if not file.is_absolute(): | ||
files[i] = str(run_files.resolve(file)) | ||
self.assertDictEqual(got, want) | ||
|
||
tests = unittest.defaultTestLoader.loadTestsFromTestCase(Test) | ||
if not unittest.TextTestRunner().run(tests).wasSuccessful(): | ||
raise ValueError('incorrect arguments') | ||
|
||
if __name__ == '__main__': | ||
_main() |