Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2004. Add deferred libraries tests according to the changed spec #2411

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions Language/Libraries_and_Scripts/Imports/deferred_import_t01.dart

This file was deleted.

79 changes: 0 additions & 79 deletions Language/Libraries_and_Scripts/Imports/deferred_import_t02.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

/// @assertion It is a compile-time error if the prefix used in a deferred
/// import is also used as the prefix of another import clause
///
/// @description Checks that it is a compile-time error if the prefix used in a
/// deferred import is also used as the prefix of another deferred import clause
/// @author sgrekhov22@gmail.com

import 'static_type_lib.dart' deferred as p;
// ^^^^^^^^
// [analyzer] unspecified

import 'syntax_lib.dart' deferred as p;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
p.loadLibrary();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

/// @assertion It is a compile-time error if the prefix used in a deferred
/// import is also used as the prefix of another import clause
///
/// @description Checks that it is a compile-time error if the prefix used in a
/// deferred import is also used as the prefix of another immediate import
/// clause
/// @author sgrekhov22@gmail.com

import 'static_type_lib.dart' deferred as p;
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

import 'syntax_lib.dart' as p;

main() {
p.loadLibrary();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

/// @assertion It is a compile-time error if the prefix used in a deferred
/// import is also used as the prefix of another import clause
///
/// @description Checks that it is not an error if the prefix used in a
/// non-deferred import is also used as the prefix of another immediate import
/// clause
/// @author sgrekhov22@gmail.com

import '../../../Utils/expect.dart';
import 'static_type_lib.dart' as p;
import 'syntax_lib.dart' as p;

main() {
Expect.equals(1, p.someFunc()); // from static_type_lib.dart
Expect.equals("hide", p.hide); // from syntax_lib.dart
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

/// @assertion It is a compile-time error if the prefix used in a deferred
/// import is also used as the prefix of another import clause
///
/// @description Checks that it is not an error if two deferred libraries with
/// two different prefixes are imported
/// @author sgrekhov22@gmail.com

import '../../../Utils/expect.dart';
import 'static_type_lib.dart' deferred as p1;
import 'syntax_lib.dart' deferred as p2;

main() async {
asyncStart();
await p1.loadLibrary();
await p2.loadLibrary();
Expect.equals(1, p1.someFunc()); // from static_type_lib.dart
Expect.equals("hide", p2.hide); // from syntax_lib.dart
asyncEnd();
}
32 changes: 32 additions & 0 deletions Language/Libraries_and_Scripts/Imports/semantics_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.

/// @assertion Let Ii be an import directive that refers to a URI via the string
/// si. The semantics of Ii is specified as follows:
/// Case ⟨Semantics of deferred imports⟩. If Ii is a deferred import with prefix
/// p, a binding of p to a deferred prefix run-time namespace NSdeferred is
/// present in the library namespace of the current library L. Let NSimport,i be
/// the namespace imported from the library specified by Ii.
/// NSdeferred then has the following bindings:
/// • The name loadLibrary is bound to a function with signature
/// Future<void> loadLibrary(). This function returns a future f. When called,
/// the function causes an immediate import I′ to be executed at some future
/// time, where I′ is derived from Ii by eliding the word deferred and adding
/// a hide loadLibrary combinator clause. The execution of the immediate
/// import may fail for implementation specific reasons. For instance, I′
/// imports a different library than the one that the specified URI referred
/// to at compiletime; or an OS level file read error occurs; etc. We say that
/// the invocation of loadLibrary succeeds if f completes with a value, and
/// that the invocation fails if f completes with an error.
///
/// @description Checks that static type of `loadLibrary` is
/// `Future<void> Function()`
/// @author sgrekhov22@gmail.com

import "static_type_lib.dart" deferred as p;
import "../../../Utils/static_type_helper.dart";

main() {
p.loadLibrary.expectStaticType<Exactly<Future<void> Function()>>();
}
49 changes: 49 additions & 0 deletions Language/Libraries_and_Scripts/Imports/semantics_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2011, 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.

/// @assertion Let Ii be an import directive that refers to a URI via the string
/// si. The semantics of Ii is specified as follows:
/// Case ⟨Semantics of deferred imports⟩. If Ii is a deferred import with prefix
/// p, a binding of p to a deferred prefix run-time namespace NSdeferred is
/// present in the library namespace of the current library L. Let NSimport,i be
/// the namespace imported from the library specified by Ii.
/// NSdeferred then has the following bindings:
/// • The name loadLibrary is bound to a function with signature
/// Future<void> loadLibrary(). This function returns a future f. When called,
/// the function causes an immediate import I′ to be executed at some future
/// time, where I′ is derived from Ii by eliding the word deferred and adding
/// a hide loadLibrary combinator clause. The execution of the immediate
/// import may fail for implementation specific reasons. For instance, I′
/// imports a different library than the one that the specified URI referred
/// to at compiletime; or an OS level file read error occurs; etc. We say that
/// the invocation of loadLibrary succeeds if f completes with a value, and
/// that the invocation fails if f completes with an error.
///
/// @description Checks that call of `loadLibrary` causes an immediate import of
/// the deferred library
/// @author ngl@unipro.ru

import "../../../Utils/expect.dart";
import "static_type_lib.dart" deferred as p;

void testLoaded() {
Expect.equals(1, p.someFunc());
Expect.equals(3, p.someVar);
Expect.equals(2, p.someGetter);
p.someSetter = 1;
p.Func;
Expect.isTrue(p.loadLibrary() is Future<void>);
Expect.runtimeIsType<Future<void>>(p.loadLibrary());
}

main() {
asyncStart();
p.loadLibrary().then((v) {
testLoaded();
asyncEnd();
},
onError: (e) {
Expect.fail("Library should be loaded");
});
}
39 changes: 39 additions & 0 deletions Language/Libraries_and_Scripts/Imports/semantics_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2011, 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.

/// @assertion Let Ii be an import directive that refers to a URI via the string
/// si. The semantics of Ii is specified as follows:
/// Case ⟨Semantics of deferred imports⟩. If Ii is a deferred import with prefix
/// p, a binding of p to a deferred prefix run-time namespace NSdeferred is
/// present in the library namespace of the current library L. Let NSimport,i be
/// the namespace imported from the library specified by Ii.
/// NSdeferred then has the following bindings:
/// ...
/// • For every top level function f named id in NSimport,i, a corresponding
/// function named id with the same signature as f. Calling the function
/// results in a dynamic error that occurs before any actual arguments are
/// evaluated. Closurizing the function also results in a dynamic error.
/// • For every top level getter g named id in NSimport,i, a corresponding
/// getter named id with the same signature as g. Calling the getter results
/// in a dynamic error.
/// • For every top level setter s named id= in NSimport,i, a corresponding
/// setter named id= with the same signature as s. Calling the setter results
/// in a dynamic error that occurs before the actual argument is evaluated.
///
/// @description Checks that for every top-level declaration in the imported
/// library a corresponding declaration with the same name created in the
/// current library. Calling the imported name results in a runtime error.
/// @Issue 33118
/// @issue 42491
/// @author ngl@unipro.ru

import "../../../Utils/expect.dart";
import "static_type_lib.dart" deferred as p;

main() {
Expect.throws(() { p.someFunc(); }, (e) => e is NoSuchMethodError);
Expect.throws(() { p.someGetter; }, (e) => e is NoSuchMethodError);
Expect.throws(() { p.someSetter = 2; }, (e) => e is NoSuchMethodError);
Expect.throws(() { p.Func; }, (e) => e is NoSuchMethodError);
}
Loading