Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: tests/standalone/io/addlatexhash_test.dart

Issue 646003002: Introduced hash valued location markers in the spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adjusted after review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // testing ../../../tools/addlatexhash.dart
6
7 import 'dart:io';
8 import 'package:path/path.dart' as path;
9 import '../../../tools/addlatexhash.dart';
10
11 final scriptDir = path.dirname(path.fromUri(Platform.script));
12 final dartRootDir = path.dirname(path.dirname(path.dirname(scriptDir)));
13 final dartRootPath = dartRootDir.toString();
14
15 // Check that the given ProcessResult indicates success; if so
16 // return the standard output, otherwise report the failure
17 checkAction(result, errorMessage) {
18 var output = result.stdout;
ricow1 2014/10/15 08:29:05 there is not really any good reason to do this ass
eernst 2014/10/15 11:03:04 OK, I did that because I envision (1) result.stdou
19 if (result.exitCode != 0) {
20 print(output);
21 print(result.stderr);
22 throw errorMessage;
23 }
24 return output;
25 }
26
27 oneTestCutMatch(line, re, expected) {
28 var result = cutMatch(line, new RegExp(re).firstMatch(line));
29 if (result != expected) {
30 throw "cutMatch '$re' from '$line' yields '$result' != '$expected'";
31 }
32 }
33
34 void testCutMatch() {
35 oneTestCutMatch("test", "", "test");
36 oneTestCutMatch("test", "e", "tst");
37 oneTestCutMatch("test", "te", "st");
38 oneTestCutMatch("test", "st", "te");
39 oneTestCutMatch("test", "test", "");
40 }
41
42 oneTestSisp(sispFun, nameSuffix, line, expected) {
43 var result = sispFun(line);
44 if (result != expected) {
45 throw "sispIsDart$nameSuffix '$line' yields $result";
46 }
47 }
48
49 testSisp() {
50 oneTestSisp(sispIsDartBegin, "Begin", "\\begin{dartCode}\n", true);
51 oneTestSisp(sispIsDartBegin, "Begin", " \\begin{dartCode}\n", true);
52 oneTestSisp(sispIsDartBegin, "Begin", "whatever else ..", false);
53 oneTestSisp(sispIsDartEnd, "End", "\\end{dartCode}", true);
54 oneTestSisp(sispIsDartEnd, "End", " \\end{dartCode}\t \n", true);
55 oneTestSisp(sispIsDartEnd, "End", "whatever else ..", false);
56 }
57
58 // Check that the LaTeX source transformation done by addlatexhash.dart
59 // does not affect the generated output, as seen via dvi2tty and diff.
60 // NB: Not part of normal testing (only local): latex and dvi2tty are
61 // not installed in the standard test environment.
62 testNoChange() {
63 var tmpDir = Directory.systemTemp.createTempSync("addlatexhash_test");
64 final tmpDirPath = tmpDir.path;
65 final specDirPath = path.join(dartRootDir, "docs", "language");
66 const specName = "dartLangSpec";
67 final specFileName = "${specName}.tex";
68 final specPath = path.join(specDirPath, specFileName);
69 const styFileName = "dart.sty";
70 final styPath = path.join(specDirPath, styFileName);
71 const tmpName = "dartLangSpec-hash";
72 final tmpFileName = "${tmpName}.tex";
73 final tmpFilePath = path.join(tmpDirPath, tmpFileName);
74 final specDviFileName = "${specName}.dvi";
75 final specDviPath = path.join(specDirPath, specDviFileName);
76 final tmpDviPath = path.join(tmpDirPath, "${tmpName}.dvi");
77
78 runLatex(fileName,workingDirectory) => Process.runSync(
79 "latex",
80 [fileName],
81 workingDirectory: workingDirectory);
82 runAddHash() => Process.runSync(
83 "dart",
84 [dartRootPath + "/tools/addlatexhash.dart",
85 dartRootPath + "/docs/language/dartLangSpec.tex",
86 tmpDir.path + "/dartLangSpec-hash.tex"]);
87 runDvi2tty(dviFile) => Process.runSync(
88 "dvi2tty",
89 [dviFile],
90 workingDirectory: tmpDir.path);
91 chkDvi2tty(file, subject) =>
92 checkAction(runDvi2tty(file), "dvitty on $subject failed");
93
94 for (var i = 0; i < 5; i++) {
95 checkAction(runLatex(specPath, specDirPath), "LaTeX on spec failed");
96 }
97 checkAction(runAddHash(),"addlatexhash.dart failed");
98 new File(styPath).copySync("$tmpDirPath/$styFileName");
99 for (var i = 0; i < 5; i++) {
100 checkAction(runLatex(tmpFileName, tmpDirPath), "LaTeX on output failed");
101 }
102 if (chkDvi2tty(specDviPath, "spec") != chkDvi2tty(tmpDviPath, "output")) {
103 throw "dvi2tty spec != dvitty output";
104 }
105 }
106
107 main([args]) {
108 testCutMatch();
109 testSisp();
110 // latex and dvi2tty are not installed in the standard test environment
111 if (args.length > 0 && args[0] == "local") testNoChange();
112 }
OLDNEW
« no previous file with comments | « docs/language/dartLangSpec.tex ('k') | tools/addlatexhash.dart » ('j') | tools/addlatexhash.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698