 |
Changeset 4003
- 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
| r3985 |
r4003 |
|
| 37 | 37 | TestMethodDelegate dg; |
|---|
| 38 | 38 | char[] name; |
|---|
| | 39 | bool called; |
|---|
| | 40 | |
|---|
| | 41 | public void call () { |
|---|
| | 42 | if (!called) dg(); |
|---|
| | 43 | } |
|---|
| 39 | 44 | |
|---|
| 40 | 45 | public static TestMethod opCall (TestMethodDelegate dg, char[] name) { |
|---|
| r3985 |
r4003 |
|
| 45 | 45 | else Stdout.format(" ({}/{}) {}:", testMethodIndex + 1, testCase.testMethods.length, testMethod.name); |
|---|
| 46 | 46 | |
|---|
| 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); |
|---|
| 51 | 53 | } |
|---|
| 52 | 54 | } |
|---|
| r3991 |
r4003 |
|
| 15 | 15 | |
|---|
| 16 | 16 | import tango.text.Util; |
|---|
| | 17 | |
|---|
| | 18 | import tango.text.convert.Layout; |
|---|
| 17 | 19 | |
|---|
| 18 | 20 | import tango.test.dtcc.Token; |
|---|
| … | … | |
| 133 | 135 | |
|---|
| 134 | 136 | 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); |
|---|
| 136 | 139 | |
|---|
| 137 | 140 | foreach (importStatement; importStatements) { source ~= importStatement ~ "\n"; } |
|---|
| 138 | 141 | |
|---|
| 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); |
|---|
| 142 | 144 | source ~= fixtures ~ "\n"; |
|---|
| 143 | 145 | source ~= "this () {\n"; |
|---|
| 144 | | source ~= "name = \"" ~ collectionName ~ "\";\n"; |
|---|
| | 146 | source ~= s.convert("name = \"{0}\";\n", collectionName); |
|---|
| 145 | 147 | |
|---|
| 146 | 148 | /* We ignore the before and after stuff for now, as itâs not implemented in |
|---|
| … | … | |
| 150 | 152 | |
|---|
| 151 | 153 | 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 | } |
|---|
| 153 | 156 | |
|---|
| 154 | 157 | source ~= "}\n"; |
|---|
| 155 | 158 | |
|---|
| 156 | 159 | 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 | } |
|---|
| 158 | 170 | |
|---|
| 159 | 171 | 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); |
|---|
| 161 | 173 | } else { |
|---|
| 162 | | source ~= testMethod.codeBlock ~ "return Test.Status.Success; }\n"; |
|---|
| | 174 | source ~= s.convert("{0} return Test.Status.Success; }\n", codeBlock); |
|---|
| 163 | 175 | } |
|---|
| 164 | 176 | } |
|---|
| 165 | 177 | |
|---|
| 166 | | foreach (helperMethod; helperMethods) { source ~= helperMethod ~ "\n"; } |
|---|
| | 178 | foreach (helperMethod; helperMethods) { source ~= s.convert("{0}\n", helperMethod); } |
|---|
| 167 | 179 | source ~= "}"; |
|---|
| 168 | 180 | |
|---|
| r3991 |
r4003 |
|
| 143 | 143 | |
|---|
| 144 | 144 | endDescription++; |
|---|
| 145 | | tokenList.addNew(TokenType.TestDescription, source[currentIndex..endDescription]); |
|---|
| | 145 | tokenList.addNew(TokenType.TestDescription, source[currentIndex..endDescription], linesCountForIndex(currentIndex)); |
|---|
| 146 | 146 | currentIndex = endDescription; |
|---|
| 147 | 147 | continue; |
|---|
| … | … | |
| 154 | 154 | auto codeBlock = consumeDCodeBlock!(T)(source, currentIndex); |
|---|
| 155 | 155 | |
|---|
| 156 | | tokenList.addNew(TokenType.TestCodeBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); |
|---|
| | 156 | tokenList.addNew(TokenType.TestCodeBlock, source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], |
|---|
| | 157 | linesCountForIndex(codeBlock["startDCodeBlock"])); |
|---|
| 157 | 158 | |
|---|
| 158 | 159 | currentIndex = codeBlock["endDCodeBlock"]; |
|---|
| … | … | |
| 172 | 173 | |
|---|
| 173 | 174 | tokenList.addNew(TokenType.CollectionStatement, |
|---|
| 174 | | source[collectionIndices["startName"]..collectionIndices["endName"]]); |
|---|
| | 175 | source[collectionIndices["startName"]..collectionIndices["endName"]], |
|---|
| | 176 | linesCountForIndex(collectionIndices["startName"])); |
|---|
| 175 | 177 | |
|---|
| 176 | 178 | currentIndex = collectionIndices["endCollection"]; |
|---|
| … | … | |
| 181 | 183 | |
|---|
| 182 | 184 | tokenList.addNew(TokenType.ImportStatement, |
|---|
| 183 | | source[importIndices["startImport"]..importIndices["endImport"]]); |
|---|
| | 185 | source[importIndices["startImport"]..importIndices["endImport"]], |
|---|
| | 186 | linesCountForIndex(importIndices["startImport"])); |
|---|
| 184 | 187 | |
|---|
| 185 | 188 | currentIndex = importIndices["endImport"]; |
|---|
| … | … | |
| 201 | 204 | |
|---|
| 202 | 205 | 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"])); |
|---|
| 204 | 208 | if (tokenIdentifier == "initialize") |
|---|
| 205 | 209 | tokenList.addNew(TokenType.InitializeCodeBlock, |
|---|
| 206 | | source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); |
|---|
| | 210 | source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], |
|---|
| | 211 | linesCountForIndex(codeBlock["startDCodeBlock"])); |
|---|
| 207 | 212 | if (tokenIdentifier == "finalize") |
|---|
| 208 | 213 | tokenList.addNew(TokenType.FinalizeCodeBlock, |
|---|
| 209 | | source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]]); |
|---|
| | 214 | source[codeBlock["startDCodeBlock"]..codeBlock["endDCodeBlock"]], |
|---|
| | 215 | linesCountForIndex(codeBlock["startDCodeBlock"])); |
|---|
| 210 | 216 | |
|---|
| 211 | 217 | |
|---|
| … | … | |
| 235 | 241 | |
|---|
| 236 | 242 | tokenList.addNew(TokenType.HelperCodeBlock, |
|---|
| 237 | | source[currentIndex + "Helper".length..helperIndices["endDCodeBlock"]]); |
|---|
| | 243 | source[currentIndex + "Helper".length..helperIndices["endDCodeBlock"]], |
|---|
| | 244 | linesCountForIndex(currentIndex)); |
|---|
| 238 | 245 | currentIndex = helperIndices["endDCodeBlock"]; |
|---|
| 239 | 246 | continue; |
|---|
| … | … | |
| 242 | 249 | auto identifierIndices = consumeWord!(T)(source, currentIndex); |
|---|
| 243 | 250 | |
|---|
| 244 | | tokenList.addNew(TokenType.TestIdentifier, source[identifierIndices["startWord"]..identifierIndices["endWord"]]); |
|---|
| | 251 | tokenList.addNew(TokenType.TestIdentifier, source[identifierIndices["startWord"]..identifierIndices["endWord"]], |
|---|
| | 252 | linesCountForIndex(identifierIndices["startWord"])); |
|---|
| 245 | 253 | |
|---|
| 246 | 254 | currentIndex = identifierIndices["endWord"]; |
|---|
| r3985 |
r4003 |
|
| 59 | 59 | T[] value; |
|---|
| 60 | 60 | TokenType type; |
|---|
| | 61 | uint line; |
|---|
| 61 | 62 | |
|---|
| 62 | | public this (TokenType _type, T[] _value, Token!(T) _previous) { |
|---|
| | 63 | public this (TokenType _type, T[] _value, Token!(T) _previous, uint _line = 0) { |
|---|
| 63 | 64 | type = _type; |
|---|
| 64 | 65 | value = _value; |
|---|
| 65 | 66 | previous = _previous; |
|---|
| | 67 | line = _line; |
|---|
| 66 | 68 | next = null; |
|---|
| 67 | 69 | } |
|---|
| … | … | |
| 75 | 77 | Token!(T) [] tokens; |
|---|
| 76 | 78 | |
|---|
| 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); |
|---|
| 79 | 81 | if (tokens.length) { tokens[$ - 1].next = token; } |
|---|
| 80 | 82 | tokens ~= token; |
|---|
Download in other formats:
|
 |