Changeset 71336 in webkit


Ignore:
Timestamp:
Nov 4, 2010 8:24:40 AM (13 years ago)
Author:
Adam Roben
Message:

Reduce our dependence on coreutils when running Python tests

This patch introduces versions of the standard echo and cat utilities
implemented in Python. They are probably missing features of their
coreutils equivalents, but they can do what's necessary for our Python
tests. This is useful on Windows, where these utilities typically
aren't available.

Fixes <http://webkit.org/b/48883> executive_unittest relies on echo
and cat utilities from coreutils, which are not present on Windows

Reviewed by Eric Seidel.

  • Scripts/webkitpy/common/system/executive_unittest.py: Changed to use

our Python-based echo and cat.

  • Scripts/webkitpy/common/system/fileutils.py: Added.

(make_stdout_binary): On Windows, puts sys.stdout into binary mode so
that \n won't be translated into \r\n. I couldn't think of a good way
to test this directly without touching the filesystem, but it is tested
indirectly by echo_unittest.

  • Scripts/webkitpy/test/cat.py: Added.

(command_arguments): Returns a list for invoking cat with the given arguments.
(main): Acts like a simplified version of the coreutils cat utility.

  • Scripts/webkitpy/test/cat_unittest.py: Added.

(CatTest.assert_cat): Runs cat with the given input and ensures the
output matches the input.
(CatTest.test_basic): Performs a simple test of cat.
(CatTest.test_no_newline): Tests what happens when the input string
doesn't have a trailing newline.
(CatTest.test_unicode): Tests passing a unicode string to cat.
(CatTest.test_as_command): Tests running cat as a separate command.

  • Scripts/webkitpy/test/echo.py: Added.

(command_arguments): Returns a list for invoking echo with the given arguments.
(main): Acts like a simplified version of the coreutils echo utility.

  • Scripts/webkitpy/test/echo_unittest.py: Added.

(EchoTest.test_basic): Performs a simple test of echo.
(EchoTest.test_no_newline): Tests passing -n to echo to suppress the
trailing newline.
(EchoTest.test_unicode): Tests passing unicode and non-unicode strings
to echo.
(EchoTest.test_argument_order): Tests what happens when -n is not the
first argument.
(EchoTest.test_empty_arguments): Tests what happens when you pass [] to
echo.main.
(EchoTest.test_no_arguments): Tests what happens when you call
echo.main with no arguments.
(EchoTest.test_as_command): Tests running echo as a separate command.

Location:
trunk/WebKitTools
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r71335 r71336  
     12010-11-02  Adam Roben  <aroben@apple.com>
     2
     3        Reduce our dependence on coreutils when running Python tests
     4
     5        This patch introduces versions of the standard echo and cat utilities
     6        implemented in Python. They are probably missing features of their
     7        coreutils equivalents, but they can do what's necessary for our Python
     8        tests. This is useful on Windows, where these utilities typically
     9        aren't available.
     10
     11        Fixes <http://webkit.org/b/48883> executive_unittest relies on echo
     12        and cat utilities from coreutils, which are not present on Windows
     13
     14        Reviewed by Eric Seidel.
     15
     16        * Scripts/webkitpy/common/system/executive_unittest.py: Changed to use
     17        our Python-based echo and cat.
     18
     19        * Scripts/webkitpy/common/system/fileutils.py: Added.
     20        (make_stdout_binary): On Windows, puts sys.stdout into binary mode so
     21        that \n won't be translated into \r\n. I couldn't think of a good way
     22        to test this directly without touching the filesystem, but it is tested
     23        indirectly by echo_unittest.
     24
     25        * Scripts/webkitpy/test/cat.py: Added.
     26        (command_arguments): Returns a list for invoking cat with the given arguments.
     27        (main): Acts like a simplified version of the coreutils cat utility.
     28
     29        * Scripts/webkitpy/test/cat_unittest.py: Added.
     30        (CatTest.assert_cat): Runs cat with the given input and ensures the
     31        output matches the input.
     32        (CatTest.test_basic): Performs a simple test of cat.
     33        (CatTest.test_no_newline): Tests what happens when the input string
     34        doesn't have a trailing newline.
     35        (CatTest.test_unicode): Tests passing a unicode string to cat.
     36        (CatTest.test_as_command): Tests running cat as a separate command.
     37
     38        * Scripts/webkitpy/test/echo.py: Added.
     39        (command_arguments): Returns a list for invoking echo with the given arguments.
     40        (main): Acts like a simplified version of the coreutils echo utility.
     41
     42        * Scripts/webkitpy/test/echo_unittest.py: Added.
     43        (EchoTest.test_basic): Performs a simple test of echo.
     44        (EchoTest.test_no_newline): Tests passing -n to echo to suppress the
     45        trailing newline.
     46        (EchoTest.test_unicode): Tests passing unicode and non-unicode strings
     47        to echo.
     48        (EchoTest.test_argument_order): Tests what happens when -n is not the
     49        first argument.
     50        (EchoTest.test_empty_arguments): Tests what happens when you pass [] to
     51        echo.main.
     52        (EchoTest.test_no_arguments): Tests what happens when you call
     53        echo.main with no arguments.
     54        (EchoTest.test_as_command): Tests running echo as a separate command.
     55
    1562010-11-04  Renata Hodovan  <reni@inf.u-szeged.hu>
    257
  • trunk/WebKitTools/Scripts/webkitpy/common/system/executive_unittest.py

    r59661 r71336  
    3434
    3535from webkitpy.common.system.executive import Executive, run_command, ScriptError
     36from webkitpy.test import cat, echo
    3637
    3738
     
    4748        self.assertRaises(AssertionError, executive.run_command, "echo")
    4849        self.assertRaises(AssertionError, executive.run_command, u"echo")
    49         executive.run_command(["echo", "foo"])
    50         executive.run_command(("echo", "foo"))
     50        executive.run_command(echo.command_arguments('foo'))
     51        executive.run_command(tuple(echo.command_arguments('foo')))
    5152
    5253    def test_run_command_with_unicode(self):
     
    5859        utf8_tor = unicode_tor.encode("utf-8")
    5960
    60         output = executive.run_command(["cat"], input=unicode_tor)
     61        output = executive.run_command(cat.command_arguments(), input=unicode_tor)
    6162        self.assertEquals(output, unicode_tor)
    6263
    63         output = executive.run_command(["echo", "-n", unicode_tor])
     64        output = executive.run_command(echo.command_arguments("-n", unicode_tor))
    6465        self.assertEquals(output, unicode_tor)
    6566
    66         output = executive.run_command(["echo", "-n", unicode_tor], decode_output=False)
     67        output = executive.run_command(echo.command_arguments("-n", unicode_tor), decode_output=False)
    6768        self.assertEquals(output, utf8_tor)
    6869
    6970        # Make sure that str() input also works.
    70         output = executive.run_command(["cat"], input=utf8_tor, decode_output=False)
     71        output = executive.run_command(cat.command_arguments(), input=utf8_tor, decode_output=False)
    7172        self.assertEquals(output, utf8_tor)
    7273
    7374        # FIXME: We should only have one run* method to test
    74         output = executive.run_and_throw_if_fail(["echo", "-n", unicode_tor], quiet=True)
     75        output = executive.run_and_throw_if_fail(echo.command_arguments("-n", unicode_tor), quiet=True)
    7576        self.assertEquals(output, unicode_tor)
    7677
    77         output = executive.run_and_throw_if_fail(["echo", "-n", unicode_tor], quiet=True, decode_output=False)
     78        output = executive.run_and_throw_if_fail(echo.command_arguments("-n", unicode_tor), quiet=True, decode_output=False)
    7879        self.assertEquals(output, utf8_tor)
    7980
Note: See TracChangeset for help on using the changeset viewer.