Index: tests/standalone/io/addlatexhash_test.dart |
diff --git a/tests/standalone/io/addlatexhash_test.dart b/tests/standalone/io/addlatexhash_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..714a4bd39c4d3fd29abdfadf63a19c255cc6f88e |
--- /dev/null |
+++ b/tests/standalone/io/addlatexhash_test.dart |
@@ -0,0 +1,119 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+// testing ../../../tools/addlatexhash.dart |
+ |
+import 'dart:io'; |
+import '../../../tools/addlatexhash.dart'; |
+ |
+final uri = Platform.script; |
+final pathList = new List.from(uri.pathSegments)..removeLast(); |
+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
|
+ |
+// Check that the given ProcessResult indicates success; if so return |
+// 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
|
+checkAction(ProcessResult result, String errorMessage) { |
+ 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
|
+ if (result.exitCode != 0) { |
+ output = result.stdout; |
+ print(output); |
+ print(result.stderr); |
+ throw errorMessage; |
+ } |
+ return output; |
+} |
+ |
+// testing cutMatch |
ricow1
2014/10/14 06:09:10
Remove comment, obvious
eernst
2014/10/14 15:06:22
Done.
|
+ |
+oneTestCutMatch(line, re, expected) { |
+ // 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
|
+ // stdout.write("cutMatch: ${line} --[${re}]--> "); |
+ var result = cutMatch(line, new RegExp(re).firstMatch(line)); |
+ // stdout.write(result + "\n"); |
+ return expected == result; |
+} |
+ |
+testCutMatch() { |
+ oneTestCutMatch("test", "e", "tst") && |
+ oneTestCutMatch("test", "te", "st") && |
+ oneTestCutMatch("test", "st", "te") && |
+ oneTestCutMatch("test", "", "test") && |
+ oneTestCutMatch("test", "test", "") |
+ ? "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.
|
+} |
+ |
+// testing sisp* functions |
ricow1
2014/10/14 06:09:10
same as above
eernst
2014/10/14 15:06:23
Done.
|
+ |
+oneTestSisp(sispFun, line, expectation) { |
+ var result = sispFun(line) == expectation; |
+ // 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.
|
+ return result; |
+} |
+ |
+testSisp() { |
+ oneTestSisp(sispIsDartBegin, "\\begin{dartCode}\n", true) && |
+ oneTestSisp(sispIsDartBegin, " \\begin{dartCode}\n", true) && |
+ oneTestSisp(sispIsDartBegin, "whatever else ..", false) && |
+ oneTestSisp(sispIsDartEnd, "\\end{dartCode}", true) && |
+ oneTestSisp(sispIsDartEnd, " \\end{dartCode}\t \n", true) && |
+ oneTestSisp(sispIsDartEnd, "whatever else ..", false) |
+ ? "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.
|
+} |
+ |
+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.
|
+ // tmp storage area |
+ var tmpDir = Directory.systemTemp.createTempSync('addlatexhash_test'); |
+ |
+ // 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.
|
+ 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.
|
+ 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.
|
+ const specName = "dartLangSpec"; |
+ final specFileName = specName + ".tex"; |
+ final specPath = specDirPath + "/" + specFileName; |
+ const styFileName = "dart.sty"; |
+ final styPath = specDirPath + "/" + styFileName; |
+ const tmpName = "dartLangSpec-hash"; |
+ final tmpFileName = tmpName + ".tex"; |
+ final tmpFilePath = tmpDirPath + "/" + tmpFileName; |
+ final specDviFileName = specName + ".dvi"; |
+ final specDviPath = specDirPath + "/" + specDviFileName; |
+ final tmpDviPath = tmpDirPath + "/" + tmpName + ".dvi"; |
+ |
+ // shorthand for actions |
+ runLatex(fileName,workingDirectory) => Process.runSync( |
+ "latex", |
+ [fileName], |
+ workingDirectory: workingDirectory); |
+ runAddHash() => Process.runSync( |
+ "dart", |
+ [dartRootPath + "/tools/addlatexhash.dart", |
+ dartRootPath + "/docs/language/dartLangSpec.tex", |
+ tmpDir.path + "/dartLangSpec-hash.tex"]); |
+ runDvi2tty(dviFile) => Process.runSync( |
+ "dvi2tty", |
+ [dviFile], |
+ workingDirectory: tmpDir.path); |
+ chkDvi2tty(file, subject) => |
+ checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
+ |
+ 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.
|
+ checkAction(runLatex(specPath, specDirPath), "LaTeX on spec failed"); |
+ } |
+ checkAction(runAddHash(),"addlatexhash.dart failed"); |
+ 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.
|
+ "copying dart.sty failed"); |
+ 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.
|
+ checkAction(runLatex(tmpFileName, tmpDirPath), "LaTeX on output failed"); |
+ } |
+ if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(tmpDviPath, "output")) { |
+ throw "dvi2tty spec != dvitty output"; |
+ } |
+} |
+ |
+main([args]) { |
+ testCutMatch(); |
+ testSisp(); |
+ // latex and dvi2tty are not installed in the standard test environment |
+ if (args.length > 0 && args[0] == "local") testNoChange(); |
+} |