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 'package:path/path.dart' as path; |
| 9 import '../../../tools/addlatexhash.dart'; |
| 10 |
| 11 final scriptDir = path.dirname(path.fromUri(Platform.script)); |
| 12 final dartRootDir = path.dirname(path.dirname(path.dirname(scriptDir))); |
| 13 final dartRootPath = dartRootDir.toString(); |
| 14 |
| 15 // Check that the given ProcessResult indicates success; if so |
| 16 // return the standard output, otherwise report the failure |
| 17 checkAction(result, errorMessage) { |
| 18 if (result.exitCode != 0) { |
| 19 print(result.stdout); |
| 20 print(result.stderr); |
| 21 throw errorMessage; |
| 22 } |
| 23 return result.stdout; |
| 24 } |
| 25 |
| 26 oneTestCutMatch(line, re, expected) { |
| 27 var result = cutMatch(line, new RegExp(re).firstMatch(line)); |
| 28 if (result != expected) { |
| 29 throw "cutMatch '$re' from '$line' yields '$result' != '$expected'"; |
| 30 } |
| 31 } |
| 32 |
| 33 void testCutMatch() { |
| 34 oneTestCutMatch("test", "", "test"); |
| 35 oneTestCutMatch("test", "e", "tst"); |
| 36 oneTestCutMatch("test", "te", "st"); |
| 37 oneTestCutMatch("test", "st", "te"); |
| 38 oneTestCutMatch("test", "test", ""); |
| 39 } |
| 40 |
| 41 oneTestSisp(sispFun, nameSuffix, line, expected) { |
| 42 var result = sispFun(line); |
| 43 if (result != expected) { |
| 44 throw "sispIsDart$nameSuffix '$line' yields $result"; |
| 45 } |
| 46 } |
| 47 |
| 48 testSisp() { |
| 49 oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true); |
| 50 oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true); |
| 51 oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false); |
| 52 oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true); |
| 53 oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true); |
| 54 oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false); |
| 55 } |
| 56 |
| 57 // Check that the LaTeX source transformation done by addlatexhash.dart |
| 58 // does not affect the generated output, as seen via dvi2tty and diff. |
| 59 // NB: Not part of normal testing (only local): latex and dvi2tty are |
| 60 // not installed in the standard test environment. |
| 61 testNoChange() { |
| 62 // set up /tmp directory to hold output |
| 63 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
| 64 final tmpDirPath = tmpDir.path; |
| 65 |
| 66 // file names/paths for original spec |
| 67 const specName = "dartLangSpec"; |
| 68 const specFileName = "$specName.tex"; |
| 69 final specDirPath = path.join(dartRootDir, "docs", "language"); |
| 70 final specPath = path.join(specDirPath, specFileName); |
| 71 final tmpSpecPath = path.join(tmpDirPath, specFileName); |
| 72 const specDviFileName = "$specName.dvi"; |
| 73 final specDviPath = path.join(tmpDirPath, specDviFileName); |
| 74 |
| 75 // file names/paths for associated sty |
| 76 const styFileName = "dart.sty"; |
| 77 final styPath = path.join(specDirPath, styFileName); |
| 78 final tmpStyPath = path.join(tmpDirPath, styFileName); |
| 79 |
| 80 // file names paths for output |
| 81 const hashName = "dartLangSpec-hash"; |
| 82 const hashFileName = "$hashName.tex"; |
| 83 final hashPath = path.join(tmpDirPath, hashFileName); |
| 84 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); |
| 85 |
| 86 // actions to take |
| 87 runLatex(fileName,workingDirectory) => |
| 88 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
| 89 |
| 90 runAddHash() => |
| 91 Process.runSync("dart", |
| 92 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 93 tmpSpecPath, |
| 94 hashPath]); |
| 95 |
| 96 runDvi2tty(dviFile) => |
| 97 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); |
| 98 |
| 99 chkDvi2tty(file, subject) => |
| 100 checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
| 101 |
| 102 // perform test |
| 103 new File(styPath).copySync(tmpStyPath); |
| 104 new File(specPath).copySync(tmpSpecPath); |
| 105 for (var i = 0; i < 5; i++) { |
| 106 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
| 107 } |
| 108 checkAction(runAddHash(),"addlatexhash.dart failed"); |
| 109 for (var i = 0; i < 5; i++) { |
| 110 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
| 111 } |
| 112 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { |
| 113 throw "dvi2tty spec != dvitty output"; |
| 114 } |
| 115 } |
| 116 |
| 117 main([args]) { |
| 118 testCutMatch(); |
| 119 testSisp(); |
| 120 // latex and dvi2tty are not installed in the standard test environment |
| 121 if (args.length > 0 && args[0] == "local") testNoChange(); |
| 122 } |
OLD | NEW |