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 /tmp directory to hold output | |
ricow1
2014/11/11 07:04:09
that comment is not true on windows
eernst
2014/11/11 08:00:40
Done.
| |
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 throw "normalization failed to produce same result"; | |
ricow1
2014/11/11 07:04:09
use block for else
eernst
2014/11/11 08:00:40
Done.
| |
107 } else sameCount++; | |
ricow1
2014/11/11 07:04:09
use block for else
eernst
2014/11/11 08:00:40
Done.
| |
108 } | |
109 } | |
110 | |
57 // Check that the LaTeX source transformation done by addlatexhash.dart | 111 // Check that the LaTeX source transformation done by addlatexhash.dart |
58 // does not affect the generated output, as seen via dvi2tty and diff. | 112 // 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 | 113 // NB: Not part of normal testing (only local): latex and dvi2tty are |
60 // not installed in the standard test environment. | 114 // not installed in the standard test environment. |
61 testNoChange() { | 115 testSameDVI() { |
62 // set up /tmp directory to hold output | 116 // set up /tmp directory to hold output |
63 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); | 117 final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
64 final tmpDirPath = tmpDir.path; | 118 final tmpDirPath = tmpDir.path; |
65 | 119 |
66 // file names/paths for original spec | 120 // file names/paths for original spec |
67 const specName = "dartLangSpec"; | 121 const specName = "dartLangSpec"; |
68 const specFileName = "$specName.tex"; | 122 const specFileName = "$specName.tex"; |
69 final specDirPath = path.join(dartRootDir, "docs", "language"); | 123 final specDirPath = path.join(dartRootDir, "docs", "language"); |
70 final specPath = path.join(specDirPath, specFileName); | 124 final specPath = path.join(specDirPath, specFileName); |
71 final tmpSpecPath = path.join(tmpDirPath, specFileName); | 125 final tmpSpecPath = path.join(tmpDirPath, specFileName); |
72 const specDviFileName = "$specName.dvi"; | 126 const specDviFileName = "$specName.dvi"; |
73 final specDviPath = path.join(tmpDirPath, specDviFileName); | 127 final specDviPath = path.join(tmpDirPath, specDviFileName); |
74 | 128 |
75 // file names/paths for associated sty | 129 // file names/paths for associated sty |
76 const styFileName = "dart.sty"; | 130 const styFileName = "dart.sty"; |
77 final styPath = path.join(specDirPath, styFileName); | 131 final styPath = path.join(specDirPath, styFileName); |
78 final tmpStyPath = path.join(tmpDirPath, styFileName); | 132 final tmpStyPath = path.join(tmpDirPath, styFileName); |
79 | 133 |
80 // file names paths for output | 134 // file names paths for output |
81 const hashName = "dartLangSpec-hash"; | 135 const hashName = "dartLangSpec-hash"; |
82 const hashFileName = "$hashName.tex"; | 136 const hashFileName = "$hashName.tex"; |
83 final hashPath = path.join(tmpDirPath, hashFileName); | 137 final hashPath = path.join(tmpDirPath, hashFileName); |
84 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); | 138 final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); |
85 | 139 |
140 final listName = specName + "-list"; | |
ricow1
2014/11/11 07:04:09
use string interpolation
eernst
2014/11/11 08:00:40
Done.
| |
141 final listFileName = "$listName.txt"; | |
142 final listPath = path.join(tmpDirPath, listFileName); | |
143 | |
86 // actions to take | 144 // actions to take |
87 runLatex(fileName,workingDirectory) => | 145 runLatex(fileName,workingDirectory) => |
88 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); | 146 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
89 | 147 |
90 runAddHash() => | 148 runAddHash() => |
91 Process.runSync("dart", | 149 Process.runSync("dart", |
92 [path.join(dartRootPath, "tools", "addlatexhash.dart"), | 150 [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
93 tmpSpecPath, | 151 tmpSpecPath, |
94 hashPath]); | 152 hashPath, |
153 listPath]); | |
95 | 154 |
96 runDvi2tty(dviFile) => | 155 runDvi2tty(dviFile) => |
97 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); | 156 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); |
98 | 157 |
99 chkDvi2tty(file, subject) => | 158 chkDvi2tty(file, subject) => |
100 checkAction(runDvi2tty(file), "dvitty on $subject failed"); | 159 checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
101 | 160 |
102 // perform test | 161 // perform test |
103 new File(styPath).copySync(tmpStyPath); | 162 var tmpStyFile = new File(styPath).copySync(tmpStyPath); |
104 new File(specPath).copySync(tmpSpecPath); | 163 var tmpStySink = tmpStyFile.openWrite(mode: FileMode.APPEND); |
105 for (var i = 0; i < 5; i++) { | 164 tmpStySink.writeln(r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}"); |
106 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); | 165 tmpStySink.close().then((_) { |
ricow1
2014/11/11 07:04:09
you can easily avoid mixing this async call in her
eernst
2014/11/11 08:00:40
Aha, I can see that writeAsStringSync includes 'cl
| |
107 } | 166 new File(specPath).copySync(tmpSpecPath); |
108 checkAction(runAddHash(),"addlatexhash.dart failed"); | 167 checkAction(runAddHash(),"addlatexhash.dart failed"); |
109 for (var i = 0; i < 5; i++) { | 168 for (var i = 0; i < 5; i++) { |
110 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); | 169 checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
111 } | 170 } |
112 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { | 171 for (var i = 0; i < 5; i++) { |
113 throw "dvi2tty spec != dvitty output"; | 172 checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
114 } | 173 } |
174 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { | |
175 throw "dvi2tty spec != dvitty output"; | |
176 } | |
177 }); | |
115 } | 178 } |
116 | 179 |
117 main([args]) { | 180 main([args]) { |
118 testCutMatch(); | 181 testCutMatch(); |
119 testSisp(); | 182 testSisp(); |
183 testSameHash(); | |
120 // latex and dvi2tty are not installed in the standard test environment | 184 // latex and dvi2tty are not installed in the standard test environment |
121 if (args.length > 0 && args[0] == "local") testNoChange(); | 185 if (args.length > 0 && args[0] == "local") testSameDVI(); |
122 } | 186 } |
OLD | NEW |