| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // 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 |
| 3 // 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 |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 // testing ../../../tools/addlatexhash.dart | 6 // testing ../../../tools/addlatexhash.dart |
| 7 | 7 |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 10 import '../../../tools/addlatexhash.dart'; | 10 import '../../../tools/addlatexhash.dart'; |
| 11 | 11 |
| 12 final scriptDir = path.dirname(path.fromUri(Platform.script)); | 12 final scriptDir = path.dirname(path.fromUri(Platform.script)); |
| 13 final dartRootDir = path.dirname(path.dirname(path.dirname(scriptDir))); | 13 final dartRootDir = path.dirname(path.dirname(path.dirname(scriptDir))); |
| 14 final dartRootPath = dartRootDir.toString(); | 14 final dartRootPath = dartRootDir.toString(); |
| 15 | 15 |
| 16 List<String> packageOptions() { |
| 17 if (Platform.packageRoot != null) { |
| 18 return <String>['--package-root=${Platform.packageRoot}']; |
| 19 } else if (Platform.packageConfig != null) { |
| 20 return <String>['--packages=${Platform.packageConfig}']; |
| 21 } else { |
| 22 return <String>[]; |
| 23 } |
| 24 } |
| 25 |
| 16 // Check that the given ProcessResult indicates success; if so | 26 // Check that the given ProcessResult indicates success; if so |
| 17 // return the standard output, otherwise report the failure | 27 // return the standard output, otherwise report the failure |
| 18 checkAction(result, errorMessage) { | 28 checkAction(result, errorMessage) { |
| 19 if (result.exitCode != 0) { | 29 if (result.exitCode != 0) { |
| 20 print(result.stdout); | 30 print(result.stdout); |
| 21 print(result.stderr); | 31 print(result.stderr); |
| 22 throw errorMessage; | 32 throw errorMessage; |
| 23 } | 33 } |
| 24 return result.stdout; | 34 return result.stdout; |
| 25 } | 35 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 final listName = par8timesName + "-list"; | 84 final listName = par8timesName + "-list"; |
| 75 final listFileName = "$listName.txt"; | 85 final listFileName = "$listName.txt"; |
| 76 final listPath = path.join(tmpDirPath, listFileName); | 86 final listPath = path.join(tmpDirPath, listFileName); |
| 77 | 87 |
| 78 // dart executable | 88 // dart executable |
| 79 final dartExecutable = Platform.executable; | 89 final dartExecutable = Platform.executable; |
| 80 if (dartExecutable == "") throw "dart executable not available"; | 90 if (dartExecutable == "") throw "dart executable not available"; |
| 81 | 91 |
| 82 // actions to take | 92 // actions to take |
| 83 runAddHash() { | 93 runAddHash() { |
| 84 var args = [ | 94 var args = packageOptions(); |
| 85 '--package-root=${Platform.packageRoot}', | 95 args.addAll([ |
| 86 path.join(dartRootPath, "tools", "addlatexhash.dart"), | 96 path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 87 tmpPar8timesPath, | 97 tmpPar8timesPath, |
| 88 hashPath, | 98 hashPath, |
| 89 listPath | 99 listPath |
| 90 ]; | 100 ]); |
| 91 return Process.runSync(dartExecutable, args); | 101 return Process.runSync(dartExecutable, args); |
| 92 } | 102 } |
| 93 | 103 |
| 94 // perform test | 104 // perform test |
| 95 new File(par8timesPath).copySync(tmpPar8timesPath); | 105 new File(par8timesPath).copySync(tmpPar8timesPath); |
| 96 checkAction(runAddHash(), "addlatexhash.dart failed"); | 106 checkAction(runAddHash(), "addlatexhash.dart failed"); |
| 97 var listFile = new File(listPath); | 107 var listFile = new File(listPath); |
| 98 var listLines = listFile.readAsLinesSync(); | 108 var listLines = listFile.readAsLinesSync(); |
| 99 var latestLine = null; | 109 var latestLine = null; |
| 100 var sameCount = 0; | 110 var sameCount = 0; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 157 |
| 148 // dart executable | 158 // dart executable |
| 149 final dartExecutable = Platform.executable; | 159 final dartExecutable = Platform.executable; |
| 150 if (dartExecutable == "") throw "dart executable not available"; | 160 if (dartExecutable == "") throw "dart executable not available"; |
| 151 | 161 |
| 152 // actions to take; rely on having latex and dvi2tty in PATH | 162 // actions to take; rely on having latex and dvi2tty in PATH |
| 153 runLatex(fileName,workingDirectory) => | 163 runLatex(fileName,workingDirectory) => |
| 154 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); | 164 Process.runSync("latex", [fileName], workingDirectory: workingDirectory); |
| 155 | 165 |
| 156 runAddHash() { | 166 runAddHash() { |
| 157 var args = [ | 167 var args = packageOptions(); |
| 158 '--package-root=${Platform.packageRoot}', | 168 args.addAll([ |
| 159 path.join(dartRootPath, "tools", "addlatexhash.dart"), | 169 path.join(dartRootPath, "tools", "addlatexhash.dart"), |
| 160 tmpSpecPath, | 170 tmpSpecPath, |
| 161 hashPath, | 171 hashPath, |
| 162 listPath | 172 listPath |
| 163 ]; | 173 ]); |
| 164 return Process.runSync(dartExecutable, args); | 174 return Process.runSync(dartExecutable, args); |
| 165 } | 175 } |
| 166 | 176 |
| 167 runDvi2tty(dviFile) => | 177 runDvi2tty(dviFile) => |
| 168 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDirPath); | 178 Process.runSync("dvi2tty", [dviFile], workingDirectory: tmpDirPath); |
| 169 | 179 |
| 170 chkDvi2tty(file, subject) => | 180 chkDvi2tty(file, subject) => |
| 171 checkAction(runDvi2tty(file), "dvitty on $subject failed"); | 181 checkAction(runDvi2tty(file), "dvitty on $subject failed"); |
| 172 | 182 |
| 173 // perform test | 183 // perform test |
| (...skipping 29 matching lines...) Expand all Loading... |
| 203 main([args]) { | 213 main([args]) { |
| 204 testCutMatch(); | 214 testCutMatch(); |
| 205 testSisp(); | 215 testSisp(); |
| 206 | 216 |
| 207 runWithTempDir(testSameHash); | 217 runWithTempDir(testSameHash); |
| 208 // latex and dvi2tty are not installed in the standard test environment | 218 // latex and dvi2tty are not installed in the standard test environment |
| 209 if (args.length > 0 && args[0] == "local") { | 219 if (args.length > 0 && args[0] == "local") { |
| 210 runWithTempDir(testSameDVI); | 220 runWithTempDir(testSameDVI); |
| 211 } | 221 } |
| 212 } | 222 } |
| OLD | NEW |