diff --git a/psh/test-autocompletion.py b/psh/test-autocompletion.py index 3800b953..eb778c4b 100644 --- a/psh/test-autocompletion.py +++ b/psh/test-autocompletion.py @@ -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) @@ -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/']]) @@ -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