Chromium Code Reviews| 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 | |
|
jbudorick
2014/10/17 15:48:00
Add a TODO for me to make these run on the bots.
| |
| 12 class CmdHelperSingleQuoteTest(unittest.TestCase): | |
| 13 | |
| 14 def testSingleQuote_basic(self): | |
| 15 self.assertEquals('hello', | |
| 16 cmd_helper.SingleQuote('hello')) | |
| 17 | |
| 18 def testSingleQuote_withSpaces(self): | |
| 19 self.assertEquals("'hello world'", | |
| 20 cmd_helper.SingleQuote('hello world')) | |
| 21 | |
| 22 def testSingleQuote_withUnsafeChars(self): | |
| 23 self.assertEquals("""'hello'"'"'; rm -rf /'""", | |
| 24 cmd_helper.SingleQuote("hello'; rm -rf /")) | |
| 25 | |
| 26 def testSingleQuote_dontExpand(self): | |
| 27 test_string = 'hello $TEST_VAR' | |
| 28 cmd = 'TEST_VAR=world; echo %s' % cmd_helper.SingleQuote(test_string) | |
| 29 self.assertEquals(test_string, | |
| 30 cmd_helper.GetCmdOutput(cmd, shell=True).rstrip()) | |
| 31 | |
| 32 | |
| 33 class CmdHelperDoubleQuoteTest(unittest.TestCase): | |
| 34 | |
| 35 def testDoubleQuote_basic(self): | |
| 36 self.assertEquals('hello', | |
| 37 cmd_helper.DoubleQuote('hello')) | |
| 38 | |
| 39 def testDoubleQuote_withSpaces(self): | |
| 40 self.assertEquals('"hello world"', | |
| 41 cmd_helper.DoubleQuote('hello world')) | |
| 42 | |
| 43 def testDoubleQuote_withUnsafeChars(self): | |
| 44 self.assertEquals('''"hello\\"; rm -rf /"''', | |
| 45 cmd_helper.DoubleQuote('hello"; rm -rf /')) | |
| 46 | |
| 47 def testSingleQuote_doExpand(self): | |
| 48 test_string = 'hello $TEST_VAR' | |
| 49 cmd = 'TEST_VAR=world; echo %s' % cmd_helper.DoubleQuote(test_string) | |
| 50 self.assertEquals('hello world', | |
| 51 cmd_helper.GetCmdOutput(cmd, shell=True).rstrip()) | |
| OLD | NEW |