protocol start, connection loss, passthrough to test start done
authorRobert Collins <robertc@robertcollins.net>
Sat, 27 Aug 2005 10:10:03 +0000 (20:10 +1000)
committerRobert Collins <robertc@robertcollins.net>
Sat, 27 Aug 2005 10:10:03 +0000 (20:10 +1000)
README
lib/subunit/__init__.py
lib/subunit/tests/__init__.py

diff --git a/README b/README
index e82e108166e48e16dbdc40a714ae4db941846c21..7d57b829dceede9f924c98d4ca1b324b9aaf56cb 100644 (file)
--- a/README
+++ b/README
@@ -28,26 +28,6 @@ Some requirements:
   anything taking a reference to them doesn't get 50 copies of the same object.
 
 
-it might look like this:
-
-foo:0:STARTTEST "test foo works."   result->startTest
-foo:0:SUCCESS                       result->addSuccess
-foo:0:ENDTEST "test foo works."     result->endTest
-foo:0:STARTTEST "tar a file."       result->startTest
-foo:0:FAILURE                       starts buffering
- __init__.py : 300 undefined object 'foo'  
-foo:0:ENDTEST                       result->addFailure ( __i... ; result->endTest
-foo:0:STARTTEST "tar a different file."  result->startTest
-foo:0:FAILURE                            starts buffering
-foo.c:34:WARNING cannot compile foo.c
-foo:0:ENDTEST "tar a different file."    result->addFailure(foo:0...; result->endTest
-foo:0:STARTTEST "test an exception during teardown." result->startTest
-foo:0:ERROR
-foo:0:ENDTEST "test an exception during teardown." 
-foo:0:WARNING blahj blah balh      shown straight on stdout
-and more random text to stdout     ditto
-
-or like this:
 TEST: test foo works
 SUCCESS: test foo works.
 TEST: tar a file.
@@ -70,15 +50,29 @@ FAILURE: tar a file.
 foo.c:34 WARNING foo is not defined.
 ========================
 
-
-test|testing|test:|testing:
-success|success:|successful|successful:
-failure: foo
-failure: foo [
+control protocol: 
+test|testing|test:|testing: test label
+success|success:|successful|successful: test label
+failure: test label
+failure: test label [
 ...
 ]
-error: foo
-error: foo [
+error: test label
+error: test label [
 ]
 unexpected output on stdout -> stdout.
 exit w/0 or last test -> error
+
+rough structure of the server:
+SubprocessTestCase(unittest.TestCase):
+
+def run:
+    do a fork,
+      this process runs server
+      child runs client and calls self.run() with a SubprocessTestResult 
+
+developing - write a server and feed it chosen strings, a mock child process etc.
+write a client and check the right things come back for the various permutations
+check that stdout output in the client is passed to the real stdout.
+
+
index aa185baebe1e07aed1e950684856caf953c027d1..bd1d8cf750fc1dddf7c97c57b2b8800dc77e29f2 100644 (file)
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+import sys
+
 def test_suite():
     import subunit.tests
     return subunit.tests.test_suite()
+
+class TestProtocolServer(object):
+    """A class for recieving results from a TestProtocol client."""
+
+    OUTSIDE_TEST = 0
+    TEST_STARTED = 1
+
+    def __init__(self):
+        self.state = TestProtocolServer.OUTSIDE_TEST
+        
+    def lineRecieved(self, line):
+        """Call the appropriate local method for the recieved line."""
+        if line.startswith("test:"):
+            self._startTest(6, line)
+        elif line.startswith("testing:"):
+            self._startTest(9, line)
+        elif line.startswith("testing"):
+            self._startTest(8, line)
+        elif line.startswith("test"):
+            self._startTest(5, line)
+        else:
+            self.stdOutLineRecieved(line)
+
+    def lostConnection(self):
+        """The input connection has finished."""
+        if self.state != TestProtocolServer.OUTSIDE_TEST:
+            self.addError("lost connection during test '%s'" 
+                          % self.current_test_description)
+
+    def _startTest(self, offset, line):
+        """Internal call to change state machine. Override startTest()."""
+        if self.state == TestProtocolServer.OUTSIDE_TEST:
+            self.state = TestProtocolServer.TEST_STARTED
+            self.current_test_description = line[offset:-1]
+            self.startTest(self.current_test_description)
+        else:
+            self.stdOutLineRecieved(line)
+        
+    def stdOutLineRecieved(self, line):
+        sys.stdout.write(line)
index 85af67241cca9bbbd547ebc8c1eefdc01b743d33..544d0e704fcdea7dcbe253b71a5bd046f2a28eee 100644 (file)
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
-from subunit.tests import TestUtil
-
-#def test_suite():
-#    loader = tests.TestLoader()
-#    result = loader.loadTestsFromName(__name__)
-#    return result
+from subunit.tests import TestUtil, test_test_protocol
 
 def test_suite():
-    return TestUtil.TestSuite()
-#    return sub.tests.test_suite()
+    result = TestUtil.TestSuite()
+    result.addTest(test_test_protocol.test_suite())
+    return result