Skip to content

Commit

Permalink
psh: autocompletion test improvements
Browse files Browse the repository at this point in the history
JIRA CI-336
  • Loading branch information
mateusz-bloch committed Sep 29, 2023
1 parent fadfb82 commit 146db1f
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions psh/test-autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,12 @@
# %LICENSE%
#
import psh.tools.psh as psh
from psh.tools.common import assert_deleted_rec, assert_dir_created, assert_file_created

TAB = '\x09'
ENTER = '\x0D'


def mkdir(p, path):
p.send('mkdir ' + path + ENTER)
p.expect_exact('mkdir ' + path)
psh.assert_prompt(p, msg='Cannot make directory: ' + path, timeout=1)


def touch(p, path):
p.send('touch ' + path + ENTER)
p.expect_exact('touch ' + path)
psh.assert_prompt(p, msg='Cannot make file: ' + path, timeout=1)


def assert_completion(p, comptab):
for prefix, suffix in comptab:
p.send(prefix)
Expand All @@ -52,16 +41,17 @@ def assert_hints(p, path, hints):

@psh.run
def harness(p):
mkdir(p, 'etc')
p.sendline('mkdir etc')
p.expect_exact('mkdir etc')

# Create test environment
mkdir(p, 'testenv')
mkdir(p, 'testenv/ipsum')
mkdir(p, 'testenv/lorem')
mkdir(p, 'testenv/loremipsum')
touch(p, 'testenv/loremipsum/dolor.txt')
touch(p, 'testenv/loremipsum/sit.jpg')
touch(p, 'testenv/loremipsum/amet.exe')
assert_dir_created(p, 'testenv')
assert_dir_created(p, 'testenv/ipsum')
assert_dir_created(p, 'testenv/lorem')
assert_dir_created(p, 'testenv/loremipsum')
assert_file_created(p, 'testenv/loremipsum/dolor.txt')
assert_file_created(p, 'testenv/loremipsum/sit.jpg')
assert_file_created(p, 'testenv/loremipsum/amet.exe')

# Check autocompletion in command
assert_completion(p, [['ls e', 'tc/']])
Expand All @@ -84,6 +74,7 @@ def harness(p):
assert_hints(p, path='ls testenv/lorem/../', hints=['ipsum', 'lorem', 'loremipsum'])
assert_hints(p, path='ls testenv/loremipsum/', hints=['amet', 'dolor', 'sit'])

# TODO Tests: backspace handling, symlink handling
# TODO cleanup folders after tests
# Cleanup
assert_deleted_rec(p, 'testenv')

# TODO Tests: backspace handling, symlink handling

0 comments on commit 146db1f

Please sign in to comment.