From c66a2d908776a18693e510ea62c3a0f41fd971d9 Mon Sep 17 00:00:00 2001 From: Alex Ameen Date: Sun, 31 Dec 2023 15:28:06 -0600 Subject: [PATCH] test update --- src/sh-scripts/ccjs/tests/ccjs.bats | 71 +++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/sh-scripts/ccjs/tests/ccjs.bats b/src/sh-scripts/ccjs/tests/ccjs.bats index 9cb92b5..f6e0564 100644 --- a/src/sh-scripts/ccjs/tests/ccjs.bats +++ b/src/sh-scripts/ccjs/tests/ccjs.bats @@ -201,6 +201,77 @@ teardown() { } +# ---------------------------------------------------------------------------- # + +# bats test_tags=ccjs:add,inline,multiple +@test "'ccjs add' multiple times appends file" { + refute "$TEST" -f compile_commands.json; + run "$CCJS" add -i src/main.cc -- -Iinclude -Wall; + assert_success; + + run "$JQ" -r 'length' compile_commands.json; + assert_success; + assert_output '1'; + + run "$CCJS" add -i src/helper.cc -- -Iinclude -Wall; + assert_success; + + run "$JQ" -r 'length' compile_commands.json; + assert_success; + assert_output '2'; +} + + +# ---------------------------------------------------------------------------- # + +# bats test_tags=ccjs:add,inline,multiple +@test "'ccjs add' updates existing file" { + refute "$TEST" -f compile_commands.json; + run "$CCJS" add -i src/main.cc -- -Iinclude -Wall; + assert_success; + + run "$JQ" -r 'length' compile_commands.json; + assert_success; + assert_output '1'; + + run "$JQ" -r '.[0].arguments|length' compile_commands.json; + assert_success; + assert_output '2'; + + run "$JQ" -r '.[0].arguments[0]' compile_commands.json; + assert_success; + assert_output '-Iinclude'; + + run "$JQ" -r '.[0].arguments[1]' compile_commands.json; + assert_success; + assert_output '-Wall'; + + # Update the entry + run "$CCJS" add -i src/main.cc -- -I../include -Wall -Werror; + assert_success; + + run "$JQ" -r 'length' compile_commands.json; + assert_success; + assert_output '1'; + + run "$JQ" -r '.[0].arguments|length' compile_commands.json; + assert_success; + assert_output '3'; + + run "$JQ" -r '.[0].arguments[0]' compile_commands.json; + assert_success; + assert_output '-I../include'; + + run "$JQ" -r '.[0].arguments[1]' compile_commands.json; + assert_success; + assert_output '-Wall'; + + run "$JQ" -r '.[0].arguments[2]' compile_commands.json; + assert_success; + assert_output '-Werror'; +} + + # ---------------------------------------------------------------------------- # # #