Chromium Code Reviews| Index: tests/standalone/io/addlatexhash_test.dart |
| diff --git a/tests/standalone/io/addlatexhash_test.dart b/tests/standalone/io/addlatexhash_test.dart |
| old mode 100644 |
| new mode 100755 |
| index 98f1ba52be528e5aff4420054da4f03526ccfceb..e26711055d2848df4ca0f29951e9e2296687347a |
| --- a/tests/standalone/io/addlatexhash_test.dart |
| +++ b/tests/standalone/io/addlatexhash_test.dart |
| @@ -1,3 +1,4 @@ |
| +#!/usr/bin/env dart |
| // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| @@ -54,11 +55,64 @@ testSisp() { |
| oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false); |
| } |
| +// Check that the hash values of paragraphs in the specially prepared |
| +// LaTeX source 'addlatexhash_test_src.tex' are identical in groups |
| +// of eight (so we get 8 identical hash values, then another hash |
| +// value 8 times, etc.) |
| +testSameHash() { |
| + // 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.
|
| + final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
| + final tmpDirPath = tmpDir.path; |
| + |
| + // file names/paths for file containing groups of 8 variants of a paragraph |
| + const par8timesName = "addlatexhash_test_src"; |
| + const par8timesFileName = "$par8timesName.tex"; |
| + final par8timesDirPath = path.join(dartRootDir, "tests", "standalone", "io"); |
| + final par8timesPath = path.join(par8timesDirPath, par8timesFileName); |
| + final tmpPar8timesPath = path.join(tmpDirPath, par8timesFileName); |
| + |
| + // file names paths for output |
| + final hashName = par8timesName + "-hash"; |
| + final hashFileName = "$hashName.tex"; |
| + final hashPath = path.join(tmpDirPath, hashFileName); |
| + final listName = par8timesName + "-list"; |
| + final listFileName = "$listName.txt"; |
| + final listPath = path.join(tmpDirPath, listFileName); |
| + |
| + // actions to take |
| + runAddHash() => |
| + Process.runSync("dart", |
| + [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| + tmpPar8timesPath, |
| + hashPath, |
| + listPath]); |
| + |
| + // perform test |
| + new File(par8timesPath).copySync(tmpPar8timesPath); |
| + checkAction(runAddHash(), "addlatexhash.dart failed"); |
| + var listFile = new File(listPath); |
| + var listLines = listFile.readAsLinesSync(); |
| + var latestLine = null; |
| + var sameCount = 0; |
| + for (var line in listLines) { |
| + if (!line.startsWith(" ")) continue; // section marker |
| + if (line.startsWith(" %")) continue; // transformed text "comment" |
| + if (line != latestLine) { |
| + // new hash, check for number of equal hashes, then reset |
| + if (sameCount % 8 == 0) { |
| + // saw zero or more blocks of 8 identical hash values: OK |
| + latestLine = line; |
| + sameCount = 1; |
| + } 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.
|
| + } else sameCount++; |
|
ricow1
2014/11/11 07:04:09
use block for else
eernst
2014/11/11 08:00:40
Done.
|
| + } |
| +} |
| + |
| // Check that the LaTeX source transformation done by addlatexhash.dart |
| // does not affect the generated output, as seen via dvi2tty and diff. |
| // NB: Not part of normal testing (only local): latex and dvi2tty are |
| // not installed in the standard test environment. |
| -testNoChange() { |
| +testSameDVI() { |
| // set up /tmp directory to hold output |
| final tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test"); |
| final tmpDirPath = tmpDir.path; |
| @@ -83,6 +137,10 @@ testNoChange() { |
| final hashPath = path.join(tmpDirPath, hashFileName); |
| final hashDviPath = path.join(tmpDirPath, "$hashName.dvi"); |
| + final listName = specName + "-list"; |
|
ricow1
2014/11/11 07:04:09
use string interpolation
eernst
2014/11/11 08:00:40
Done.
|
| + final listFileName = "$listName.txt"; |
| + final listPath = path.join(tmpDirPath, listFileName); |
| + |
| // actions to take |
| runLatex(fileName,workingDirectory) => |
| Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
| @@ -91,7 +149,8 @@ testNoChange() { |
| Process.runSync("dart", |
| [path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| tmpSpecPath, |
| - hashPath]); |
| + hashPath, |
| + listPath]); |
| runDvi2tty(dviFile) => |
| Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDir.path); |
| @@ -100,23 +159,28 @@ testNoChange() { |
| checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
| // perform test |
| - new File(styPath).copySync(tmpStyPath); |
| - new File(specPath).copySync(tmpSpecPath); |
| - for (var i = 0; i < 5; i++) { |
| - checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
| - } |
| - checkAction(runAddHash(),"addlatexhash.dart failed"); |
| - for (var i = 0; i < 5; i++) { |
| - checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
| - } |
| - if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { |
| - throw "dvi2tty spec != dvitty output"; |
| - } |
| + var tmpStyFile = new File(styPath).copySync(tmpStyPath); |
| + var tmpStySink = tmpStyFile.openWrite(mode: FileMode.APPEND); |
| + tmpStySink.writeln(r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}"); |
| + 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
|
| + new File(specPath).copySync(tmpSpecPath); |
| + checkAction(runAddHash(),"addlatexhash.dart failed"); |
| + for (var i = 0; i < 5; i++) { |
| + checkAction(runLatex(specName, tmpDirPath), "LaTeX on spec failed"); |
| + } |
| + for (var i = 0; i < 5; i++) { |
| + checkAction(runLatex(hashFileName, tmpDirPath), "LaTeX on output failed"); |
| + } |
| + if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(hashDviPath, "output")) { |
| + throw "dvi2tty spec != dvitty output"; |
| + } |
| + }); |
| } |
| main([args]) { |
| testCutMatch(); |
| testSisp(); |
| + testSameHash(); |
| // latex and dvi2tty are not installed in the standard test environment |
| - if (args.length > 0 && args[0] == "local") testNoChange(); |
| + if (args.length > 0 && args[0] == "local") testSameDVI(); |
| } |