1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Tests for the cmd_helper module."""
9 from pylib
import cmd_helper
11 # TODO(jbudorick) Make these tests run on the bots.
14 class CmdHelperSingleQuoteTest(unittest
.TestCase
):
16 def testSingleQuote_basic(self
):
17 self
.assertEquals('hello',
18 cmd_helper
.SingleQuote('hello'))
20 def testSingleQuote_withSpaces(self
):
21 self
.assertEquals("'hello world'",
22 cmd_helper
.SingleQuote('hello world'))
24 def testSingleQuote_withUnsafeChars(self
):
25 self
.assertEquals("""'hello'"'"'; rm -rf /'""",
26 cmd_helper
.SingleQuote("hello'; rm -rf /"))
28 def testSingleQuote_dontExpand(self
):
29 test_string
= 'hello $TEST_VAR'
30 cmd
= 'TEST_VAR=world; echo %s' % cmd_helper
.SingleQuote(test_string
)
31 self
.assertEquals(test_string
,
32 cmd_helper
.GetCmdOutput(cmd
, shell
=True).rstrip())
35 class CmdHelperDoubleQuoteTest(unittest
.TestCase
):
37 def testDoubleQuote_basic(self
):
38 self
.assertEquals('hello',
39 cmd_helper
.DoubleQuote('hello'))
41 def testDoubleQuote_withSpaces(self
):
42 self
.assertEquals('"hello world"',
43 cmd_helper
.DoubleQuote('hello world'))
45 def testDoubleQuote_withUnsafeChars(self
):
46 self
.assertEquals('''"hello\\"; rm -rf /"''',
47 cmd_helper
.DoubleQuote('hello"; rm -rf /'))
49 def testSingleQuote_doExpand(self
):
50 test_string
= 'hello $TEST_VAR'
51 cmd
= 'TEST_VAR=world; echo %s' % cmd_helper
.DoubleQuote(test_string
)
52 self
.assertEquals('hello world',
53 cmd_helper
.GetCmdOutput(cmd
, shell
=True).rstrip())