diff options
author | Gabriel F. T. Gomes <gabriel@inconstante.net.br> | 2019-08-07 09:17:13 -0300 |
---|---|---|
committer | Gabriel F. T. Gomes <gabriel@inconstante.net.br> | 2019-08-07 09:17:13 -0300 |
commit | 5732da2af736c40cf693354485446ab4867ecb4d (patch) | |
tree | 76d76cdfa16ca62d20fb109da13895ec64fff110 /test/generate | |
parent | 9cd22d1df8f0f5b554858471c86faa9f37b8fed4 (diff) | |
download | bash-completion-5732da2af736c40cf693354485446ab4867ecb4d.tar.gz |
New upstream version 2.9upstream/2.9
Diffstat (limited to 'test/generate')
-rwxr-xr-x | test/generate | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/test/generate b/test/generate index deeba05a..59f525b7 100755 --- a/test/generate +++ b/test/generate @@ -1,64 +1,60 @@ -#!/bin/bash -eu -# Generate skeleton files for completion of specified command. -# Test skeleton files are generated as well. -# @param $1 string Command, e.g. 'make' -# @param $2 string Completion function, e.g. _command -# @param $3 string Completion arguments, e.g. '-o filenames' - - -# Generate test code -# @param $1 string Command, e.g. 'make' -generate_test_completion() { - local path="completion/$1.exp" - # Does file already exist? - #if [ ! -f "$path" ]; then - # No, file doesn't exist; generate file - cat <<EXPECT > "$path" -assert_source_completions $1 -EXPECT - #fi -} # generate_test_completion() - - -# Generate test code -# @param $1 string Command, e.g. 'make' -# @param $2 string Completion function, e.g. _command -# @param $3 string Completion arguments, e.g. ' -o filenames' -generate_test_lib_completions() { - local path="lib/completions/$1.exp" - # Does file already exist? - #if [ ! -f "$path" ]; then - # No, file doesn't exist; generate file - cat <<EXPECT > "$path" -proc setup {} { - save_env -} - - -proc teardown {} { - assert_env_unmodified -} - - -setup - - -assert_complete_any "$1 " -sync_after_int - - -teardown -EXPECT - #fi -} # generate_test_lib_completions() - - - # If argument count is wrong, show help -if [ $# -ne 1 ]; then - echo "Usage: $0 command" - echo "Example: $0 make" - exit 1 -fi - -generate_test_completion "$1" -generate_test_lib_completions "$1" +#!/usr/bin/env python3 + +# Generate skeleton files for completion of specified command + +import fileinput +import re +import sys + + +def main(): + if len(sys.argv) < 2: + print("Usage: %s command [args...]" % sys.argv[0], file=sys.stderr) + sys.exit(1) + + cmd = testfile = sys.argv[1] + args = " ".join(sys.argv[2:]) if len(sys.argv) > 2 else "" + marker = "" + if re.search("[.+-]", cmd): + testfile = re.sub("[.-]", "_", cmd).replace("+", "plus") + marker = '\n@pytest.mark.bashcomp(\n cmd="%s",\n)' % cmd + testfile = "test_%s.py" % testfile + name = re.sub("(^|[_-]+)(.)", lambda m: m.group(2).upper(), cmd) + name = name.replace("+", "Plus") + + with open("t/%s" % testfile, "w") as f: + print( + """\ +import pytest + +%s +class Test%s: + @pytest.mark.complete("%s %s") + def test_1(self, completion): + assert completion""" + % (marker, name, cmd, args), + file=f, + ) + + in_extra_dist = False + extra_dist_lines = set() + with fileinput.input(files=("t/Makefile.am"), inplace=True) as f: + for line in f: + if line.startswith("EXTRA_DIST "): + in_extra_dist = True + elif in_extra_dist: + if line.startswith("\t"): + line = line.strip() + if not line.endswith("\\"): + line += " \\" + extra_dist_lines.add(line) + continue + extra_dist_lines.add("%s \\" % testfile) + sys.stdout.write("\t") + print("\n\t".join(sorted(extra_dist_lines))[:-2]) + in_extra_dist = False + sys.stdout.write(line) + + +if __name__ == "__main__": + main() |