Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(833)

Side by Side Diff: runtime/vm/isolate_reload_test.cc

Issue 2205513002: Pay attention to exports when determine which libraries to reload. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Pay attention to exports when determine which libraries to reload. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/isolate_reload.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_tools_api.h" 6 #include "include/dart_tools_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 777
778 EXPECT_EQ(107, SimpleInvoke(lib, "main")); 778 EXPECT_EQ(107, SimpleInvoke(lib, "main"));
779 779
780 lib = TestCase::GetReloadErrorOrRootLibrary(); 780 lib = TestCase::GetReloadErrorOrRootLibrary();
781 EXPECT_VALID(lib); 781 EXPECT_VALID(lib);
782 EXPECT_EQ(105, SimpleInvoke(lib, "main")); 782 EXPECT_EQ(105, SimpleInvoke(lib, "main"));
783 } 783 }
784 784
785 785
786 TEST_CASE(IsolateReload_LibraryLookup) { 786 TEST_CASE(IsolateReload_LibraryLookup) {
787 const char* kImportScript =
788 "importedFunc() => 'a';\n";
789 TestCase::AddTestLib("test:lib1", kImportScript);
790
787 const char* kScript = 791 const char* kScript =
788 "main() {\n" 792 "main() {\n"
789 " return importedFunc();\n" 793 " return importedFunc();\n"
790 "}\n"; 794 "}\n";
791
792 Dart_Handle result; 795 Dart_Handle result;
793
794 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 796 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
795 EXPECT_VALID(lib); 797 EXPECT_VALID(lib);
796 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc"); 798 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc");
797 799
798 // Fail to find 'test:importable_lib' in the isolate. 800 // Fail to find 'test:lib1' in the isolate.
799 result = Dart_LookupLibrary(NewString("test:importable_lib")); 801 result = Dart_LookupLibrary(NewString("test:lib1"));
800 EXPECT(Dart_IsError(result)); 802 EXPECT(Dart_IsError(result));
801 803
802 const char* kReloadScript = 804 const char* kReloadScript =
803 "import 'test:importable_lib';\n" 805 "import 'test:lib1';\n"
804 "main() {\n" 806 "main() {\n"
805 " return importedFunc();\n" 807 " return importedFunc();\n"
806 "}\n"; 808 "}\n";
807 809
808 // Reload and add 'test:importable_lib' to isolate. 810 // Reload and add 'test:lib1' to isolate.
809 lib = TestCase::ReloadTestScript(kReloadScript); 811 lib = TestCase::ReloadTestScript(kReloadScript);
810 EXPECT_VALID(lib); 812 EXPECT_VALID(lib);
811 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main")); 813 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main"));
812 814
813 // Find 'test:importable_lib' in the isolate. 815 // Find 'test:lib1' in the isolate.
814 result = Dart_LookupLibrary(NewString("test:importable_lib")); 816 result = Dart_LookupLibrary(NewString("test:lib1"));
815 EXPECT(Dart_IsLibrary(result)); 817 EXPECT(Dart_IsLibrary(result));
816 818
817 // Reload and remove 'dart:math' from isolate. 819 // Reload and remove 'dart:math' from isolate.
818 lib = TestCase::ReloadTestScript(kScript); 820 lib = TestCase::ReloadTestScript(kScript);
819 EXPECT_VALID(lib); 821 EXPECT_VALID(lib);
820 822
821 // Fail to find 'test:importable_lib' in the isolate. 823 // Fail to find 'test:lib1' in the isolate.
822 result = Dart_LookupLibrary(NewString("test:importable_lib")); 824 result = Dart_LookupLibrary(NewString("test:lib1"));
823 EXPECT(Dart_IsError(result)); 825 EXPECT(Dart_IsError(result));
824 } 826 }
825 827
826 828
827 TEST_CASE(IsolateReload_LibraryHide) { 829 TEST_CASE(IsolateReload_LibraryHide) {
828 // Import 'test:importable_lib' with importedFunc hidden. Will result in an 830 const char* kImportScript =
831 "importedFunc() => 'a';\n";
832 TestCase::AddTestLib("test:lib1", kImportScript);
833
834 // Import 'test:lib1' with importedFunc hidden. Will result in an
829 // error. 835 // error.
830 const char* kScript = 836 const char* kScript =
831 "import 'test:importable_lib' hide importedFunc;\n" 837 "import 'test:lib1' hide importedFunc;\n"
832 "main() {\n" 838 "main() {\n"
833 " return importedFunc();\n" 839 " return importedFunc();\n"
834 "}\n"; 840 "}\n";
835 841
836 // Dart_Handle result; 842 // Dart_Handle result;
837 843
838 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 844 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
839 EXPECT_VALID(lib); 845 EXPECT_VALID(lib);
840 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc"); 846 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc");
841 847
842 // Import 'test:importable_lib'. 848 // Import 'test:lib1'.
843 const char* kReloadScript = 849 const char* kReloadScript =
844 "import 'test:importable_lib';\n" 850 "import 'test:lib1';\n"
845 "main() {\n" 851 "main() {\n"
846 " return importedFunc();\n" 852 " return importedFunc();\n"
847 "}\n"; 853 "}\n";
848 854
849 lib = TestCase::ReloadTestScript(kReloadScript); 855 lib = TestCase::ReloadTestScript(kReloadScript);
850 EXPECT_VALID(lib); 856 EXPECT_VALID(lib);
851 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main")); 857 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main"));
852 } 858 }
853 859
854 860
855 TEST_CASE(IsolateReload_LibraryShow) { 861 TEST_CASE(IsolateReload_LibraryShow) {
856 // Import 'test:importable_lib' with importedIntFunc visible. Will result in 862 const char* kImportScript =
863 "importedFunc() => 'a';\n"
864 "importedIntFunc() => 4;\n";
865 TestCase::AddTestLib("test:lib1", kImportScript);
866
867 // Import 'test:lib1' with importedIntFunc visible. Will result in
857 // an error when 'main' is invoked. 868 // an error when 'main' is invoked.
858 const char* kScript = 869 const char* kScript =
859 "import 'test:importable_lib' show importedIntFunc;\n" 870 "import 'test:lib1' show importedIntFunc;\n"
860 "main() {\n" 871 "main() {\n"
861 " return importedFunc();\n" 872 " return importedFunc();\n"
862 "}\n" 873 "}\n"
863 "mainInt() {\n" 874 "mainInt() {\n"
864 " return importedIntFunc();\n" 875 " return importedIntFunc();\n"
865 "}\n"; 876 "}\n";
866 877
867 878
868 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 879 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
869 EXPECT_VALID(lib); 880 EXPECT_VALID(lib);
870 881
871 // Works. 882 // Works.
872 EXPECT_EQ(4, SimpleInvoke(lib, "mainInt")); 883 EXPECT_EQ(4, SimpleInvoke(lib, "mainInt"));
873 // Results in an error. 884 // Results in an error.
874 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc"); 885 EXPECT_ERROR(SimpleInvokeError(lib, "main"), "importedFunc");
875 886
876 // Import 'test:importable_lib' with importedFunc visible. Will result in 887 // Import 'test:lib1' with importedFunc visible. Will result in
877 // an error when 'mainInt' is invoked. 888 // an error when 'mainInt' is invoked.
878 const char* kReloadScript = 889 const char* kReloadScript =
879 "import 'test:importable_lib' show importedFunc;\n" 890 "import 'test:lib1' show importedFunc;\n"
880 "main() {\n" 891 "main() {\n"
881 " return importedFunc();\n" 892 " return importedFunc();\n"
882 "}\n" 893 "}\n"
883 "mainInt() {\n" 894 "mainInt() {\n"
884 " return importedIntFunc();\n" 895 " return importedIntFunc();\n"
885 "}\n"; 896 "}\n";
886 897
887 lib = TestCase::ReloadTestScript(kReloadScript); 898 lib = TestCase::ReloadTestScript(kReloadScript);
888 EXPECT_VALID(lib); 899 EXPECT_VALID(lib);
889 900
890 // Works. 901 // Works.
891 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main")); 902 EXPECT_STREQ("a", SimpleInvokeStr(lib, "main"));
892 // Results in an error. 903 // Results in an error.
893 EXPECT_ERROR(SimpleInvokeError(lib, "mainInt"), "importedIntFunc"); 904 EXPECT_ERROR(SimpleInvokeError(lib, "mainInt"), "importedIntFunc");
894 } 905 }
895 906
896 907
897 // Verifies that we clear the ICs for the functions live on the stack in a way 908 // Verifies that we clear the ICs for the functions live on the stack in a way
898 // that is compatible with the fast path smi stubs. 909 // that is compatible with the fast path smi stubs.
899 TEST_CASE(IsolateReload_SmiFastPathStubs) { 910 TEST_CASE(IsolateReload_SmiFastPathStubs) {
911 const char* kImportScript =
912 "importedIntFunc() => 4;\n";
913 TestCase::AddTestLib("test:lib1", kImportScript);
914
900 const char* kScript = 915 const char* kScript =
901 "import 'test:isolate_reload_helper';\n" 916 "import 'test:isolate_reload_helper';\n"
902 "import 'test:importable_lib' show importedIntFunc;\n" 917 "import 'test:lib1' show importedIntFunc;\n"
903 "main() {\n" 918 "main() {\n"
904 " var x = importedIntFunc();\n" 919 " var x = importedIntFunc();\n"
905 " var y = importedIntFunc();\n" 920 " var y = importedIntFunc();\n"
906 " reloadTest();\n" 921 " reloadTest();\n"
907 " return x + y;\n" 922 " return x + y;\n"
908 "}\n"; 923 "}\n";
909 924
910 925
911 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 926 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
912 EXPECT_VALID(lib); 927 EXPECT_VALID(lib);
913 928
914 // Identity reload. 929 // Identity reload.
915 TestCase::SetReloadTestScript(kScript); 930 TestCase::SetReloadTestScript(kScript);
916 931
917 EXPECT_EQ(8, SimpleInvoke(lib, "main")); 932 EXPECT_EQ(8, SimpleInvoke(lib, "main"));
918 } 933 }
919 934
920 935
921 // Verifies that we assign the correct patch classes for imported 936 // Verifies that we assign the correct patch classes for imported
922 // mixins when we reload. 937 // mixins when we reload.
923 TEST_CASE(IsolateReload_ImportedMixinFunction) { 938 TEST_CASE(IsolateReload_ImportedMixinFunction) {
939 const char* kImportScript =
940 "class ImportedMixin {\n"
941 " mixinFunc() => 'mixin';\n"
942 "}\n";
943 TestCase::AddTestLib("test:lib1", kImportScript);
944
924 const char* kScript = 945 const char* kScript =
925 "import 'test:importable_lib' show ImportedMixin;\n" 946 "import 'test:lib1' show ImportedMixin;\n"
926 "class A extends Object with ImportedMixin {\n" 947 "class A extends Object with ImportedMixin {\n"
927 "}" 948 "}"
928 "var func = new A().mixinFunc;\n" 949 "var func = new A().mixinFunc;\n"
929 "main() {\n" 950 "main() {\n"
930 " return func();\n" 951 " return func();\n"
931 "}\n"; 952 "}\n";
932 953
933 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 954 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
934 EXPECT_VALID(lib); 955 EXPECT_VALID(lib);
935 956
936 EXPECT_STREQ("mixin", SimpleInvokeStr(lib, "main")); 957 EXPECT_STREQ("mixin", SimpleInvokeStr(lib, "main"));
937 958
938 const char* kReloadScript = 959 const char* kReloadScript =
939 "import 'test:importable_lib' show ImportedMixin;\n" 960 "import 'test:lib1' show ImportedMixin;\n"
940 "class A extends Object with ImportedMixin {\n" 961 "class A extends Object with ImportedMixin {\n"
941 "}" 962 "}"
942 "var func;\n" 963 "var func;\n"
943 "main() {\n" 964 "main() {\n"
944 " return func();\n" 965 " return func();\n"
945 "}\n"; 966 "}\n";
946 967
947 lib = TestCase::ReloadTestScript(kReloadScript); 968 lib = TestCase::ReloadTestScript(kReloadScript);
948 EXPECT_VALID(lib); 969 EXPECT_VALID(lib);
949 EXPECT_STREQ("mixin", SimpleInvokeStr(lib, "main")); 970 EXPECT_STREQ("mixin", SimpleInvokeStr(lib, "main"));
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 } 2245 }
2225 2246
2226 static bool NothingModifiedCallback(const char* url, int64_t since) { 2247 static bool NothingModifiedCallback(const char* url, int64_t since) {
2227 return false; 2248 return false;
2228 } 2249 }
2229 2250
2230 2251
2231 TEST_CASE(IsolateReload_NoLibsModified) { 2252 TEST_CASE(IsolateReload_NoLibsModified) {
2232 const char* kImportScript = 2253 const char* kImportScript =
2233 "importedFunc() => 'fancy';"; 2254 "importedFunc() => 'fancy';";
2234 TestCase::SetImportableTestLibScript(kImportScript); 2255 TestCase::AddTestLib("test:lib1", kImportScript);
2235 2256
2236 const char* kScript = 2257 const char* kScript =
2237 "import 'test:importable_lib';\n" 2258 "import 'test:lib1';\n"
2238 "main() {\n" 2259 "main() {\n"
2239 " return importedFunc() + ' feast';\n" 2260 " return importedFunc() + ' feast';\n"
2240 "}\n"; 2261 "}\n";
2241 2262
2242 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 2263 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
2243 EXPECT_VALID(lib); 2264 EXPECT_VALID(lib);
2244 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); 2265 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2245 2266
2246 const char* kReloadImportScript = 2267 const char* kReloadImportScript =
2247 "importedFunc() => 'bossy';"; 2268 "importedFunc() => 'bossy';";
2248 TestCase::SetImportableTestLibScript(kReloadImportScript); 2269 TestCase::AddTestLib("test:lib1", kReloadImportScript);
2249 2270
2250 const char* kReloadScript = 2271 const char* kReloadScript =
2251 "import 'test:importable_lib';\n" 2272 "import 'test:lib1';\n"
2252 "main() {\n" 2273 "main() {\n"
2253 " return importedFunc() + ' pants';\n" 2274 " return importedFunc() + ' pants';\n"
2254 "}\n"; 2275 "}\n";
2255 2276
2256 Dart_SetFileModifiedCallback(&NothingModifiedCallback); 2277 Dart_SetFileModifiedCallback(&NothingModifiedCallback);
2257 lib = TestCase::ReloadTestScript(kReloadScript); 2278 lib = TestCase::ReloadTestScript(kReloadScript);
2258 EXPECT_VALID(lib); 2279 EXPECT_VALID(lib);
2259 Dart_SetFileModifiedCallback(NULL); 2280 Dart_SetFileModifiedCallback(NULL);
2260 2281
2261 // No reload occurred because no files were "modified". 2282 // No reload occurred because no files were "modified".
2262 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); 2283 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2263 } 2284 }
2264 2285
2265 2286
2266 static bool MainModifiedCallback(const char* url, int64_t since) { 2287 static bool MainModifiedCallback(const char* url, int64_t since) {
2267 if (strcmp(url, "test-lib") == 0) { 2288 if (strcmp(url, "test-lib") == 0) {
2268 return true; 2289 return true;
2269 } 2290 }
2270 return false; 2291 return false;
2271 } 2292 }
2272 2293
2273 2294
2274 TEST_CASE(IsolateReload_MainLibModified) { 2295 TEST_CASE(IsolateReload_MainLibModified) {
2275 const char* kImportScript = 2296 const char* kImportScript =
2276 "importedFunc() => 'fancy';"; 2297 "importedFunc() => 'fancy';";
2277 TestCase::SetImportableTestLibScript(kImportScript); 2298 TestCase::AddTestLib("test:lib1", kImportScript);
2278 2299
2279 const char* kScript = 2300 const char* kScript =
2280 "import 'test:importable_lib';\n" 2301 "import 'test:lib1';\n"
2281 "main() {\n" 2302 "main() {\n"
2282 " return importedFunc() + ' feast';\n" 2303 " return importedFunc() + ' feast';\n"
2283 "}\n"; 2304 "}\n";
2284 2305
2285 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 2306 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
2286 EXPECT_VALID(lib); 2307 EXPECT_VALID(lib);
2287 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); 2308 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2288 2309
2289 const char* kReloadImportScript = 2310 const char* kReloadImportScript =
2290 "importedFunc() => 'bossy';"; 2311 "importedFunc() => 'bossy';";
2291 TestCase::SetImportableTestLibScript(kReloadImportScript); 2312 TestCase::AddTestLib("test:lib1", kReloadImportScript);
2292 2313
2293 const char* kReloadScript = 2314 const char* kReloadScript =
2294 "import 'test:importable_lib';\n" 2315 "import 'test:lib1';\n"
2295 "main() {\n" 2316 "main() {\n"
2296 " return importedFunc() + ' pants';\n" 2317 " return importedFunc() + ' pants';\n"
2297 "}\n"; 2318 "}\n";
2298 2319
2299 Dart_SetFileModifiedCallback(&MainModifiedCallback); 2320 Dart_SetFileModifiedCallback(&MainModifiedCallback);
2300 lib = TestCase::ReloadTestScript(kReloadScript); 2321 lib = TestCase::ReloadTestScript(kReloadScript);
2301 EXPECT_VALID(lib); 2322 EXPECT_VALID(lib);
2302 Dart_SetFileModifiedCallback(NULL); 2323 Dart_SetFileModifiedCallback(NULL);
2303 2324
2304 // Imported library is not reloaded. 2325 // Imported library is not reloaded.
2305 EXPECT_STREQ("fancy pants", SimpleInvokeStr(lib, "main")); 2326 EXPECT_STREQ("fancy pants", SimpleInvokeStr(lib, "main"));
2306 } 2327 }
2307 2328
2308 2329
2309 static bool ImportModifiedCallback(const char* url, int64_t since) { 2330 static bool ImportModifiedCallback(const char* url, int64_t since) {
2310 if (strcmp(url, "test:importable_lib") == 0) { 2331 if (strcmp(url, "test:lib1") == 0) {
2311 return true; 2332 return true;
2312 } 2333 }
2313 return false; 2334 return false;
2314 } 2335 }
2315 2336
2316 2337
2317 TEST_CASE(IsolateReload_ImportedLibModified) { 2338 TEST_CASE(IsolateReload_ImportedLibModified) {
2318 const char* kImportScript = 2339 const char* kImportScript =
2319 "importedFunc() => 'fancy';"; 2340 "importedFunc() => 'fancy';";
2320 TestCase::SetImportableTestLibScript(kImportScript); 2341 TestCase::AddTestLib("test:lib1", kImportScript);
2321 2342
2322 const char* kScript = 2343 const char* kScript =
2323 "import 'test:importable_lib';\n" 2344 "import 'test:lib1';\n"
2324 "main() {\n" 2345 "main() {\n"
2325 " return importedFunc() + ' feast';\n" 2346 " return importedFunc() + ' feast';\n"
2326 "}\n"; 2347 "}\n";
2327 2348
2328 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 2349 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
2329 EXPECT_VALID(lib); 2350 EXPECT_VALID(lib);
2330 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); 2351 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2331 2352
2332 const char* kReloadImportScript = 2353 const char* kReloadImportScript =
2333 "importedFunc() => 'bossy';"; 2354 "importedFunc() => 'bossy';";
2334 TestCase::SetImportableTestLibScript(kReloadImportScript); 2355 TestCase::AddTestLib("test:lib1", kReloadImportScript);
2335 2356
2336 const char* kReloadScript = 2357 const char* kReloadScript =
2337 "import 'test:importable_lib';\n" 2358 "import 'test:lib1';\n"
2338 "main() {\n" 2359 "main() {\n"
2339 " return importedFunc() + ' pants';\n" 2360 " return importedFunc() + ' pants';\n"
2340 "}\n"; 2361 "}\n";
2341 2362
2342 Dart_SetFileModifiedCallback(&ImportModifiedCallback); 2363 Dart_SetFileModifiedCallback(&ImportModifiedCallback);
2343 lib = TestCase::ReloadTestScript(kReloadScript); 2364 lib = TestCase::ReloadTestScript(kReloadScript);
2344 EXPECT_VALID(lib); 2365 EXPECT_VALID(lib);
2345 Dart_SetFileModifiedCallback(NULL); 2366 Dart_SetFileModifiedCallback(NULL);
2346 2367
2347 // Modification of an imported library propagates to the importing library. 2368 // Modification of an imported library propagates to the importing library.
2348 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); 2369 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
2349 } 2370 }
2350 2371
2351 2372
2352 TEST_CASE(IsolateReload_PrefixImportedLibModified) { 2373 TEST_CASE(IsolateReload_PrefixImportedLibModified) {
2353 const char* kImportScript = 2374 const char* kImportScript =
2354 "importedFunc() => 'fancy';"; 2375 "importedFunc() => 'fancy';";
2355 TestCase::SetImportableTestLibScript(kImportScript); 2376 TestCase::AddTestLib("test:lib1", kImportScript);
2356 2377
2357 const char* kScript = 2378 const char* kScript =
2358 "import 'test:importable_lib' as cobra;\n" 2379 "import 'test:lib1' as cobra;\n"
2359 "main() {\n" 2380 "main() {\n"
2360 " return cobra.importedFunc() + ' feast';\n" 2381 " return cobra.importedFunc() + ' feast';\n"
2361 "}\n"; 2382 "}\n";
2362 2383
2363 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 2384 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
2364 EXPECT_VALID(lib); 2385 EXPECT_VALID(lib);
2365 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main")); 2386 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2366 2387
2367 const char* kReloadImportScript = 2388 const char* kReloadImportScript =
2368 "importedFunc() => 'bossy';"; 2389 "importedFunc() => 'bossy';";
2369 TestCase::SetImportableTestLibScript(kReloadImportScript); 2390 TestCase::AddTestLib("test:lib1", kReloadImportScript);
2370 2391
2371 const char* kReloadScript = 2392 const char* kReloadScript =
2372 "import 'test:importable_lib' as cobra;\n" 2393 "import 'test:lib1' as cobra;\n"
2373 "main() {\n" 2394 "main() {\n"
2374 " return cobra.importedFunc() + ' pants';\n" 2395 " return cobra.importedFunc() + ' pants';\n"
2375 "}\n"; 2396 "}\n";
2376 2397
2377 Dart_SetFileModifiedCallback(&ImportModifiedCallback); 2398 Dart_SetFileModifiedCallback(&ImportModifiedCallback);
2378 lib = TestCase::ReloadTestScript(kReloadScript); 2399 lib = TestCase::ReloadTestScript(kReloadScript);
2379 EXPECT_VALID(lib); 2400 EXPECT_VALID(lib);
2380 Dart_SetFileModifiedCallback(NULL); 2401 Dart_SetFileModifiedCallback(NULL);
2381 2402
2382 // Modification of an prefix-imported library propagates to the 2403 // Modification of an prefix-imported library propagates to the
2383 // importing library. 2404 // importing library.
2384 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main")); 2405 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
2385 } 2406 }
2386 2407
2387 2408
2409 static bool ExportModifiedCallback(const char* url, int64_t since) {
2410 if (strcmp(url, "test:exportlib") == 0) {
2411 return true;
2412 }
2413 return false;
2414 }
2415
2416
2417 TEST_CASE(IsolateReload_ExportedLibModified) {
2418 const char* kImportScript =
2419 "export 'test:exportlib';";
2420 TestCase::AddTestLib("test:importlib", kImportScript);
2421
2422 const char* kExportScript =
2423 "exportedFunc() => 'fancy';";
2424 TestCase::AddTestLib("test:exportlib", kExportScript);
2425
2426 const char* kScript =
2427 "import 'test:importlib';\n"
2428 "main() {\n"
2429 " return exportedFunc() + ' feast';\n"
2430 "}\n";
2431
2432 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
2433 EXPECT_VALID(lib);
2434 EXPECT_STREQ("fancy feast", SimpleInvokeStr(lib, "main"));
2435
2436 const char* kReloadExportScript =
2437 "exportedFunc() => 'bossy';";
2438 TestCase::AddTestLib("test:exportlib", kReloadExportScript);
2439
2440 const char* kReloadScript =
2441 "import 'test:importlib';\n"
2442 "main() {\n"
2443 " return exportedFunc() + ' pants';\n"
2444 "}\n";
2445
2446 Dart_SetFileModifiedCallback(&ExportModifiedCallback);
2447 lib = TestCase::ReloadTestScript(kReloadScript);
2448 EXPECT_VALID(lib);
2449 Dart_SetFileModifiedCallback(NULL);
2450
2451 // Modification of an exported library propagates.
2452 EXPECT_STREQ("bossy pants", SimpleInvokeStr(lib, "main"));
2453 }
2454
2388 #endif // !PRODUCT 2455 #endif // !PRODUCT
2389 2456
2390 } // namespace dart 2457 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/isolate_reload.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698