1#!/usr/bin/env python
2import os
3import sys
4import unittest
5
6import pexpect
7
8
9class Test(unittest.TestCase):
10    def test_fish(self):
11        os.environ['TERM'] = 'vt100'
12        child = pexpect.spawn('fish -i')
13        with open(os.environ['IDF_PATH'] + '/fish' + str(sys.version_info.major) + '.out', 'wb') as output:
14            child.logfile = output
15            child.sendline('. ./export.fish')
16            result = child.expect(
17                ['Go to the project directory and run.*idf\\.py build', pexpect.EOF,
18                 pexpect.TIMEOUT], timeout=40)
19            self.assertEqual(result, 0, 'Export was not successful!')
20            child.send('idf.py \t\t')
21            result = child.expect(['all.*app.*app-flash.*bootloader.*', pexpect.EOF, pexpect.TIMEOUT], timeout=40)
22            self.assertEqual(result, 0, 'Autocompletion for idf.py failed in fish!')
23
24    def test_bash(self):
25        os.environ['TERM'] = 'xterm-256color'
26        child = pexpect.spawn('bash -i')
27        with open(os.environ['IDF_PATH'] + '/bash' + str(sys.version_info.major) + '.out', 'wb') as output:
28            child.logfile = output
29            child.sendline('. ./export.sh')
30            child.send('idf.py \t\t')
31            result = child.expect(
32                ['Go to the project directory and run.*idf\\.py build', pexpect.EOF,
33                 pexpect.TIMEOUT], timeout=40)
34            self.assertEqual(result, 0, 'Export was not successful!')
35            result = child.expect(
36                ['all.*app.*app-flash.*bootloader.*bootloader-flash.*build-system-targets.*clean.*', pexpect.EOF,
37                 pexpect.TIMEOUT], timeout=40)
38            self.assertEqual(result, 0, 'Autocompletion for idf.py failed in bash!')
39
40    def test_zsh(self):
41        child = pexpect.spawn('zsh -i')
42        with open(os.environ['IDF_PATH'] + '/zsh' + str(sys.version_info.major) + '.out', 'wb') as output:
43            child.logfile = output
44            child.sendline('. ./export.sh')
45            result = child.expect(
46                ['Go to the project directory and run.*idf\\.py build', pexpect.EOF,
47                 pexpect.TIMEOUT], timeout=40)
48            self.assertEqual(result, 0, 'Export was not successful!')
49            child.send('idf.py \t\t')
50            result = child.expect(
51                ['all.*app.*app-flash.*bootloader.*bootloader-flash.*build-system-targets.*clean.*', pexpect.EOF,
52                 pexpect.TIMEOUT], timeout=40)
53            self.assertEqual(result, 0, 'Autocompletion for idf.py failed in zsh!')
54
55
56if __name__ == '__main__':
57    unittest.main()
58