OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 """Tests for the cmd_helper module.""" |
| 6 |
| 7 import unittest |
| 8 |
| 9 from pylib import cmd_helper |
| 10 |
| 11 # TODO(jbudorick) Make these tests run on the bots. |
| 12 |
| 13 |
| 14 class CmdHelperSingleQuoteTest(unittest.TestCase): |
| 15 |
| 16 def testSingleQuote_basic(self): |
| 17 self.assertEquals('hello', |
| 18 cmd_helper.SingleQuote('hello')) |
| 19 |
| 20 def testSingleQuote_withSpaces(self): |
| 21 self.assertEquals("'hello world'", |
| 22 cmd_helper.SingleQuote('hello world')) |
| 23 |
| 24 def testSingleQuote_withUnsafeChars(self): |
| 25 self.assertEquals("""'hello'"'"'; rm -rf /'""", |
| 26 cmd_helper.SingleQuote("hello'; rm -rf /")) |
| 27 |
| 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()) |
| 33 |
| 34 |
| 35 class CmdHelperDoubleQuoteTest(unittest.TestCase): |
| 36 |
| 37 def testDoubleQuote_basic(self): |
| 38 self.assertEquals('hello', |
| 39 cmd_helper.DoubleQuote('hello')) |
| 40 |
| 41 def testDoubleQuote_withSpaces(self): |
| 42 self.assertEquals('"hello world"', |
| 43 cmd_helper.DoubleQuote('hello world')) |
| 44 |
| 45 def testDoubleQuote_withUnsafeChars(self): |
| 46 self.assertEquals('''"hello\\"; rm -rf /"''', |
| 47 cmd_helper.DoubleQuote('hello"; rm -rf /')) |
| 48 |
| 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()) |
OLD | NEW |