Bug 1499511 - Add unit test for adb.py _escape_command_line; r=bc
authorGeoff Brown <gbrown@mozilla.com>
Wed, 17 Oct 2018 11:11:52 -0600
changeset 500247 73466d27dd000194e73f6f5aa9eca0a961dd8bc7
parent 500246 bc1992018c602430c33ab99d3004d787a2fa07bd
child 500248 dce4f5d77296ddf754487066686ef789952fdb47
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbc
bugs1499511
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499511 - Add unit test for adb.py _escape_command_line; r=bc
testing/mozbase/mozdevice/tests/manifest.ini
testing/mozbase/mozdevice/tests/test_escape_command_line.py
--- a/testing/mozbase/mozdevice/tests/manifest.ini
+++ b/testing/mozbase/mozdevice/tests/manifest.ini
@@ -1,6 +1,7 @@
 [DEFAULT]
 subsuite = mozbase, os == "linux"
 skip-if = python == 3
 [test_socket_connection.py]
 [test_is_app_installed.py]
 [test_chown.py]
+[test_escape_command_line.py]
new file mode 100644
--- /dev/null
+++ b/testing/mozbase/mozdevice/tests/test_escape_command_line.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import
+
+import mozunit
+
+
+def test_escape_command_line(mock_adb_object, redirect_stdout_and_assert):
+    """Test _escape_command_line."""
+    cases = {
+        # expected output : test input
+        'adb shell ls -l': ['adb', 'shell', 'ls', '-l'],
+        'adb shell "ls -l"': ['adb', 'shell', 'ls -l'],
+        '-e "if (true)"': ['-e', 'if (true)'],
+        '-e "if (x === \\"hello\\")"': ['-e', 'if (x === "hello")'],
+        '-e "if (x === \'hello\')"': ['-e', "if (x === 'hello')"],
+    }
+    for expected, input in cases.items():
+        assert mock_adb_object._escape_command_line(input) == expected
+
+
+if __name__ == '__main__':
+    mozunit.main()