1# -*- coding: utf-8 -*- 2# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3# See https://llvm.org/LICENSE.txt for license information. 4# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 6import libscanbuild.shell as sut 7import unittest 8 9 10class ShellTest(unittest.TestCase): 11 12 def test_encode_decode_are_same(self): 13 def test(value): 14 self.assertEqual(sut.encode(sut.decode(value)), value) 15 16 test("") 17 test("clang") 18 test("clang this and that") 19 20 def test_decode_encode_are_same(self): 21 def test(value): 22 self.assertEqual(sut.decode(sut.encode(value)), value) 23 24 test([]) 25 test(['clang']) 26 test(['clang', 'this', 'and', 'that']) 27 test(['clang', 'this and', 'that']) 28 test(['clang', "it's me", 'again']) 29 test(['clang', 'some "words" are', 'quoted']) 30 31 def test_encode(self): 32 self.assertEqual(sut.encode(['clang', "it's me", 'again']), 33 'clang "it\'s me" again') 34 self.assertEqual(sut.encode(['clang', "it(s me", 'again)']), 35 'clang "it(s me" "again)"') 36 self.assertEqual(sut.encode(['clang', 'redirect > it']), 37 'clang "redirect > it"') 38 self.assertEqual(sut.encode(['clang', '-DKEY="VALUE"']), 39 'clang -DKEY=\\"VALUE\\"') 40 self.assertEqual(sut.encode(['clang', '-DKEY="value with spaces"']), 41 'clang -DKEY=\\"value with spaces\\"') 42