Exemplo n.º 1
0
    def test_factorial(self):
        """Test that the factorial example works."""
        factdir = os.path.join(self.__examples, "factorial")

        source = os.path.join(factdir, "factorial.i8")
        objfile = os.path.join(factdir, "factorial.o")
        testfile = os.path.join(factdir, "test-factorial.py")

        self.__unlink_me.append(objfile)

        # Run the exact commands in the documentation
        sys.argv[1:] = ["-c", source]
        self.assertIs(compiler.main(), None)
        sys.argv[1:] = ["-i", objfile, "-q", "example::factorial(i)i", "12"]
        self.assertIs(runtime.main(), None)
        sys.argv[1:] = ["-i", objfile, testfile]
        self.assertIs(runtime.main(), None)

        # Check nothing was output to stderr
        sys.stderr.flush()
        errors = open(self.__streams["stderr"][0]).read()
        self.assertEqual(errors, "")

        # Check the output of the two I8X invocations
        if hasattr(sys.stdout, "getvalue"):
            # Captured by nosetests
            output = sys.stdout.getvalue()
        else:
            # Captured by us
            sys.stdout.flush()
            output = open(self.__streams["stdout"][0]).read()
        lines = output.split("\n")
        self.assertEqual(lines[0], "479001600")
        self.assertTrue(lines[-4].startswith("Ran 1 test in "))
        self.assertEqual(lines[-2], "OK")
Exemplo n.º 2
0
    def test_factorial(self):
        """Test that the factorial example works."""
        factdir = os.path.join(self.__examples, "factorial")

        source = os.path.join(factdir, "factorial.i8")
        objfile = os.path.join(factdir, "factorial.o")
        testfile = os.path.join(factdir, "test-factorial.py")

        self.__unlink_me.append(objfile)

        # Run the exact commands in the documentation
        sys.argv[1:] = ["-c", source]
        self.assertIs(compiler.main(), None)
        sys.argv[1:] = ["-i", objfile, "-q", "example::factorial(i)i", "12"]
        self.assertIs(runtime.main(), None)
        sys.argv[1:] = ["-i", objfile, testfile]
        self.assertIs(runtime.main(), None)

        # Check nothing was output to stderr
        sys.stderr.flush()
        errors = open(self.__streams["stderr"][0]).read()
        self.assertEqual(errors, "")

        # Check the output of the two I8X invocations
        if hasattr(sys.stdout, "getvalue"):
            # Captured by nosetests
            output = sys.stdout.getvalue()
        else:
            # Captured by us
            sys.stdout.flush()
            output = open(self.__streams["stdout"][0]).read()
        lines = output.split("\n")
        self.assertEqual(lines[0], "479001600")
        self.assertTrue(lines[-4].startswith("Ran 1 test in "))
        self.assertEqual(lines[-2], "OK")
Exemplo n.º 3
0
 def test_failure_path(self):
     """Check the i8c console scripts entry point failure path."""
     sys.argv[1:] = ["-x"]
     sys.stderr = sys.stdout
     self.assertEqual(main(), 1)
Exemplo n.º 4
0
 def test_success_path(self):
     """Check the i8c console scripts entry point success path."""
     sys.argv[1:] = ["--version"]
     self.assertIs(main(), None)
Exemplo n.º 5
0
 def test_failure_path(self):
     """Check the i8c console scripts entry point failure path."""
     sys.argv[1:] = ["-x"]
     sys.stderr = sys.stdout
     self.assertEqual(main(), 1)
Exemplo n.º 6
0
 def test_success_path(self):
     """Check the i8c console scripts entry point success path."""
     sys.argv[1:] = ["--version"]
     self.assertIs(main(), None)