Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // testing ../../../tools/addlatexhash.dart | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 import '../../../tools/addlatexhash.dart'; | |
| 9 | |
| 10 final uri = Platform.script; | |
| 11 final pathList = new List.from(uri.pathSegments)..removeLast(); | |
| 12 final dartRootPath = "/" + pathList.join("/") + "/../../.."; | |
|
ricow1
2014/10/14 06:09:10
you can do:
import 'package:path/path.dart';
and u
eernst
2014/10/14 15:06:22
OK, required a '--package-root=$dartroot/out/Relea
ricow1
2014/10/15 08:29:05
Yep, that is automatically passed to the vm for th
| |
| 13 | |
| 14 // Check that the given ProcessResult indicates success; if so return | |
| 15 // the standard output, otherwise report the failure | |
|
ricow1
2014/10/14 06:09:10
comment is wrong, since this is not what we are do
eernst
2014/10/14 15:06:22
.. or throw; but the comment should be much more t
| |
| 16 checkAction(ProcessResult result, String errorMessage) { | |
| 17 var output; | |
|
ricow1
2014/10/14 06:09:10
you need to set output here, otherwise it will not
eernst
2014/10/14 15:06:22
Forgot to resolve the case: Is a ProcessResult ev
| |
| 18 if (result.exitCode != 0) { | |
| 19 output = result.stdout; | |
| 20 print(output); | |
| 21 print(result.stderr); | |
| 22 throw errorMessage; | |
| 23 } | |
| 24 return output; | |
| 25 } | |
| 26 | |
| 27 // testing cutMatch | |
|
ricow1
2014/10/14 06:09:10
Remove comment, obvious
eernst
2014/10/14 15:06:22
Done.
| |
| 28 | |
| 29 oneTestCutMatch(line, re, expected) { | |
| 30 // Code which is commented out: useful during debugging | |
|
ricow1
2014/10/14 06:09:10
we don't do commented out code, not in production
eernst
2014/10/14 15:06:22
Sounds nice and clean!
But then what's the right
ricow1
2014/10/15 08:29:05
well, normally when you need to debug the info you
| |
| 31 // stdout.write("cutMatch: ${line} --[${re}]--> "); | |
| 32 var result = cutMatch(line, new RegExp(re).firstMatch(line)); | |
| 33 // stdout.write(result + "\n"); | |
| 34 return expected == result; | |
| 35 } | |
| 36 | |
| 37 testCutMatch() { | |
| 38 oneTestCutMatch("test", "e", "tst") && | |
| 39 oneTestCutMatch("test", "te", "st") && | |
| 40 oneTestCutMatch("test", "st", "te") && | |
| 41 oneTestCutMatch("test", "", "test") && | |
| 42 oneTestCutMatch("test", "test", "") | |
| 43 ? "OK" : throw "Failed in testCutMatch"; | |
|
ricow1
2014/10/14 06:09:10
I would structure this differently. When this fail
eernst
2014/10/14 15:06:22
Done.
| |
| 44 } | |
| 45 | |
| 46 // testing sisp* functions | |
|
ricow1
2014/10/14 06:09:10
same as above
eernst
2014/10/14 15:06:23
Done.
| |
| 47 | |
| 48 oneTestSisp(sispFun, line, expectation) { | |
| 49 var result = sispFun(line) == expectation; | |
| 50 // stdout.write("sispIsDart*: ${line}: ${expectation}\n"); | |
|
ricow1
2014/10/14 06:09:10
no commented out code
eernst
2014/10/14 15:06:22
Done.
| |
| 51 return result; | |
| 52 } | |
| 53 | |
| 54 testSisp() { | |
| 55 oneTestSisp(sispIsDartBegin, "\\begin{dartCode}\n", true) && | |
| 56 oneTestSisp(sispIsDartBegin, " \\begin{dartCode}\n", true) && | |
| 57 oneTestSisp(sispIsDartBegin, "whatever else ..", false) && | |
| 58 oneTestSisp(sispIsDartEnd, "\\end{dartCode}", true) && | |
| 59 oneTestSisp(sispIsDartEnd, " \\end{dartCode}\t \n", true) && | |
| 60 oneTestSisp(sispIsDartEnd, "whatever else ..", false) | |
| 61 ? "OK" : throw "Failed in testSisp"; | |
|
ricow1
2014/10/14 06:09:10
Same comment as above, throw in the oneTestSisp fu
eernst
2014/10/14 15:06:22
Done.
| |
| 62 } | |
| 63 | |
| 64 testNoChange() { | |
|
ricow1
2014/10/14 06:09:11
Explicitly state that this is _not_ run as part of
eernst
2014/10/14 15:06:22
Done.
| |
| 65 // tmp storage area | |
| 66 var tmpDir = Directory.systemTemp.createTempSync('addlatexhash_test'); | |
| 67 | |
| 68 // actions | |
|
ricow1
2014/10/14 06:09:10
this is not actions? (also, we don't normally name
eernst
2014/10/14 15:06:23
Done.
| |
| 69 final tmpDirPath = tmpDir.path; | |
|
ricow1
2014/10/14 06:09:10
for all of this and the below also use the path pa
eernst
2014/10/14 15:06:22
Done.
| |
| 70 final specDirPath = dartRootPath + "/docs/language"; | |
|
ricow1
2014/10/14 06:09:10
as stated above, use the path package. That said,
eernst
2014/10/14 15:06:22
Done.
| |
| 71 const specName = "dartLangSpec"; | |
| 72 final specFileName = specName + ".tex"; | |
| 73 final specPath = specDirPath + "/" + specFileName; | |
| 74 const styFileName = "dart.sty"; | |
| 75 final styPath = specDirPath + "/" + styFileName; | |
| 76 const tmpName = "dartLangSpec-hash"; | |
| 77 final tmpFileName = tmpName + ".tex"; | |
| 78 final tmpFilePath = tmpDirPath + "/" + tmpFileName; | |
| 79 final specDviFileName = specName + ".dvi"; | |
| 80 final specDviPath = specDirPath + "/" + specDviFileName; | |
| 81 final tmpDviPath = tmpDirPath + "/" + tmpName + ".dvi"; | |
| 82 | |
| 83 // shorthand for actions | |
| 84 runLatex(fileName,workingDirectory) => Process.runSync( | |
| 85 "latex", | |
| 86 [fileName], | |
| 87 workingDirectory: workingDirectory); | |
| 88 runAddHash() => Process.runSync( | |
| 89 "dart", | |
| 90 [dartRootPath + "/tools/addlatexhash.dart", | |
| 91 dartRootPath + "/docs/language/dartLangSpec.tex", | |
| 92 tmpDir.path + "/dartLangSpec-hash.tex"]); | |
| 93 runDvi2tty(dviFile) => Process.runSync( | |
| 94 "dvi2tty", | |
| 95 [dviFile], | |
| 96 workingDirectory: tmpDir.path); | |
| 97 chkDvi2tty(file, subject) => | |
| 98 checkAction(runDvi2tty(file), "dvitty on $subject failed"); | |
| 99 | |
| 100 for (var i=0; i<5; i++) { | |
|
ricow1
2014/10/14 06:09:10
space around = and <
eernst
2014/10/14 15:06:22
Done.
| |
| 101 checkAction(runLatex(specPath, specDirPath), "LaTeX on spec failed"); | |
| 102 } | |
| 103 checkAction(runAddHash(),"addlatexhash.dart failed"); | |
| 104 checkAction(Process.runSync("cp", [styPath, tmpDirPath]), | |
|
ricow1
2014/10/14 06:09:10
new File('styPath').copySync('$tmpDirPath/$styFile
eernst
2014/10/14 15:06:22
Done, except using plain styPath.
| |
| 105 "copying dart.sty failed"); | |
| 106 for (var i=0; i<5; i++) { | |
|
ricow1
2014/10/14 06:09:11
space around = and <
eernst
2014/10/14 15:06:22
Done.
| |
| 107 checkAction(runLatex(tmpFileName, tmpDirPath), "LaTeX on output failed"); | |
| 108 } | |
| 109 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(tmpDviPath, "output")) { | |
| 110 throw "dvi2tty spec != dvitty output"; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 main([args]) { | |
| 115 testCutMatch(); | |
| 116 testSisp(); | |
| 117 // latex and dvi2tty are not installed in the standard test environment | |
| 118 if (args.length > 0 && args[0] == "local") testNoChange(); | |
| 119 } | |
| OLD | NEW |