Write JSON to a temp file, load into a CDB, remove the file. Returns the number of entries loaded.
| 449 | /// Write JSON to a temp file, load into a CDB, remove the file. |
| 450 | /// Returns the number of entries loaded. |
| 451 | std::size_t load_json(CompilationDatabase& database, llvm::StringRef json) { |
| 452 | auto path = fs::createTemporaryFile("cdb", "json"); |
| 453 | if(!path) |
| 454 | return 0; |
| 455 | { |
| 456 | std::error_code ec; |
| 457 | llvm::raw_fd_ostream out(*path, ec); |
| 458 | if(ec) |
| 459 | return 0; |
| 460 | out << json; |
| 461 | } |
| 462 | auto count = database.load(*path).value_or(0); |
| 463 | llvm::sys::fs::remove(*path); |
| 464 | return count; |
| 465 | } |
| 466 | |
| 467 | TEST_CASE(LoadMixedFormats) { |
| 468 | /// "arguments" array and "command" string can coexist in the same CDB. |
no test coverage detected