Index: tests/standalone/from_environment_test.dart |
diff --git a/tests/standalone/from_environment_test.dart b/tests/standalone/from_environment_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6d3fc1b21a058b38590bc2337271785a61ac0f5b |
--- /dev/null |
+++ b/tests/standalone/from_environment_test.dart |
@@ -0,0 +1,93 @@ |
+// Copyright (c) 2013, 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. |
+ |
+import 'dart:convert'; |
+import 'dart:io'; |
+ |
+import "package:expect/expect.dart"; |
+import 'package:path/path.dart'; |
+ |
+Future test(List defines, String script, Map expected, {bool fail: false}) { |
+ String executable = new File(Platform.executable).fullPathSync(); |
+ var script_path = join(dirname(Platform.script), script); |
+ var args = []; |
+ args.addAll(defines); |
+ args.add(script_path); |
+ print(args); |
+ Map fromEnviromnemt; |
+ return Process.run(executable, args) |
+ .then((result) { |
+ print(result.stderr); |
+ if (!fail) { |
+ Expect.equals(0, result.exitCode); |
+ print(result.stdout); |
+ fromEnviromnemt = JSON.decode(result.stdout); |
+ expected.forEach((key, value) { |
+ Expect.equals(value, fromEnviromnemt[key]); |
+ }); |
+ } else { |
+ print(result.exitCode); |
+ print(result.stdout); |
+ Expect.isFalse(result.exitCode == 0); |
+ } |
+ }); |
+} |
+ |
+main() { |
+ //String tests. |
+ test(['-Da=a', '-Db=bb', '-Dc=ccc'], |
+ 'from_environment_string_script.dart', |
+ {'a' : 'a', 'b' : 'bb', 'c': 'ccc'}) |
+ .then((_) { |
+ test(['-Da=a'], |
+ 'from_environment_string_script.dart', |
+ {'a' : 'a', 'b' : '', 'c': 'default'}); |
+ }) |
+ .then((_) { |
+ test(['-Da=1', '-Db=12', '-Dc=123'], |
+ 'from_environment_int_script.dart', |
+ {'a' : 1, 'b' : 12, 'c': 123}); |
+ }) |
+ // Integer tests. |
+ .then((_) { |
+ test(['-Da=1', '-Db=12', '-Dc=123'], |
+ 'from_environment_int_script.dart', |
+ {'a' : 1, 'b' : 12, 'c': 123}); |
+ }) |
+ // Boolean tests. |
+ .then((_) { |
+ test(['-Da=true', '-Db=false', '-Dc=yes'], |
+ 'from_environment_bool_script.dart', |
+ {'a' : true, 'b' : false, 'c': true}); |
+ }) |
+ .then((_) { |
+ test(['-Da=0', '-Db=false', '-Dc'], |
+ 'from_environment_bool_script.dart', |
+ {'a' : true, 'b' : false, 'c': true}); |
+ }) |
+ .then((_) { |
+ test(['-Da=a'], |
+ 'from_environment_bool_script.dart', |
+ {'a' : true, 'b' : false, 'c': true}); |
+ }) |
+ // Failing tests |
+ .then((_) { |
+ test(['-Da'], |
+ 'from_environment_string_script.dart', |
+ null, |
+ fail: true); |
+ }) |
+ .then((_) { |
+ test(['-Da'], |
+ 'from_environment_int_script.dart', |
+ null, |
+ fail: true); |
+ }) |
+ .then((_) { |
+ test(['-Db=12', '-Dc=13'], |
+ 'from_environment_bool_script.dart', |
+ null, |
+ fail: true); |
+ }); |
+} |