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 // dart executable |
| 83 final dartExecutable = Platform.executable; |
| 84 if (dartExecutable == "") throw "dart executable not available"; |
| 85 |
| 86 // actions to take |
| 87 runAddHash() => |
| 88 Process.runSync(dartExecutable, |
| 89 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 90 tmpPar8timesPath, |
| 91 hashPath, |
| 92 listPath]); |
| 93 |
| 94 // perform test |
| 95 new File(par8timesPath).copySync(tmpPar8timesPath); |
| 96 checkAction(runAddHash(), "addlatexhash.dart failed"); |
| 97 var listFile = new File(listPath); |
| 98 var listLines = listFile.readAsLinesSync(); |
| 99 var latestLine = null; |
| 100 var sameCount = 0; |
| 101 for (var line in listLines) { |
| 102 if (!line.startsWith(" ")) continue; // section marker |
| 103 if (line.startsWith(" %")) continue; // transformed text "comment" |
| 104 if (line != latestLine) { |
| 105 // new hash, check for number of equal hashes, then reset |
| 106 if (sameCount % 8 == 0) { |
| 107 // saw zero or more blocks of 8 identical hash values: OK |
| 108 latestLine = line; |
| 109 sameCount = 1; |
| 110 } else { |
| 111 throw "normalization failed to produce same result"; |
| 112 } |
| 113 } else { |
| 114 sameCount++; |
| 115 } |
| 116 } |
| 117 } |
| 118 |
57 // Check that the LaTeX source transformation done by addlatexhash.dart | 119 // Check that the LaTeX source transformation done by addlatexhash.dart |
58 // does not affect the generated output, as seen via dvi2tty and diff. | 120 // 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 | 121 // NB: Not part of normal testing (only local): latex and dvi2tty are |
60 // not installed in the standard test environment. | 122 // not installed in the standard test environment. |
61 testNoChange() { | 123 testSameDVI() { |
62 // set up /tmp directory to hold output | 124 // set up /tmp directory to hold output |
63 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); | 125 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
64 final tmpDirPath = tmpDir.path; | 126 final tmpDirPath = tmpDir.path; |
65 | 127 |
66 // file names/paths for original spec | 128 // file names/paths for original spec |
67 const specName = "dartLangSpec"; | 129 const specName = "dartLangSpec"; |
68 const specFileName = "$specName.tex"; | 130 const specFileName = "$specName.tex"; |
69 final specDirPath = path.join(dartRootDir, "docs", "language"); | 131 final specDirPath = path.join(dartRootDir, "docs", "language"); |
70 final specPath = path.join(specDirPath, specFileName); | 132 final specPath = path.join(specDirPath, specFileName); |
71 final tmpSpecPath = path.join(tmpDirPath, specFileName); | 133 final tmpSpecPath = path.join(tmpDirPath, specFileName); |
72 const specDviFileName = "$specName.dvi"; | 134 const specDviFileName = "$specName.dvi"; |
73 final specDviPath = path.join(tmpDirPath, specDviFileName); | 135 final specDviPath = path.join(tmpDirPath, specDviFileName); |
74 | 136 |
75 // file names/paths for associated sty | 137 // file names/paths for associated sty |
76 const styFileName = "dart.sty"; | 138 const styFileName = "dart.sty"; |
77 final styPath = path.join(specDirPath, styFileName); | 139 final styPath = path.join(specDirPath, styFileName); |
78 final tmpStyPath = path.join(tmpDirPath, styFileName); | 140 final tmpStyPath = path.join(tmpDirPath, styFileName); |
79 | 141 |
80 // file names paths for output | 142 // file names paths for output |
81 const hashName = "dartLangSpec-hash"; | 143 const hashName = "dartLangSpec-hash"; |
82 const hashFileName = "$hashName.tex"; | 144 const hashFileName = "$hashName.tex"; |
83 final hashPath = path.join(tmpDirPath, hashFileName); | 145 final hashPath = path.join(tmpDirPath, hashFileName); |
84 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); | 146 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); |
85 | 147 |
86 // actions to take | 148 final listName = "$specName-list"; |
| 149 final listFileName = "$listName.txt"; |
| 150 final listPath = path.join(tmpDirPath, listFileName); |
| 151 |
| 152 // dart executable |
| 153 final dartExecutable = Platform.executable; |
| 154 if (dartExecutable == "") throw "dart executable not available"; |
| 155 |
| 156 // actions to take; rely on having latex and dvi2tty in PATH |
87 runLatex(fileName,workingDirectory) => | 157 runLatex(fileName,workingDirectory) => |
88 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); | 158 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
89 | 159 |
90 runAddHash() => | 160 runAddHash() => |
91 Process.runSync("dart", | 161 Process.runSync(dartExecutable, |
92 [path.join(dartRootPath, "tools", "addlatexhash.dart"), | 162 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
93 tmpSpecPath, | 163 tmpSpecPath, |
94 hashPath]); | 164 hashPath, |
| 165 listPath]); |
95 | 166 |
96 runDvi2tty(dviFile) => | 167 runDvi2tty(dviFile) => |
97 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); | 168 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); |
98 | 169 |
99 chkDvi2tty(file, subject) => | 170 chkDvi2tty(file, subject) => |
100 checkAction(runDvi2tty(file), "dvitty on $subject failed"); | 171 checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
101 | 172 |
102 // perform test | 173 // perform test |
103 new File(styPath).copySync(tmpStyPath); | 174 var renewLMHashCmd = r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}"; |
| 175 new File(styPath) |
| 176 .copySync(tmpStyPath) |
| 177 .writeAsStringSync(renewLMHashCmd, mode: FileMode.APPEND); |
104 new File(specPath).copySync(tmpSpecPath); | 178 new File(specPath).copySync(tmpSpecPath); |
| 179 |
| 180 checkAction(runAddHash(),"addlatexhash.dart failed"); |
105 for (var i = 0; i < 5; i++) { | 181 for (var i = 0; i < 5; i++) { |
106 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); | 182 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
107 } | 183 } |
108 checkAction(runAddHash(),"addlatexhash.dart failed"); | |
109 for (var i = 0; i < 5; i++) { | 184 for (var i = 0; i < 5; i++) { |
110 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); | 185 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
111 } | 186 } |
112 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { | 187 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { |
113 throw "dvi2tty spec != dvitty output"; | 188 throw "dvi2tty spec != dvitty output"; |
114 } | 189 } |
115 } | 190 } |
116 | 191 |
117 main([args]) { | 192 main([args]) { |
118 testCutMatch(); | 193 testCutMatch(); |
119 testSisp(); | 194 testSisp(); |
| 195 testSameHash(); |
120 // latex and dvi2tty are not installed in the standard test environment | 196 // latex and dvi2tty are not installed in the standard test environment |
121 if (args.length > 0 && args[0] == "local") testNoChange(); | 197 if (args.length > 0 && args[0] == "local") testSameDVI(); |
122 } | 198 } |
OLD | NEW |