| OLD | NEW |
| 1 #!/usr/bin/env dart |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 2 // 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 // 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 // BSD-style license that can be found in the LICENSE file. |
| 4 | 5 |
| 5 // testing ../../../tools/addlatexhash.dart | 6 // testing ../../../tools/addlatexhash.dart |
| 6 | 7 |
| 7 import 'dart:io'; | 8 import 'dart:io'; |
| 8 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 9 import '../../../tools/addlatexhash.dart'; | 10 import '../../../tools/addlatexhash.dart'; |
| 10 | 11 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 48 |
| 48 testSisp() { | 49 testSisp() { |
| 49 oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true); | 50 oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true); |
| 50 oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true); | 51 oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true); |
| 51 oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false); | 52 oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false); |
| 52 oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true); | 53 oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true); |
| 53 oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true); | 54 oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true); |
| 54 oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false); | 55 oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false); |
| 55 } | 56 } |
| 56 | 57 |
| 58 // Check that the hash values of paragraphs in the specially prepared |
| 59 // LaTeX source 'addlatexhash_test_src.tex' are identical in groups |
| 60 // of eight (so we get 8 identical hash values, then another hash |
| 61 // value 8 times, etc.) |
| 62 testSameHash() { |
| 63 // set up temporary directory to hold output |
| 64 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
| 65 final tmpDirPath = tmpDir.path; |
| 66 |
| 67 // file names/paths for file containing groups of 8 variants of a paragraph |
| 68 const par8timesName = "addlatexhash_test_src"; |
| 69 const par8timesFileName = "$par8timesName.tex"; |
| 70 final par8timesDirPath = path.join(dartRootDir, "tests", "standalone", "io"); |
| 71 final par8timesPath = path.join(par8timesDirPath, par8timesFileName); |
| 72 final tmpPar8timesPath = path.join(tmpDirPath, par8timesFileName); |
| 73 |
| 74 // file names paths for output |
| 75 final hashName = par8timesName + "-hash"; |
| 76 final hashFileName = "$hashName.tex"; |
| 77 final hashPath = path.join(tmpDirPath, hashFileName); |
| 78 final listName = par8timesName + "-list"; |
| 79 final listFileName = "$listName.txt"; |
| 80 final listPath = path.join(tmpDirPath, listFileName); |
| 81 |
| 82 // actions to take |
| 83 runAddHash() => |
| 84 Process.runSync("dart", |
| 85 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 86 tmpPar8timesPath, |
| 87 hashPath, |
| 88 listPath]); |
| 89 |
| 90 // perform test |
| 91 new File(par8timesPath).copySync(tmpPar8timesPath); |
| 92 checkAction(runAddHash(), "addlatexhash.dart failed"); |
| 93 var listFile = new File(listPath); |
| 94 var listLines = listFile.readAsLinesSync(); |
| 95 var latestLine = null; |
| 96 var sameCount = 0; |
| 97 for (var line in listLines) { |
| 98 if (!line.startsWith(" ")) continue; // section marker |
| 99 if (line.startsWith(" %")) continue; // transformed text "comment" |
| 100 if (line != latestLine) { |
| 101 // new hash, check for number of equal hashes, then reset |
| 102 if (sameCount % 8 == 0) { |
| 103 // saw zero or more blocks of 8 identical hash values: OK |
| 104 latestLine = line; |
| 105 sameCount = 1; |
| 106 } else { |
| 107 throw "normalization failed to produce same result"; |
| 108 } |
| 109 } else { |
| 110 sameCount++; |
| 111 } |
| 112 } |
| 113 } |
| 114 |
| 57 // Check that the LaTeX source transformation done by addlatexhash.dart | 115 // Check that the LaTeX source transformation done by addlatexhash.dart |
| 58 // does not affect the generated output, as seen via dvi2tty and diff. | 116 // 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 | 117 // NB: Not part of normal testing (only local): latex and dvi2tty are |
| 60 // not installed in the standard test environment. | 118 // not installed in the standard test environment. |
| 61 testNoChange() { | 119 testSameDVI() { |
| 62 // set up /tmp directory to hold output | 120 // set up /tmp directory to hold output |
| 63 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); | 121 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
| 64 final tmpDirPath = tmpDir.path; | 122 final tmpDirPath = tmpDir.path; |
| 65 | 123 |
| 66 // file names/paths for original spec | 124 // file names/paths for original spec |
| 67 const specName = "dartLangSpec"; | 125 const specName = "dartLangSpec"; |
| 68 const specFileName = "$specName.tex"; | 126 const specFileName = "$specName.tex"; |
| 69 final specDirPath = path.join(dartRootDir, "docs", "language"); | 127 final specDirPath = path.join(dartRootDir, "docs", "language"); |
| 70 final specPath = path.join(specDirPath, specFileName); | 128 final specPath = path.join(specDirPath, specFileName); |
| 71 final tmpSpecPath = path.join(tmpDirPath, specFileName); | 129 final tmpSpecPath = path.join(tmpDirPath, specFileName); |
| 72 const specDviFileName = "$specName.dvi"; | 130 const specDviFileName = "$specName.dvi"; |
| 73 final specDviPath = path.join(tmpDirPath, specDviFileName); | 131 final specDviPath = path.join(tmpDirPath, specDviFileName); |
| 74 | 132 |
| 75 // file names/paths for associated sty | 133 // file names/paths for associated sty |
| 76 const styFileName = "dart.sty"; | 134 const styFileName = "dart.sty"; |
| 77 final styPath = path.join(specDirPath, styFileName); | 135 final styPath = path.join(specDirPath, styFileName); |
| 78 final tmpStyPath = path.join(tmpDirPath, styFileName); | 136 final tmpStyPath = path.join(tmpDirPath, styFileName); |
| 79 | 137 |
| 80 // file names paths for output | 138 // file names paths for output |
| 81 const hashName = "dartLangSpec-hash"; | 139 const hashName = "dartLangSpec-hash"; |
| 82 const hashFileName = "$hashName.tex"; | 140 const hashFileName = "$hashName.tex"; |
| 83 final hashPath = path.join(tmpDirPath, hashFileName); | 141 final hashPath = path.join(tmpDirPath, hashFileName); |
| 84 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); | 142 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); |
| 85 | 143 |
| 144 final listName = "$specName-list"; |
| 145 final listFileName = "$listName.txt"; |
| 146 final listPath = path.join(tmpDirPath, listFileName); |
| 147 |
| 86 // actions to take | 148 // actions to take |
| 87 runLatex(fileName,workingDirectory) => | 149 runLatex(fileName,workingDirectory) => |
| 88 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); | 150 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
| 89 | 151 |
| 90 runAddHash() => | 152 runAddHash() => |
| 91 Process.runSync("dart", | 153 Process.runSync("dart", |
| 92 [path.join(dartRootPath, "tools", "addlatexhash.dart"), | 154 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 93 tmpSpecPath, | 155 tmpSpecPath, |
| 94 hashPath]); | 156 hashPath, |
| 157 listPath]); |
| 95 | 158 |
| 96 runDvi2tty(dviFile) => | 159 runDvi2tty(dviFile) => |
| 97 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); | 160 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); |
| 98 | 161 |
| 99 chkDvi2tty(file, subject) => | 162 chkDvi2tty(file, subject) => |
| 100 checkAction(runDvi2tty(file), "dvitty on $subject failed"); | 163 checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
| 101 | 164 |
| 102 // perform test | 165 // perform test |
| 103 new File(styPath).copySync(tmpStyPath); | 166 var renewLMHashCmd = r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}"; |
| 167 new File(styPath) |
| 168 .copySync(tmpStyPath) |
| 169 .writeAsStringSync(renewLMHashCmd, mode: FileMode.APPEND); |
| 104 new File(specPath).copySync(tmpSpecPath); | 170 new File(specPath).copySync(tmpSpecPath); |
| 171 |
| 172 checkAction(runAddHash(),"addlatexhash.dart failed"); |
| 105 for (var i = 0; i < 5; i++) { | 173 for (var i = 0; i < 5; i++) { |
| 106 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); | 174 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
| 107 } | 175 } |
| 108 checkAction(runAddHash(),"addlatexhash.dart failed"); | |
| 109 for (var i = 0; i < 5; i++) { | 176 for (var i = 0; i < 5; i++) { |
| 110 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); | 177 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
| 111 } | 178 } |
| 112 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { | 179 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { |
| 113 throw "dvi2tty spec != dvitty output"; | 180 throw "dvi2tty spec != dvitty output"; |
| 114 } | 181 } |
| 115 } | 182 } |
| 116 | 183 |
| 117 main([args]) { | 184 main([args]) { |
| 118 testCutMatch(); | 185 testCutMatch(); |
| 119 testSisp(); | 186 testSisp(); |
| 187 testSameHash(); |
| 120 // latex and dvi2tty are not installed in the standard test environment | 188 // latex and dvi2tty are not installed in the standard test environment |
| 121 if (args.length > 0 && args[0] == "local") testNoChange(); | 189 if (args.length > 0 && args[0] == "local") testSameDVI(); |
| 122 } | 190 } |
| OLD | NEW |