Skip to content

Commit 232e9db

Browse files
author
sgrekhov
committed
Fix for #585. Make fromEnvironment tests to be independed from defaultValue
1 parent 8328167 commit 232e9db

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

LibTest/core/String/String.fromEnvironment_A01_t01.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
*/
1717
import "../../../Utils/expect.dart";
1818

19+
const ENV_VAR = "SOME_ENV_VARIABLE";
20+
1921
main() {
20-
var s1 = new String.fromEnvironment("SOME_ENV_VARIABLE",
21-
defaultValue: "No");
22-
Expect.equals("No", s1);
22+
const def1 = bool.hasEnvironment(ENV_VAR) ? const String.fromEnvironment(ENV_VAR) : "No";
23+
var s1 = const String.fromEnvironment(ENV_VAR, defaultValue: def1);
24+
Expect.equals(def1, s1);
2325

24-
var s2 = new String.fromEnvironment("SOME_ENV_VARIABLE");
25-
Expect.isNull(s2);
26+
const def2 = bool.hasEnvironment(ENV_VAR) ? const String.fromEnvironment(ENV_VAR) : null;
27+
var s2 = const bool.hasEnvironment(ENV_VAR)
28+
? String.fromEnvironment(ENV_VAR)
29+
: def2;
30+
Expect.equals(def2, s2);
2631
}

LibTest/core/bool/bool.fromEnvironment_A01_t01.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
import "../../../Utils/expect.dart";
1717

18+
const ENV_VAR = "SOME_ENV_VARIABLE";
19+
1820
main() {
19-
const someFlag = const bool.fromEnvironment("someFlag");
20-
Expect.isFalse(someFlag);
21+
const def1 = bool.hasEnvironment(ENV_VAR) ? const bool.fromEnvironment(ENV_VAR) : false;
22+
var b = bool.hasEnvironment(ENV_VAR) ? const bool.fromEnvironment(ENV_VAR) : def1;
23+
Expect.equals(def1, b);
2124
}

LibTest/core/int/int.fromEnvironment_A01_t01.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
* @assertion const int.fromEnvironment(String name, {int defaultValue})
88
* Returns the integer value of the given environment declaration name.
99
* The result is the same as would be returned by:
10-
* int.parse(const String.fromEnvironment(name, defaultValue: ""),
11-
* (_) => defaultValue)
10+
* int.tryParse(const String.fromEnvironment(name, defaultValue: ""))
11+
* ?? defaultValue
1212
* @description Checks that this constructor returns null if there is no
1313
* environment variable with appropriate name
1414
1515
*/
1616
import "../../../Utils/expect.dart";
1717

18+
const ENV_VAR = "SOME_ENV_VARIABLE";
19+
1820
main() {
19-
const someFlag = const int.fromEnvironment("someFlag");
20-
Expect.isNull(someFlag);
21+
const def1 = bool.hasEnvironment(ENV_VAR) ? const int.fromEnvironment(ENV_VAR) : null;
22+
const v1 = bool.hasEnvironment(ENV_VAR) ? const int.fromEnvironment(ENV_VAR) : def1;
23+
Expect.equals(def1, v1);
24+
25+
const def2 = bool.hasEnvironment(ENV_VAR) ? const int.fromEnvironment(ENV_VAR) : 42;
26+
const v2 = const int.fromEnvironment(ENV_VAR, defaultValue: def2);
27+
Expect.equals(def2, v2);
2128
}

0 commit comments

Comments
 (0)