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