Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 4003

Show
Ignore:
Timestamp:
10/12/08 20:51:55 (1 month ago)
Author:
Jim Panic
Message:

Added #line feature, so error messages display the line number in the .dtc file, not the generated .d file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/tango.test/tango/test/TestCase.d

    r3985 r4003  
    3737        TestMethodDelegate dg; 
    3838        char[]             name; 
     39        bool               called; 
     40 
     41        public void call () { 
     42            if (!called) dg(); 
     43        } 
    3944 
    4045        public static TestMethod opCall (TestMethodDelegate dg, char[] name) { 
  • branches/tango.test/tango/test/TestManager.d

    r3985 r4003  
    4545                else Stdout.format("    ({}/{}) {}:", testMethodIndex + 1, testCase.testMethods.length, testMethod.name); 
    4646 
    47                 if (testMethod.dg() == Test.Status.Success) { 
    48                     Stdout(" success.").newline; 
    49                 } else { 
    50                     Stdout(" failure.don't ").newline; 
     47                try { 
     48                    if (testMethod.call == Test.Status.Success) Stdout(" success.").newline; 
     49                    else Stdout(" failed.").newline; 
     50                } catch (Exception e) { 
     51                    Stdout.formatln(" failed:"); 
     52                    Stdout.formatln("          - {}({}): {} ({})", e.file, e.line, e.msg, e.toString); 
    5153                } 
    5254            } 
  • branches/tango.test/tango/test/dtcc/Adapter.d

    r3991 r4003  
    1515 
    1616import tango.text.Util; 
     17 
     18import tango.text.convert.Layout; 
    1719 
    1820import tango.test.dtcc.Token; 
     
    133135 
    134136    T[] generateSource () { 
    135         T[] source = "module " ~ baseDir ~ "." ~ collectionName ~ ";\n"; 
     137        auto s = new Layout!(T); 
     138        T[] source = s.convert("module {0}.{1};\n", baseDir, collectionName); 
    136139 
    137140        foreach (importStatement; importStatements) { source ~= importStatement ~ "\n"; } 
    138141 
    139         source ~= "import tango.test.TestCase;\n"; 
    140         source ~= "mixin(TestCaseImports!());\n"; 
    141         source ~= "class " ~ collectionName ~ ": TestCase {\n"; 
     142        source ~= "import tango.test.TestCase;\nmixin(TestCaseImports!());\n"; 
     143        source ~= s.convert("class {0}: TestCase {{ \n", collectionName); 
    142144        source ~= fixtures ~ "\n"; 
    143145        source ~= "this () {\n"; 
    144         source ~= "name = \"" ~ collectionName ~ "\";\n"
     146        source ~= s.convert("name = \"{0}\";\n", collectionName)
    145147 
    146148        /* We ignore the before and after stuff for now, as it’s not implemented in 
     
    150152         
    151153        foreach (testMethod; testMethods) {  
    152             source ~= "this ~= TestMethod(&" ~ testMethod.identifier ~ ", " ~ (testMethod.description == "" ? "\"\"" : testMethod.description) ~ ");\n"; } 
     154            source ~= s.convert("this ~= TestMethod(&{0}, {1});\n", testMethod.identifier, (testMethod.description == "" ? "\"\"" : testMethod.description)); 
     155        } 
    153156 
    154157        source ~= "}\n"; 
    155158 
    156159        foreach (testMethod; testMethods) {  
    157             source ~= "Test.Status " ~ testMethod.identifier ~ " () {\n"; 
     160            source ~= s.convert("#line {0}\n", testMethod.lastToken.previous.line); 
     161            source ~= s.convert("Test.Status {0} () {{\n", testMethod.identifier); 
     162 
     163            T[] codeBlock; 
     164 
     165            uint offset = 0; 
     166            foreach (T[] line; lines!(T)(testMethod.codeBlock)) { 
     167                codeBlock ~= s.convert("#line {0}\n{1}\n", testMethod.lastToken.line + offset, line); 
     168                offset++; 
     169            } 
    158170             
    159171            if (testMethod.exception) { 
    160                 source ~= "return Test.expectException!(" ~ testMethod.exception ~ ")(" ~ testMethod.codeBlock ~ ") ? Test.Status.Success : Test.Status.Failure;\n}\n"
     172                source ~= s.convert("return Test.expectException!({0})({1}) ? Test.Status.Success : Test.Status.Failure;\n}\n", testMethod.exception, codeBlock)
    161173            } else { 
    162                 source ~= testMethod.codeBlock ~ "return Test.Status.Success; }\n"
     174                source ~= s.convert("{0} return Test.Status.Success; }\n", codeBlock)
    163175            } 
    164176        } 
    165177             
    166         foreach (helperMethod; helperMethods) { source ~= helperMethod ~ "\n"; } 
     178        foreach (helperMethod; helperMethods) { source ~= s.convert("{0}\n", helperMethod); } 
    167179        source ~= "}"; 
    168180 
  • branches/tango.test/tango/test/dtcc/Lexer.d

    r3991 r4003  
    143143 
    144144                    endDescription++; 
    145                     tokenList.addNew(TokenType.TestDescription, source[currentIndex..endDescription]); 
     145                    tokenList.addNew(TokenType.TestDescription, source[currentIndex..endDescription], linesCountForIndex(currentIndex)); 
    146146                    currentIndex = endDescription; 
    147147                    continue; 
     
    154154                auto codeBlock = consumeDCodeBlock!(T)(source, currentIndex); 
    155155 
    156                 tokenList.addNew(TokenType.TestCodeBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); 
     156                tokenList.addNew(TokenType.TestCodeBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], 
     157                                 linesCountForIndex(codeBlock["startDCodeBlock"])); 
    157158 
    158159                currentIndex = codeBlock["endDCodeBlock"]; 
     
    172173                     
    173174                    tokenList.addNew(TokenType.CollectionStatement,  
    174                                      source[collectionIndices["startName"]..collectionIndices["endName"]]); 
     175                                     source[collectionIndices["startName"]..collectionIndices["endName"]], 
     176                                     linesCountForIndex(collectionIndices["startName"])); 
    175177 
    176178                    currentIndex = collectionIndices["endCollection"]; 
     
    181183 
    182184                    tokenList.addNew(TokenType.ImportStatement, 
    183                                      source[importIndices["startImport"]..importIndices["endImport"]]); 
     185                                     source[importIndices["startImport"]..importIndices["endImport"]], 
     186                                     linesCountForIndex(importIndices["startImport"])); 
    184187 
    185188                    currentIndex = importIndices["endImport"]; 
     
    201204 
    202205                    if (tokenIdentifier == "fixtures") 
    203                         tokenList.addNew(TokenType.FixturesBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); 
     206                        tokenList.addNew(TokenType.FixturesBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], 
     207                                         linesCountForIndex(codeBlock["startDCodeBlock"])); 
    204208                    if (tokenIdentifier == "initialize") 
    205209                        tokenList.addNew(TokenType.InitializeCodeBlock, 
    206                                          source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); 
     210                                         source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], 
     211                                         linesCountForIndex(codeBlock["startDCodeBlock"])); 
    207212                    if (tokenIdentifier == "finalize") 
    208213                        tokenList.addNew(TokenType.FinalizeCodeBlock, 
    209                                          source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); 
     214                                         source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], 
     215                                         linesCountForIndex(codeBlock["startDCodeBlock"])); 
    210216 
    211217 
     
    235241 
    236242                    tokenList.addNew(TokenType.HelperCodeBlock, 
    237                                      source[currentIndex + "Helper".length..helperIndices["endDCodeBlock"]]); 
     243                                     source[currentIndex + "Helper".length..helperIndices["endDCodeBlock"]], 
     244                                     linesCountForIndex(currentIndex)); 
    238245                    currentIndex = helperIndices["endDCodeBlock"]; 
    239246                    continue; 
     
    242249                    auto identifierIndices = consumeWord!(T)(source, currentIndex); 
    243250 
    244                     tokenList.addNew(TokenType.TestIdentifier, source[identifierIndices["startWord"]..identifierIndices["endWord"]]); 
     251                    tokenList.addNew(TokenType.TestIdentifier, source[identifierIndices["startWord"]..identifierIndices["endWord"]], 
     252                                     linesCountForIndex(identifierIndices["startWord"])); 
    245253 
    246254                    currentIndex = identifierIndices["endWord"]; 
  • branches/tango.test/tango/test/dtcc/Token.d

    r3985 r4003  
    5959    T[]       value; 
    6060    TokenType type; 
     61    uint      line; 
    6162 
    62     public this (TokenType _type, T[] _value, Token!(T) _previous) { 
     63    public this (TokenType _type, T[] _value, Token!(T) _previous, uint _line = 0) { 
    6364        type = _type; 
    6465        value = _value; 
    6566        previous = _previous; 
     67        line = _line; 
    6668        next = null; 
    6769    } 
     
    7577    Token!(T) [] tokens; 
    7678 
    77     void addNew (TokenType type, T[] value = "") { 
    78         auto token = new Token!(T)(type, value, (tokens.length ? tokens[$ - 1] : null)); 
     79    void addNew (TokenType type, T[] value = "", uint line = 0) { 
     80        auto token = new Token!(T)(type, value, (tokens.length ? tokens[$ - 1] : null), line); 
    7981        if (tokens.length) { tokens[$ - 1].next = token; } 
    8082        tokens ~= token;