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..ea0bc659b33309ac707c0b97c13394fea940d44e |
--- /dev/null |
+++ b/tests/standalone/io/addlatexhash_test.dart |
@@ -0,0 +1,112 @@ |
+// 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 'package:path/path.dart' as path; |
+import '../../../tools/addlatexhash.dart'; |
+ |
+final scriptDir = path.dirname(path.fromUri(Platform.script)); |
+final dartRootDir = path.dirname(path.dirname(path.dirname(scriptDir))); |
+final dartRootPath = dartRootDir.toString(); |
+ |
+// Check that the given ProcessResult indicates success; if so |
+// return the standard output, otherwise report the failure |
+checkAction(result, errorMessage) { |
+ var output = result.stdout; |
ricow1
2014/10/15 08:29:05
there is not really any good reason to do this ass
eernst
2014/10/15 11:03:04
OK, I did that because I envision (1) result.stdou
|
+ if (result.exitCode != 0) { |
+ print(output); |
+ print(result.stderr); |
+ throw errorMessage; |
+ } |
+ return output; |
+} |
+ |
+oneTestCutMatch(line, re, expected) { |
+ var result = cutMatch(line, new RegExp(re).firstMatch(line)); |
+ if (result != expected) { |
+ throw "cutMatch '$re' from '$line' yields '$result' != '$expected'"; |
+ } |
+} |
+ |
+void testCutMatch() { |
+ oneTestCutMatch("test", "", "test"); |
+ oneTestCutMatch("test", "e", "tst"); |
+ oneTestCutMatch("test", "te", "st"); |
+ oneTestCutMatch("test", "st", "te"); |
+ oneTestCutMatch("test", "test", ""); |
+} |
+ |
+oneTestSisp(sispFun, nameSuffix, line, expected) { |
+ var result = sispFun(line); |
+ if (result != expected) { |
+ throw "sispIsDart$nameSuffix '$line' yields $result"; |
+ } |
+} |
+ |
+testSisp() { |
+ oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true); |
+ oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true); |
+ oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false); |
+ oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true); |
+ oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true); |
+ oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false); |
+} |
+ |
+// Check that the LaTeX source transformation done by addlatexhash.dart |
+// does not affect the generated output, as seen via dvi2tty and diff. |
+// NB: Not part of normal testing (only local): latex and dvi2tty are |
+// not installed in the standard test environment. |
+testNoChange() { |
+ var tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
+ final tmpDirPath = tmpDir.path; |
+ final specDirPath = path.join(dartRootDir, "docs", "language"); |
+ const specName = "dartLangSpec"; |
+ final specFileName = "${specName}.tex"; |
+ final specPath = path.join(specDirPath, specFileName); |
+ const styFileName = "dart.sty"; |
+ final styPath = path.join(specDirPath, styFileName); |
+ const tmpName = "dartLangSpec-hash"; |
+ final tmpFileName = "${tmpName}.tex"; |
+ final tmpFilePath = path.join(tmpDirPath, tmpFileName); |
+ final specDviFileName = "${specName}.dvi"; |
+ final specDviPath = path.join(specDirPath, specDviFileName); |
+ final tmpDviPath = path.join(tmpDirPath, "${tmpName}.dvi"); |
+ |
+ 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++) { |
+ checkAction(runLatex(specPath, specDirPath), "LaTeX on spec failed"); |
+ } |
+ checkAction(runAddHash(),"addlatexhash.dart failed"); |
+ new File(styPath).copySync("$tmpDirPath/$styFileName"); |
+ for (var i = 0; i < 5; i++) { |
+ 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(); |
+} |