-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CompilationDatabase.split (issue #624)
- Loading branch information
Showing
3 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
open OUnit2 | ||
|
||
let command_object_from_string s = | ||
s | ||
|> Yojson.Safe.from_string | ||
|> CompilationDatabase.command_object_of_yojson | ||
|> Result.get_ok | ||
|
||
let test_split_arguments _ = | ||
let obj = command_object_from_string {json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"arguments": [ | ||
"gcc", | ||
"-DANSWER=42", | ||
"-Ilib/", | ||
"main.c", | ||
"lib/lib.c" | ||
], | ||
"file": "lib/lib.c" | ||
} | ||
|json} | ||
in | ||
let actual_split = CompilationDatabase.split obj in | ||
let expected_split = List.map command_object_from_string [ | ||
{json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"arguments": [ | ||
"gcc", | ||
"-DANSWER=42", | ||
"-Ilib/", | ||
"main.c" | ||
], | ||
"file": "main.c" | ||
} | ||
|json}; | ||
{json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"arguments": [ | ||
"gcc", | ||
"-DANSWER=42", | ||
"-Ilib/", | ||
"lib/lib.c" | ||
], | ||
"file": "lib/lib.c" | ||
} | ||
|json}; | ||
] | ||
in | ||
assert_equal ~printer:CompilationDatabase.show expected_split actual_split | ||
|
||
let test_split_command _ = | ||
let obj = command_object_from_string {json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"command": "gcc -DANSWER=42 -Ilib/ main.c lib/lib.c", | ||
"file": "lib/lib.c" | ||
} | ||
|json} | ||
in | ||
let actual_split = CompilationDatabase.split obj in | ||
let expected_split = List.map command_object_from_string [ | ||
{json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"command": "gcc -DANSWER=42 -Ilib/ main.c", | ||
"file": "main.c" | ||
} | ||
|json}; | ||
{json| | ||
{ | ||
"directory": "/home/simmo/Desktop/goblint-action-test/makefile-project", | ||
"command": "gcc -DANSWER=42 -Ilib/ lib/lib.c", | ||
"file": "lib/lib.c" | ||
} | ||
|json}; | ||
] | ||
in | ||
assert_equal ~printer:CompilationDatabase.show expected_split actual_split | ||
|
||
let tests = | ||
"compilationDatabaseTest" >::: [ | ||
"split" >::: [ | ||
"arguments" >:: test_split_arguments; | ||
"command" >:: test_split_command; | ||
]; | ||
] |