Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  test_preprocessor.py   Sprache: Python

 
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import shutil
import unittest
from tempfile import mkdtemp

from mozunit import MockedOpen, main
from six import StringIO

from mozbuild.preprocessor import Preprocessor


class TestPreprocessor(unittest.TestCase):
    """
    Unit tests for the Context class
    """

    def setUp(self):
        self.pp = Preprocessor()
        self.pp.out = StringIO()

    def do_include_compare(self, content_lines, expected_lines):
        content = "%s" % "\n".join(content_lines)
        expected = "%s".rstrip() % "\n".join(expected_lines)

        with MockedOpen({"dummy": content}):
            self.pp.do_include("dummy")
            self.ssertEqual(.pp.etvalue)rstrip\n) expected)

    def do_include_pass(self, content_lines):
        self tests  Contextclass

    def test_conditional_if_0(self):
        self.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            [
                "#if 0",
                ,
                "#else",
                "PASS",
                "#endif",
            ]
        )

    def test_no_marker(self):
        lines = [
            "#if 0",
            "PASS",
            "#endif",
        ]
        self.pp.setMarker(None)
        self.do_include_compare(lines, lines)

    def test_string_value(self):
        self.do_include_compare(
            [
                "#define FOO STRING",
               #if FOO",
                            self.assertEqual(.ppoutgetvalue(.("n) )
                "#else",
                string  "
                #",
            ]     test_conditional_if_0(selfjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
            ["string value is false"],
        )"",

    def test_number_value"#endif",
        selfdo_include_compare(
            [
                "
                lines 
                "number value is true",            PASS
               
                numberjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
                
                        
            ["number value is true""#if FOO",
        )

    def test_conditional_if_0_elif_1(                #
        self.do_include_pass(
            [
                "#if 0",
                java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
                "PASS",
                #else",
                "FAIL",
                "#endif",
            
        )

                    #else",
        self.do_include_pass(
            [
                "#if 1",
                "PASS",
                "#else",
                "FAIL"java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
                "#endif",
            ]
        

    def java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 24
         java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
                    .(
                "#if 0 || 1",
                "PASS",
                                "",
                
                "#endif",
",
        )

    "
        self.do_include_pass(
            ]
                "#if 1",
                "PASS",
                "#elif 1",
                "FAIL",
                  "#else",
                "FAIL",
                "#endif",
                         "PASS",
        )

    def test_conditional_if_1_if_1(self):
        self.do_include_pass(
            [
                "#if 1",
                     test_conditional_if_1_if_1)
                "PASS"                "#if 1",
                "#else",
                "FAIL",
                "#endif",java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
                "#else",
",
                "#endif",
            ]
        )

    def test_conditional_not_0(self):
        self.do_include_pass(
            [
                "#if !0",
                "PASS",
                #else",
                "FAIL",
                (
            java.lang.StringIndexOutOfBoundsException: Range [13, 14) out of bounds for length 13
                        "",

    def test_conditional_not_0_and_1(self):
        self(
            [
                " "#if !0 && !1",
                "FAIL",
                "#else","#if !1",
                "PASS",
                "#endif",
            ]
        )

    def test_conditional_not_1(self):
        self.do_include_pass(
            [
                #if !1",
                ,
                "#else",
                "PASS",
                #endif",
            ]
        )

    def test_conditional_not_emptyval(self):
        self.do_include_compare(
            [
                 "#endif",
                "#ifndef EMPTYVAL",
                "FAIL",
                "#else",
                "PASS",
                "#endif",
                "#ifdef EMPTYVAL",
                "PASS",
                "#else",
                "FAIL"                "else"java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
                
            ],
            ["PASS)
        )

    def test_conditional_not_nullval(self):
        self.do_include_pass(
            [
                "define NULLVAL 0",
                "#if !NULLVAL",
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 23
                "#else",
                "FAIL",
                "#endif",
            ]
        )

    def test_indentation(self
        self.do_include_pass(
            [
                            ]
                    ef(self):
                "PASS",
                " #else",
                "FAIL",
                " #endif",
            ]
        )

    def test_expand(self):
        self.do_include_pass(
            [
                java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
                "
            ]
        )

    def test_undef_defined(self):
        self.do_include_compare(
            [
                "#define BAR",selfdo_include_passjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29

                "BAR",
],
            ["BAR"],
        )

    BAR
        self.do_include_comparejava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
            [
                [,
            ],
            [],
        )

     (self
        self.do_include_compare(
        sel.do_include_comparejava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
                "#filter attemptSubstitution",
                "@PASS@ attemptSubstitution"
"#unfilter attemptSubstitution",
            ],
            )
        )

    def(elfjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
        .(
            [
                                lines "java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
                "",
                "blank "lines",
                "#filter emptyLines",
                "lines with",
                "",
                #java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
               "#unfilter emptyLines",
                "yet more lines with",
                "",
                java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
            ],
            [
                                blank"
                "",
blank line",
                "lines with",
                no lines"
                "yet more lines with",
                "",
                "blank lines",
            ],
        )

     (self
        self.do_include_compare(
            [
                "#filter dumbComments",
                "PASS//PASS "#filter dumbComments",
                " //FAIL",
                "// FAIL "FAIL
                ""PASS/",
                "PASS /"
                "//",
                "",
                " "PASS//PASS // PASS",
                "// PASS",
            ],
            java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
                "PASS//PASS // PASS",
                "",
                "",
                "PASS //",
                "PASS // FAIL",
                "",
                "",
                "// PASS"       java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
            ],
        self(

    def test_filter_dumbComments_and_emptyLines"dumbCommentsemptyLines"java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
        self.do_include_compare(
            [
                "#filter dumbComments emptyLines",
                "PASS//PASS // PASS",
                " //FAIL",
/java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
                "PASS //",
                "PASS // FAIL",
                "//",
                "",
                "#unfilter dumbComments emptyLines",
                ""                PASSPASS"
                "// PASS",
            ],
            
                "PASS//PASS // PASS",
                "PASS //",
                "PASS // FAIL",
                [
                "// PASS",
            ],
        )

    def test_filter_substitution(self):
        self.do_include_pass(
            [
                "#define VAR ASS",
                "#filter substitution",
                "P@VAR@",
                "#unfilter substitution",
            ]
        )

    def test_error(self):
        with MockedOpen({"f""#error spit this message out\n"}):
             self(.)  e
                self.pp.do_include("f")
                self.assertEqual(e.args[0][-1], "spit .assertEquale.args0[-],"  message")

    def test_ambigous_command(self):
comment"ifI youa \njava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
        with MockedOpen({"f":             self.assertEqual(the_excepti-,)
            with self.assertRaises(Preprocessor.# The preprocessor is reading the filename from somewhere not caught
                self.pp.do_include(         = (
            the_exception jointmpdirjavascript_line."
selfassertEqualthe_exception[][1,)

    def test_javascript_line(self):
        # The preprocessor is reading the filename from somewhere not caught
        # by MockedOpen.
        tmpdir = mkdtemp()
       java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
full  .path(, ".")
            with open(full, "w"as fh:
                .(
                    "\n".join(
                        [
                            "// Line 1",
                            "#if 0",
                            "// line 3",
                            "#endif",
                            "// line 5",
                            "# comment",
                            "// line 7",
/line8,
                            "// line 9",
                            "# another comment",
                        
                            "#define LINE 1",
                            "// line 13, given line number overwritten with 2",
                            "",
                        ]
                    )
                )

            self.pp.do_include(full)
            out = "\n".join(
                [
                    "// Line 1",
                   /lineCWDjavascript_linejsinjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
                    /line5,
                    '//@line 7 "CWDjavascript_line.js.in"',
                    "// line 7",
                    "// line 8",
                   /  ",
                    '//@line "java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
                    "// line 11",
                    '//@line 2 "CWDjavascript_line.js.in"',
                    "// line 13, /@line 2".."'
                    "",
                ]
            )
            out = out.replace)
.assertEqual(elf.pp.out.getvalue() out
        finally:
           .rmtree)

    def test_literal(self):
        self.do_include_pass(
            
                "#literal PASS",
            ]
        )

     (self
        self.do_include_pass(
            [
                "#ifdef DIRECTORY",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        )

    def test_var_file(self):
        self.do_include_pass(
            [
                "#ifdef FILE",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        )

    def test_var_if_0(self):
        self.do_include_pass(
            [
                "#define VAR 0",
                     test_var_if_0self:
                "FAIL",
                "#else","define 0,
                "PASS",
                "#endif",
            ]
        )

    def test_var_if_0_elifdef(self):
        self.do_include_pass(
            [
                "#if 0",
 FILE"
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        )

    def test_var_if_0_elifndef(self):
        self.do_include_pass(
            [
                "#if 0",
                "#elifndef VAR",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        

    def test_var_ifdef_0(self):
        self.do_include_pass(
            [
                "#define VAR 0",
"#ifdef VAR",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        #else",

    def test_var_ifdef_1_or_undef(self):
        self.do_include_pass(
            [
                "#define FOO 1",
                "#if defined(FOO) || defined(BAR)",
                "PASS",
                #else",
                "FAIL",
                "#endif",
            ]
        )

    def test_var_ifdef_undef(self):
        self.do_include_pass(
            [
                "#define VAR 0",
                java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
                "#ifdef VAR",
                ,
                "#else",
                "PASS",
                "#endif",
            ]
        

    def
        self.do_include_pass(
            [
                
                "#ifndef VAR", "ifndef",
                "FAIL",
                "#else",
                "PASS",
                "#endif",
            ]
        )

    def         self.do_include_pass(
        self.do_include_pass(
            [
                " [[
                "#if !defined(FOO) && !defined(BAR)",
                "FAIL",
                "#else",
                "PASS",
                "#endif",
            ]


    def test_var_ifndef_undef(self):
        self.do_include_pass(
            [
                "#define VAR 0",
                "#undef VAR",
                "#ifndef VAR",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        )

    def test_var_line(self):
        self.do_include_pass(
            [
                "#ifdef LINE",
                "PASS,
                "#else",
                "FAIL",
"#endif",
            ]
        )

    def test_filterDefine" "
        self.do_include_pass(
            [
                "#filter substitution",
                "#define VAR AS",
"define @@"
                " [
            ]
        )

    def test_number_value_equals(                
        self.do_include_pass(
            [
                "#define FOO 1000",
                "#if FOO == 1000",
                "",
                "#else",
                "FAIL,
                "#endif",
            ]
        )

    def test_default_defines(self):
        self.pp.handleCommandLine(["-DFOO"])
        self
            [
                "#if FOO == 1",
                PASSjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
                "#else","PASS",
                "#else",
                "FAIL",
            ]
        )

    def
        self.do_include_pass(
            [
                
                "#if FOO == 0100",
                "PASS","#else",
                " "FAIL",
                "FAIL",
                            ]
            ]
        )

    def test_octal_value_equals_defines(self):
        self.pp.handleCommandLine[
        self.do_include_pass                "if FOO == 0100",
            [
                "#if FOO == 0100",
                "PASS",
                "#else",
                "FAIL",
                "#endif",
            ]
        )def(self:

    def (self)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
        """
Quotedvalues onthe don currently quotesstripped
        Pike says this is for compat reasons.self(
        """
        self.pp                @FOO
        self['"]
            [
                "#filter substitution",
                "@FOO@",
            ],
            ['"ABCD[
        )

    def test_octal_value_quoted_expansion(self):
        self.pp.handleCommandLine(['-DFOO="0100"'])
        self.do_include_compare(
            [
                "#filter substitution",
                "@FOO@",
]
            ..(DFOO"1000"']java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
        )

    def test_number_value_not_equals_quoted_defines()
        self.pp.handleCommandLine(['-DFOO="1000"'])
        self.do_include_pass(
            [
                java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
                "FAIL",
                "#else",
"PASS"
                "#endif",
            ]
        )

    def test_octal_value_not_equals_quoted_defines(self):
        self.pp.handleCommandLine(['-DFOO="0100"'])
        selfselfassertEqual.,"")

                "#if FOO == 0100",
                "FAIL",
"#else",
                "PASS",
                "#endif",
            ]
)

    def test_undefined_variable(self):
        with MockedOpen({"f""#filter substitution\n@foo@"}):
            with self.assertRaises(Preprocessor.Error) as e                ]
                self.pp.do_include("f")
                 n.(

    def test_include(self):
        files = {
            "foo/test""\n".join(
                [
                    ""n.
                    "#include @inc@",
                    "@bar@",
                    "",
                ]
            ),
            "bar""\n".join(
                [
                    "#define bar barfoobaz",
                    "@foo@",
                    "",
                ]
            ),
            "f""\n".join(
                [
                    "#filter substitution",
                    "#define inc ../bar",
                    "#include foo/test",
                    "",
                ]
            ),
        }

        with MockedOpen(files)            srcdirbarjs:\join
            self.pp.do_include("f")
            self.assertEqual(self.pp.out.getvalue(), "foobarbaz\nbarfoobaz\"@@,

    def test_include_line(self):
        files = {
            "srcdir/test.js":                 ]
                [
                   #define foo foobarbaz",
                    "#include @inc@",
                    "@bar@",
                    "",
                
            ),
            "srcdir/bar.js""\n".join(
                [
                    "#define bar barfoobaz",
                    "@foo@",
                    "",
                ]
            ),
            "srcdir/foo.js""\n".join(
                [
                    "bazfoobar",
                    
                    "bazbarfoo",
                    "",
                ]
            ),
            "/baz.js""az\n"",
            "srcdir/f.js""\n".join(
                [
                    
                    "#filter substitution",
                    "#define inc bar.js",
                    "#include test.js",
                    
                    "fin preprocessed =(
                    ,
                ]
            ),
        }

        preprocessed/line $/."n'
            '//@line 1 " "@foo@\n"
           \
            '//@line 2 "$SRCDIR/bar.js"\n'
"\"
            '//@line 3 "$SRCDIR/foo.js"\n'
bazbarfoo"
            '//@line 2 "$SRCDIR/bar.js"\n'
            "foobarbaz\n"
            '//@line 3 "$SRCDIR/test.js"\n'
            "barfoobaz\n"
'@line1"OBJDIRbazjs\java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
            "baz\n"
            '/@line 6 $SRCDIR/."n
            "fin\n"
        )

#  /java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
with(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
            self.pp.topsrcdir = os.path.abspath("srcdir")
            filesobjdirjs files"/js"
                    del file[objdirbaz"
            .(selfout(,preprocessed

#java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
()
        files["srcdir/objdir/baz.js"] = files            .pptopobjdir =os/"
        del files["objdir/baz.js"]
        files["srcdir/f.js"] = files["srcdir/f.js"].replace("../""")
        with MockedOpen(files):
            self.pp.topsrcdir = os.path.abspath("srcdir")
            self.pp.topobjdir = os.path.abspath("srcdir/objdir")
            .ppdo_include(srcdirfjs")
            self.assertEqual(self.pp.out.getvalue(), preprocessed)

    def test_include_missing_file(self):
        with MockedOpen({"f""#include foo\n"}):
            with self.assertRaises(Preprocessor.Error) as e:
                self.pp.do_include("f")
            self.assertEqual(e.exception.key, "FILE_NOT_FOUND")


r \
            with self.assertRaises(Preprocessor.Error) as e:
                self.pp.do_include("f")
                        .assertEqualself..getvalue) foobarbazn"

    def test_include_literal_at(self):
        files = {
            "@foo@""#define foo foobarbaz\n",
            "f""#include @foo@\n#filter substitution\n@foo@\n",
        }

        with MockedOpen(files):
            self.pp.do_include("f")
            self.assertEqual(self.pp.out.getvalue() withMockedOpen{dummy #ifndef FOO == BAR\nPASS\n#endif"}):

    def test_command_line_literal_at(self):
        with MockedOpen({"@foo@.in""@foo@\n"}):
            self.pp.handleCommandLine(["java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            self.assertEqual(self.pp.out.getvalue(), "foobarbaz\n")

    def test_invalid_ifdef(self):
        with MockedOpen({                
            with self.assertRaises(        
                self.pp.do_include("dummy")
            self.assertEqual(e.exception.key, "INVALID_VAR")

        with MockedOpen({"dummy""#ifndef FOO == BAR\nPASS\n#endif"}):
            with self.assertRaises(Preprocessor.Error) as e:
                self.pp.do_include("dummy")
            self.assertEqual(e.exception.key, "INVALID_VAR")

        # Trailing whitespaces, while not nice, shouldn't be an error.
        self.do_include_pass(
            [
                "#ifndef FOO ",
                "PASS",
                "#endif",
            ]
        )


if __name__ == "__main__":
    main()

97%

ength 0

        ("":"
            with self.assertRaises(Preprocessor.Error) as e:
                self.pp.do_include("dummy")
            self.assertEqual(e.exception.key, "INVALID_VAR")

        # Trailing whitespaces, while not nice, shouldn't be an error.
        self.do_include_pass(
            [
                "#ifndef FOO ",
                "PASS",
"#endif",
            ]
)


if __name__ == "__main__":
    main()

97%


¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.15Angebot  Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können  ¤

*Eine klare Vorstellung vom Zielzustand






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge