Skip to content

Commit cd90715

Browse files
committed
Issue #1109: Libraries_and_Scripts test updated, new tests added.
1 parent 83328f0 commit cd90715

10 files changed

+157
-14
lines changed

Language/Libraries_and_Scripts/Scripts/main_declaration_t05.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// @assertion Let L be a library that exports a declaration D named main. It is
66
/// a compile-time error unless D is a function declaration.
77
///
8-
/// @description Checks that it is a compile-time error if library exports
8+
/// @description Checks that it is not a compile-time error if library exports
99
/// declaration named main and this declaration is not a function. Test that
1010
/// library prefix named 'main' is not an error
1111
/// @author [email protected]

Language/Libraries_and_Scripts/Scripts/main_declaration_t06.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// @assertion Let L be a library that exports a declaration D named main. It is
66
/// a compile-time error unless D is a function declaration.
77
///
8-
/// @description Checks that it is a compile-time error if library exports
8+
/// @description Checks that it is a not compile-time error if library exports
99
/// declaration named main and this declaration is not a function. Test that
1010
/// library name 'main' is not an error
1111
/// @author [email protected]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2021, 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 A script is a library whose exported namespace (19.2) includes a
6+
/// top-level function declaration named main that has either zero, one or two
7+
/// required arguments.
8+
///
9+
/// @description Checks main function can have zero required arguments
10+
/// @author [email protected]
11+
12+
main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2021, 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 Let L be a library that exports a declaration D named main.
6+
/// ...
7+
/// It is a compile-time error if D declares more than two required positional
8+
/// parameters, or if there are any required named parameters.
9+
///
10+
/// @description Checks that main function can have 'var args' argument.
11+
/// @author [email protected]
12+
13+
void main(var args) {
14+
}

Language/Libraries_and_Scripts/Scripts/top_level_main_t01.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,29 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion It is a run time error if S does not declare or export either:
6-
/// • A top-level function named main, or
7-
/// • A top-level getter named main that returns a function.
8-
/// @description Checks that it is a run time error if script does not declare a
9-
/// top level function main()
10-
/// @runtime-error
11-
/// @author vasya
5+
/// @assertion A Dart program will typically be executed by executing a script.
6+
/// @description Checks that dart returns correct exit code if main function
7+
/// presents in the executed dart script.
8+
/// @author iarkh
129
/// @issue 42487
1310
11+
import "../../../Utils/expect.dart";
12+
import "dart:io";
1413

15-
library Script_without_main;
14+
run_main() async {
15+
String executable = Platform.resolvedExecutable;
16+
String eScript = Platform.script.toString().replaceAll(".dart", "_lib.dart");
17+
int called = 0;
1618

17-
class C {}
19+
await Process.run(
20+
executable, [...Platform.executableArguments, eScript])
21+
.then((ProcessResult results) {
22+
Expect.equals(0, results.exitCode);
23+
called++;
24+
});
25+
Expect.equals(1, called);
26+
}
1827

19-
void f() {}
20-
21-
final constX = 1;
28+
main(List<String> args) {
29+
run_main();
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2011, 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+
library Script_with_main;
6+
7+
class C {}
8+
9+
void f() {}
10+
11+
final constX = 1;
12+
13+
main() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2021, 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 A Dart program will typically be executed by executing a script.
6+
/// @description Checks that dart returns correct (non-zero) exit code if [main]
7+
/// function is absent in the executed dart script.
8+
/// @author iarkh
9+
/// @issue 42487
10+
11+
import "../../../Utils/expect.dart";
12+
import "dart:io";
13+
14+
run_main() async {
15+
String executable = Platform.resolvedExecutable;
16+
String eScript = Platform.script.toString().replaceAll(".dart", "_lib.dart");
17+
int called = 0;
18+
await Process.run(executable, [eScript]).then((ProcessResult results) {
19+
Expect.notEquals(0, results);
20+
called++;
21+
});
22+
Expect.equals(1, called);
23+
}
24+
25+
main(List<String> args) {
26+
run_main();
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2021, 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+
library Script_without_main;
6+
7+
class C {}
8+
9+
void f() {}
10+
11+
final constX = 1;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2021, 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 A library consists of (a possibly empty) set of imports, a set
6+
/// of exports, and a set of top level declarations. A top level declaration
7+
/// is either a class, a type alias declaration, a function or a variable
8+
/// declaration. The members of a library L are those top level declarations
9+
/// given within L.
10+
/// topLevelDefinition:
11+
/// classDefinition |
12+
/// enumType |
13+
/// typeAlias |
14+
/// external? functionSignature ';' |
15+
/// external? getterSignature ';' |
16+
/// external? setterSignature ';' |
17+
/// functionSignature functionBody |
18+
/// returnType? get identifier functionBody |
19+
/// returnType? set identifier formalParameterList functionBody |
20+
/// (final | const) type? staticFinalDeclarationList ';' |
21+
/// variableDeclaration ';'
22+
/// ;
23+
/// @description Checks that a library containing correct top level non-function
24+
/// type alias definitions is parsed without errors.
25+
/// @author iarkh
26+
27+
28+
import "top_level_syntax_t20_lib.dart";
29+
30+
main() {
31+
AAlias a = AAlias();
32+
BAlias b = = BAlias();
33+
34+
CAlias1 c1 = CAlias1();
35+
CAlias1<String> c2 = CAlias1<String>();
36+
37+
CAlias2 c3 = CAlias2();
38+
CAlias2<num> c4 = CAlias2();
39+
CAlias2<int> c5 = C<int>();
40+
C<int> c6 = CAlias2<int>();
41+
CAlias2<double> c7 = CAlias2<double>();
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2021, 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+
library Libraries_and_Scripts_A01_t21_lib;
6+
7+
class A {}
8+
class B extends A {}
9+
class C<T> {}
10+
11+
typedef AAlias = A;
12+
typedef BAlias = B;
13+
typedef CAlias1<T> = C<T>;
14+
typedef CAlias2<T extends num> = C<T>;
15+

0 commit comments

Comments
 (0)