@@ -401,3 +401,70 @@ TEST_F(PluginManagerTest, MatchPluginName) {
401401 ASSERT_FALSE (PluginManager::MatchPluginName (" foo." , Foo, Bar));
402402 ASSERT_FALSE (PluginManager::MatchPluginName (" foo.ba" , Foo, Bar));
403403}
404+
405+ TEST_F (PluginManagerTest, JsonFormat) {
406+ RegisterMockSystemRuntimePlugins ();
407+
408+ // We expect the following JSON output:
409+ // {
410+ // "system-runtime": [
411+ // {
412+ // "enabled": true,
413+ // "name": "a"
414+ // },
415+ // {
416+ // "enabled": true,
417+ // "name": "b"
418+ // },
419+ // {
420+ // "enabled": true,
421+ // "name": "c"
422+ // }
423+ // ]
424+ // }
425+ llvm::json::Object obj = PluginManager::GetJSON ();
426+
427+ // We should have a "system-runtime" array in the top-level object.
428+ llvm::json::Array *maybe_array = obj.getArray (" system-runtime" );
429+ ASSERT_TRUE (maybe_array!= nullptr );
430+ auto &array = *maybe_array;
431+ ASSERT_EQ (array.size (), 3u );
432+
433+ // Check plugin "a" info.
434+ ASSERT_TRUE (array[0 ].getAsObject () != nullptr );
435+ ASSERT_TRUE (array[0 ].getAsObject ()->getString (" name" ) == " a" );
436+ ASSERT_TRUE (array[0 ].getAsObject ()->getBoolean (" enabled" ) == true );
437+
438+ // Check plugin "b" info.
439+ ASSERT_TRUE (array[1 ].getAsObject () != nullptr );
440+ ASSERT_TRUE (array[1 ].getAsObject ()->getString (" name" ) == " b" );
441+ ASSERT_TRUE (array[1 ].getAsObject ()->getBoolean (" enabled" ) == true );
442+
443+ // Check plugin "c" info.
444+ ASSERT_TRUE (array[2 ].getAsObject () != nullptr );
445+ ASSERT_TRUE (array[2 ].getAsObject ()->getString (" name" ) == " c" );
446+ ASSERT_TRUE (array[2 ].getAsObject ()->getBoolean (" enabled" ) == true );
447+
448+ // Disabling a plugin should be reflected in the JSON output.
449+ ASSERT_TRUE (PluginManager::SetSystemRuntimePluginEnabled (" b" , false ));
450+ array = *PluginManager::GetJSON ().getArray (" system-runtime" );
451+ ASSERT_TRUE (array[0 ].getAsObject ()->getBoolean (" enabled" ) == true );
452+ ASSERT_TRUE (array[1 ].getAsObject ()->getBoolean (" enabled" ) == false );
453+ ASSERT_TRUE (array[2 ].getAsObject ()->getBoolean (" enabled" ) == true );
454+
455+ // Un-registering a plugin should be reflected in the JSON output.
456+ ASSERT_TRUE (PluginManager::UnregisterPlugin (CreateSystemRuntimePluginB));
457+ array = *PluginManager::GetJSON ().getArray (" system-runtime" );
458+ ASSERT_EQ (array.size (), 2u );
459+ ASSERT_TRUE (array[0 ].getAsObject ()->getString (" name" ) == " a" );
460+ ASSERT_TRUE (array[1 ].getAsObject ()->getString (" name" ) == " c" );
461+
462+ // Filtering the JSON output should only include the matching plugins.
463+ array = *PluginManager::GetJSON (" system-runtime.c" ).getArray (" system-runtime" );
464+ ASSERT_EQ (array.size (), 1u );
465+ ASSERT_TRUE (array[0 ].getAsObject ()->getString (" name" ) == " c" );
466+
467+ // Empty JSON output is allowed if there are no matching plugins.
468+ obj = PluginManager::GetJSON (" non-existent-plugin" );
469+ ASSERT_TRUE (obj.empty ());
470+ }
0 commit comments