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