Skip to content

Commit 9a3da0a

Browse files
author
sgrekhov
committed
#993. Added tests for Abi class
1 parent 971ac72 commit 9a3da0a

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022, 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+
/// @assertion Abi.current()
6+
/// The ABI the Dart VM is currently running on.
7+
///
8+
/// @description Checks that this method returns the ABI the Dart VM is
9+
/// currently running on
10+
/// @author [email protected]
11+
12+
import "dart:ffi";
13+
import "../../../Utils/expect.dart";
14+
15+
main() {
16+
final abi = Abi.current();
17+
Expect.isTrue(Abi.values.contains(abi));
18+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022, 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+
/// @assertion Abi.current()
6+
/// The ABI the Dart VM is currently running on.
7+
///
8+
/// @description Checks that this method returns the ABI the Dart VM is
9+
/// currently running on
10+
/// @author [email protected]
11+
12+
import "dart:ffi";
13+
import 'dart:io';
14+
import "../../../Utils/expect.dart";
15+
16+
main() {
17+
final abi = Abi.current();
18+
Expect.isTrue(Abi.values.contains(abi));
19+
if (Platform.isAndroid) {
20+
Expect.isTrue(
21+
abi == Abi.androidArm ||
22+
abi == Abi.androidArm64 ||
23+
abi == Abi.androidIA32 ||
24+
abi == Abi.androidX64,
25+
abi.toString());
26+
}
27+
if (Platform.isFuchsia) {
28+
Expect.isTrue(
29+
abi == Abi.fuchsiaArm64 || abi == Abi.fuchsiaX64, abi.toString());
30+
}
31+
if (Platform.isIOS) {
32+
Expect.isTrue(abi == Abi.iosArm || abi == Abi.iosArm64 || abi == Abi.iosX64,
33+
abi.toString());
34+
}
35+
if (Platform.isLinux) {
36+
Expect.isTrue(
37+
abi == Abi.linuxArm ||
38+
abi == Abi.linuxArm64 ||
39+
abi == Abi.linuxX64 ||
40+
abi == Abi.linuxIA32 ||
41+
abi == Abi.linuxRiscv32 ||
42+
abi == Abi.linuxRiscv64,
43+
abi.toString());
44+
}
45+
if (Platform.isMacOS) {
46+
Expect.isTrue(abi == Abi.macosX64 || abi == Abi.macosArm64, abi.toString());
47+
}
48+
if (Platform.isWindows) {
49+
Expect.isTrue(
50+
abi == Abi.windowsArm64 ||
51+
abi == Abi.windowsIA32 ||
52+
abi == Abi.windowsX64,
53+
abi.toString());
54+
}
55+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2022, 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+
/// @assertion @override
6+
/// String toString()
7+
/// override
8+
/// A string representation of this ABI.
9+
///
10+
// The string is equal to the 'on' part from Platform.version and dart --version
11+
///
12+
/// @description Checks that this method returns a string which is equal to the
13+
/// 'on' part from Platform.version
14+
/// @author [email protected]
15+
16+
import "dart:ffi";
17+
import 'dart:io';
18+
import "../../../Utils/expect.dart";
19+
20+
main() {
21+
final abi = Abi.current();
22+
String expected = Platform.version
23+
.substring(Platform.version.indexOf(" on ") + 4)
24+
.trim()
25+
.replaceAll("\"", "");
26+
Expect.equals(expected, abi.toString());
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2022, 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+
/// @assertion values constant Null safety
6+
/// List<Abi> const values
7+
/// The ABIs that the DartVM can run on.
8+
///
9+
/// Does not contain a macosIA32. We have stopped supporting 32-bit MacOS.
10+
///
11+
/// Includes windowsArm64, even though it is currently not supported. Support
12+
/// has been requested for Flutter.
13+
/// https://github.com/flutter/flutter/issues/53120
14+
///
15+
/// @description Checks that this list contains `windowsArm64` and the current
16+
/// ABI
17+
/// @author [email protected]
18+
19+
import "dart:ffi";
20+
import "../../../Utils/expect.dart";
21+
22+
main() {
23+
Expect.isTrue(Abi.values.contains(Abi.current()));
24+
Expect.isTrue(Abi.values.contains(Abi.windowsArm64));
25+
}

0 commit comments

Comments
 (0)