• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2#                     The LLVM Compiler Infrastructure
3#
4# This file is distributed under the University of Illinois Open Source
5# License. See LICENSE.TXT for details.
6
7import libscanbuild.shell as sut
8import unittest
9
10
11class ShellTest(unittest.TestCase):
12
13    def test_encode_decode_are_same(self):
14        def test(value):
15            self.assertEqual(sut.encode(sut.decode(value)), value)
16
17        test("")
18        test("clang")
19        test("clang this and that")
20
21    def test_decode_encode_are_same(self):
22        def test(value):
23            self.assertEqual(sut.decode(sut.encode(value)), value)
24
25        test([])
26        test(['clang'])
27        test(['clang', 'this', 'and', 'that'])
28        test(['clang', 'this and', 'that'])
29        test(['clang', "it's me", 'again'])
30        test(['clang', 'some "words" are', 'quoted'])
31
32    def test_encode(self):
33        self.assertEqual(sut.encode(['clang', "it's me", 'again']),
34                         'clang "it\'s me" again')
35        self.assertEqual(sut.encode(['clang', "it(s me", 'again)']),
36                         'clang "it(s me" "again)"')
37        self.assertEqual(sut.encode(['clang', 'redirect > it']),
38                         'clang "redirect > it"')
39        self.assertEqual(sut.encode(['clang', '-DKEY="VALUE"']),
40                         'clang -DKEY=\\"VALUE\\"')
41        self.assertEqual(sut.encode(['clang', '-DKEY="value with spaces"']),
42                         'clang -DKEY=\\"value with spaces\\"')
43