[tests] Update two conditional import tests

These tests were just failing on the VM for a very long time.

Rewrite them into a simpler version that just tests conditional
importing rather than trying to do clever things with HttpRequest.

R=eernst@google.com

Change-Id: Iebb7f6210ae4f2215c9445695189533116ffb5b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338160
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
Vyacheslav Egorov 2023-11-28 14:27:39 +00:00 committed by Commit Queue
parent a805417983
commit 775b7bdd73
6 changed files with 55 additions and 62 deletions

View file

@ -0,0 +1,25 @@
// Copyright (c) 2016, 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 "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
import "default.dart"
if (dart.library.io) "io.dart"
if (dart.library.html) "html.dart" deferred as d show value;
void main() async {
asyncStart();
final io = const String.fromEnvironment("dart.library.io") == "true";
final html = const String.fromEnvironment("dart.library.html") == "true";
await d.loadLibrary().timeout(const Duration(seconds: 5));
if (io) {
Expect.equals("io", d.value);
} else if (html) {
Expect.equals("html", d.value);
} else {
Expect.equals("default", d.value);
}
asyncEnd();
}

View file

@ -5,32 +5,21 @@
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
// All three libraries have an HttpRequest class.
import "conditional_import_test.dart"
if (dart.library.io) "dart:io"
if (dart.library.html) "dart:html" deferred as d show HttpRequest;
import "default.dart"
if (dart.library.io) "io.dart"
if (dart.library.html) "html.dart" deferred as d show value;
class HttpRequest {}
void main() {
void main() async {
asyncStart();
var io = const bool.fromEnvironment("dart.library.io");
var html = const bool.fromEnvironment("dart.library.html");
() async {
// Shouldn't fail. Shouldn't time out.
await d.loadLibrary().timeout(const Duration(seconds: 5));
if (io) {
print("io");
Expect.throws(() => new d.HttpRequest()); // Class is abstract in dart:io
} else if (html) {
print("html");
dynamic r = new d.HttpRequest(); // Shouldn't throw
var o = r.open; // Shouldn't fail, the open method is there.
} else {
print("none");
dynamic r = new d.HttpRequest();
Expect.isTrue(r is HttpRequest);
}
asyncEnd();
}();
final io = const bool.fromEnvironment("dart.library.io");
final html = const bool.fromEnvironment("dart.library.html");
await d.loadLibrary().timeout(const Duration(seconds: 5));
if (io) {
Expect.equals("io", d.value);
} else if (html) {
Expect.equals("html", d.value);
} else {
Expect.equals("default", d.value);
}
asyncEnd();
}

View file

@ -1,36 +0,0 @@
// Copyright (c) 2016, 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 "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
// All three libraries have an HttpRequest class.
import "conditional_string_test.dart"
if (dart.library.io == "true") "dart:io"
if (dart.library.html == "true") "dart:html" deferred as d show HttpRequest;
class HttpRequest {}
void main() {
asyncStart();
var io = const String.fromEnvironment("dart.library.io");
var html = const String.fromEnvironment("dart.library.html");
() async {
// Shouldn't fail. Shouldn't time out.
await d.loadLibrary().timeout(const Duration(seconds: 5));
if (io == "true") {
print("io");
Expect.throws(() => new d.HttpRequest()); // Class is abstract in dart:io
} else if (html == "true") {
print("html");
dynamic r = new d.HttpRequest(); // Shouldn't throw
var o = r.open; // Shouldn't fail, the open method is there.
} else {
print("none");
dynamic r = new d.HttpRequest();
Expect.isTrue(r is HttpRequest);
}
asyncEnd();
}();
}

View file

@ -0,0 +1,5 @@
// Copyright (c) 2023, 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.
final value = "default";

View file

@ -0,0 +1,5 @@
// Copyright (c) 2023, 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.
final value = "html";

View file

@ -0,0 +1,5 @@
// Copyright (c) 2023, 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.
final value = "io";