[VM Unit Tests] Fix some of the VM unit tests to account for new null safety semantics
- Some tests were using a 'main' with a signature that does not match the new spec,changed these tests to invoke 'testMain' instead of 'main' - deleted test case for a factory method that returns a null (reports as a compilation error now) - Fixed some of the isolate_reload tests to not crash - Turn on non-nullable experiment flag by default for unit tests - Added a unit test for creation of a non nullable list of strings using the Dart C API. Change-Id: I2c345aaabdc29e9222c1d451f2ef43ba5cdb3686 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167821 Commit-Queue: Siva Annamalai <asiva@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
8f5f6971a9
commit
3a6cf0e6d4
@@ -215,7 +215,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_WriteBarrierElimination_Regress43786) {
|
||||
final root = List<dynamic>.filled(128, null);
|
||||
List<dynamic> last = root;
|
||||
for (int i = 0; i < 10 * 1024; ++i) {
|
||||
final nc = List(128);
|
||||
final nc = List<dynamic>.filled(128, null);
|
||||
last[0] = nc;
|
||||
last = nc;
|
||||
}
|
||||
|
||||
@@ -1966,7 +1966,7 @@ TEST_CASE(DartAPI_TypedDataViewListGetAsBytes) {
|
||||
|
||||
const char* kScriptChars =
|
||||
"import 'dart:typed_data';\n"
|
||||
"List main(int size) {\n"
|
||||
"List testMain(int size) {\n"
|
||||
" var a = new Int8List(size);\n"
|
||||
" var view = new Int8List.view(a.buffer, 0, size);\n"
|
||||
" return view;\n"
|
||||
@@ -1977,7 +1977,7 @@ TEST_CASE(DartAPI_TypedDataViewListGetAsBytes) {
|
||||
// Test with a typed data view object.
|
||||
Dart_Handle dart_args[1];
|
||||
dart_args[0] = Dart_NewInteger(kSize);
|
||||
Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args);
|
||||
Dart_Handle view_obj = Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
|
||||
EXPECT_VALID(view_obj);
|
||||
for (intptr_t i = 0; i < kSize; ++i) {
|
||||
EXPECT_VALID(Dart_ListSetAt(view_obj, i, Dart_NewInteger(i & 0xff)));
|
||||
@@ -1998,7 +1998,7 @@ TEST_CASE(DartAPI_TypedDataViewListIsTypedData) {
|
||||
|
||||
const char* kScriptChars =
|
||||
"import 'dart:typed_data';\n"
|
||||
"List main(int size) {\n"
|
||||
"List testMain(int size) {\n"
|
||||
" var a = new Int8List(size);\n"
|
||||
" var view = new Int8List.view(a.buffer, 0, size);\n"
|
||||
" return view;\n"
|
||||
@@ -2009,7 +2009,7 @@ TEST_CASE(DartAPI_TypedDataViewListIsTypedData) {
|
||||
// Create a typed data view object.
|
||||
Dart_Handle dart_args[1];
|
||||
dart_args[0] = Dart_NewInteger(kSize);
|
||||
Dart_Handle view_obj = Dart_Invoke(lib, NewString("main"), 1, dart_args);
|
||||
Dart_Handle view_obj = Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
|
||||
EXPECT_VALID(view_obj);
|
||||
// Test that the API considers it a TypedData object.
|
||||
EXPECT(Dart_IsTypedData(view_obj));
|
||||
@@ -5524,9 +5524,6 @@ TEST_CASE(DartAPI_New) {
|
||||
" factory MyClass.multiply(value) {\n"
|
||||
" return new MyClass.named(value * 100);\n"
|
||||
" }\n"
|
||||
" factory MyClass.nullo() {\n"
|
||||
" return null;\n"
|
||||
" }\n"
|
||||
" var foo;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
@@ -5687,11 +5684,6 @@ TEST_CASE(DartAPI_New) {
|
||||
EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
|
||||
EXPECT_EQ(1100, int_value);
|
||||
|
||||
// Invoke a factory constructor which returns null.
|
||||
result = Dart_New(type, NewString("nullo"), 0, NULL);
|
||||
EXPECT_VALID(result);
|
||||
EXPECT(Dart_IsNull(result));
|
||||
|
||||
// Pass an error class object. Error is passed through.
|
||||
result = Dart_New(Dart_NewApiError("myerror"), NewString("named"), 1, args);
|
||||
EXPECT_ERROR(result, "myerror");
|
||||
@@ -5967,6 +5959,13 @@ TEST_CASE(DartAPI_NewListOfTypeFilled) {
|
||||
|
||||
// Null is always valid as the fill argument if we're creating an empty list.
|
||||
EXPECT_VALID(Dart_NewListOfTypeFilled(zxhandle_type, Dart_Null(), 0));
|
||||
|
||||
// Test creation of a non nullable list of strings.
|
||||
Dart_Handle corelib = Dart_LookupLibrary(NewString("dart:core"));
|
||||
EXPECT_VALID(corelib);
|
||||
Dart_Handle string_type =
|
||||
Dart_GetNonNullableType(corelib, NewString("String"), 0, NULL);
|
||||
EXPECT_VALID(Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), 2));
|
||||
}
|
||||
|
||||
static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) {
|
||||
@@ -8626,7 +8625,7 @@ TEST_CASE(DartAPI_CollectTwoOldSpacePeers) {
|
||||
|
||||
TEST_CASE(DartAPI_ExternalStringIndexOf) {
|
||||
const char* kScriptChars =
|
||||
"main(String pattern) {\n"
|
||||
"testMain(String pattern) {\n"
|
||||
" var str = 'Hello World';\n"
|
||||
" return str.indexOf(pattern);\n"
|
||||
"}\n";
|
||||
@@ -8641,7 +8640,7 @@ TEST_CASE(DartAPI_ExternalStringIndexOf) {
|
||||
|
||||
Dart_Handle dart_args[1];
|
||||
dart_args[0] = ext8;
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("main"), 1, dart_args);
|
||||
Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
|
||||
int64_t value = 0;
|
||||
result = Dart_IntegerToInt64(result, &value);
|
||||
EXPECT_VALID(result);
|
||||
|
||||
@@ -1096,12 +1096,12 @@ TEST_CASE(IsolateReload_LibraryLookup) {
|
||||
|
||||
const char* kScript =
|
||||
"main() {\n"
|
||||
" return importedFunc();\n"
|
||||
" return 'b';\n"
|
||||
"}\n";
|
||||
Dart_Handle result;
|
||||
Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
|
||||
EXPECT_VALID(lib);
|
||||
EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc");
|
||||
EXPECT_STREQ("b", SimpleInvokeStr(lib, "main"));
|
||||
|
||||
// Fail to find 'test:lib1' in the isolate.
|
||||
result = Dart_LookupLibrary(NewString("test:lib1"));
|
||||
@@ -1122,7 +1122,7 @@ TEST_CASE(IsolateReload_LibraryLookup) {
|
||||
result = Dart_LookupLibrary(NewString("test:lib1"));
|
||||
EXPECT(Dart_IsLibrary(result));
|
||||
|
||||
// Reload and remove 'dart:math' from isolate.
|
||||
// Reload and remove 'test:lib1' from isolate.
|
||||
lib = TestCase::ReloadTestScript(kScript);
|
||||
EXPECT_VALID(lib);
|
||||
|
||||
@@ -1362,22 +1362,15 @@ TEST_CASE(IsolateReload_PendingUnqualifiedCall_InstanceToStatic) {
|
||||
"}\n";
|
||||
|
||||
EXPECT_VALID(TestCase::SetReloadTestScript(kReloadScript));
|
||||
|
||||
const char* expected = "static";
|
||||
const char* result = SimpleInvokeStr(lib, "main");
|
||||
EXPECT_NOTNULL(result);
|
||||
|
||||
// Bail out if we've already failed so we don't crash in StringEquals.
|
||||
if (result == NULL) {
|
||||
return;
|
||||
}
|
||||
EXPECT_STREQ(expected, result);
|
||||
|
||||
// Bail out if we've already failed so we don't crash in the tag handler.
|
||||
if (strcmp(expected, result) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
lib = Dart_RootLibrary();
|
||||
EXPECT_NON_NULL(lib);
|
||||
EXPECT_STREQ(expected, SimpleInvokeStr(lib, "main"));
|
||||
@@ -1390,7 +1383,6 @@ TEST_CASE(IsolateReload_PendingConstructorCall_AbstractToConcrete) {
|
||||
"class C {\n"
|
||||
" test() {\n"
|
||||
" reloadTest();\n"
|
||||
" return new Foo();\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"main() {\n"
|
||||
@@ -1480,19 +1472,7 @@ TEST_CASE(IsolateReload_PendingConstructorCall_ConcreteToAbstract) {
|
||||
"}\n";
|
||||
|
||||
EXPECT_VALID(TestCase::SetReloadTestScript(kReloadScript));
|
||||
|
||||
const char* expected = "exception";
|
||||
const char* result = SimpleInvokeStr(lib, "main");
|
||||
EXPECT_STREQ(expected, result);
|
||||
|
||||
// Bail out if we've already failed so we don't crash in the tag handler.
|
||||
if ((result == NULL) || (strcmp(expected, result) != 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
lib = Dart_RootLibrary();
|
||||
EXPECT_NON_NULL(lib);
|
||||
EXPECT_STREQ(expected, SimpleInvokeStr(lib, "main"));
|
||||
EXPECT_ERROR(SimpleInvokeError(lib, "main"), "is abstract");
|
||||
}
|
||||
|
||||
TEST_CASE(IsolateReload_PendingStaticCall_DefinedToNSM) {
|
||||
@@ -1533,7 +1513,6 @@ TEST_CASE(IsolateReload_PendingStaticCall_DefinedToNSM) {
|
||||
"}\n";
|
||||
|
||||
EXPECT_VALID(TestCase::SetReloadTestScript(kReloadScript));
|
||||
|
||||
const char* expected = "exception";
|
||||
const char* result = SimpleInvokeStr(lib, "main");
|
||||
EXPECT_NOTNULL(result);
|
||||
@@ -1544,12 +1523,6 @@ TEST_CASE(IsolateReload_PendingStaticCall_DefinedToNSM) {
|
||||
}
|
||||
EXPECT_STREQ(expected, result);
|
||||
|
||||
// Bail out if we've already failed so we don't crash in the tag handler.
|
||||
if (strcmp(expected, result) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
EXPECT_STREQ(expected, result);
|
||||
lib = Dart_RootLibrary();
|
||||
EXPECT_NON_NULL(lib);
|
||||
EXPECT_STREQ(expected, SimpleInvokeStr(lib, "main"));
|
||||
@@ -1596,12 +1569,12 @@ TEST_CASE(IsolateReload_PendingStaticCall_NSMToDefined) {
|
||||
|
||||
const char* expected = "static";
|
||||
const char* result = SimpleInvokeStr(lib, "main");
|
||||
EXPECT_STREQ(expected, result);
|
||||
|
||||
// Bail out if we've already failed so we don't crash in the tag handler.
|
||||
if ((result == NULL) || (strcmp(expected, result) != 0)) {
|
||||
if (result == NULL) {
|
||||
return;
|
||||
}
|
||||
EXPECT_STREQ(expected, result);
|
||||
|
||||
lib = Dart_RootLibrary();
|
||||
EXPECT_NON_NULL(lib);
|
||||
|
||||
Reference in New Issue
Block a user