Skip to content

Commit

Permalink
format_file_check_test: extend to test multiple files
Browse files Browse the repository at this point in the history
generalize format_file_check_test.sh to test both formatted and
unformatted files, single or multiple files at a time

test that --verify returns correct return code for each case

(currently fails for multiple files)

remove format_file_check_nochange_test.sh because its test case is also
covered
  • Loading branch information
hellux committed Nov 1, 2024
1 parent 86ee9ba commit d00c72d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 65 deletions.
8 changes: 0 additions & 8 deletions verilog/tools/formatter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@ sh_test_with_runfiles_lib(
data = [":verible-verilog-format"],
)

sh_test_with_runfiles_lib(
name = "format-file-nochange-check_test",
size = "small",
srcs = ["format_file_check_nochange_test.sh"],
args = ["$(location :verible-verilog-format)"],
data = [":verible-verilog-format"],
)

sh_test_with_runfiles_lib(
name = "format-file-lex-error_test",
size = "small",
Expand Down
45 changes: 0 additions & 45 deletions verilog/tools/formatter/format_file_check_nochange_test.sh

This file was deleted.

42 changes: 30 additions & 12 deletions verilog/tools/formatter/format_file_check_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,47 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Tests verible-verilog-format reading from a file, checking for formatting
# changes where changes are needed. This should return 1.
# Tests verible-verilog-format reading from single or multiple files, checking
# for formatting changes where changes are needed. This should return 1 if any
# of the files are incorrectly formatted.


declare -r MY_INPUT_FILE="${TEST_TMPDIR}/myinput.txt"

# Get tool from argument
[[ "$#" == 1 ]] || {
echo "Expecting 1 positional argument, verible-verilog-format path."
exit 1
}
formatter="$(rlocation ${TEST_WORKSPACE}/${1})"

cat >${MY_INPUT_FILE} <<EOF
# create 1 formatted and 1 unformatted file
unformatted="${TEST_TMPDIR}/unformatted.sv"
formatted="${TEST_TMPDIR}/formatted.sv"
cat >"${unformatted}" <<EOF
module m ;endmodule
EOF
cp "$unformatted" "$formatted"
$formatter --inplace "$formatted"

cases=(
"$formatted"
"$unformatted"
"$unformatted $unformatted"
"$unformatted $formatted"
"$formatted $unformatted"
"$formatted $formatted"
)

# Run formatter.
${formatter} --verbose --verify ${MY_INPUT_FILE}
if [ "$?" -eq 0 ]; then
echo "Changes should produce non-zero error code"
echo "FAIL"
exit 1
fi
for files in "${cases[@]}"; do
echo "$files" | grep -q unformatted.sv
expected_ret=$((!$?))
echo Formatting...
${formatter} --verbose --verify --inplace $files
actual_ret=$?
if [ "$actual_ret" -ne "$expected_ret" ]; then
echo "Expected return code $expected_ret, got $actual_ret"
echo "FAIL"
exit 1
fi
done

echo "PASS"

0 comments on commit d00c72d

Please sign in to comment.