From cf8ca5ead38fdb16c2e069c4e0f05286e5bcff4e Mon Sep 17 00:00:00 2001 From: yiwiy9 Date: Sat, 23 Sep 2023 17:23:35 +0900 Subject: [PATCH] Add cargo test validation before generating snippets --- .devcontainer/cargo_snippet.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.devcontainer/cargo_snippet.sh b/.devcontainer/cargo_snippet.sh index 73c1da5..74b0f3a 100644 --- a/.devcontainer/cargo_snippet.sh +++ b/.devcontainer/cargo_snippet.sh @@ -5,6 +5,13 @@ # Navigate to the lib directory within the workspace folder cd $WORKSPACE_FOLDER/src/lib +# Run the tests silently. Exit with an error if tests fail. +if ! cargo test &>/dev/null; then + echo "Error: Tests failed." + exit 1 +fi + # Generate Rust code snippets using cargo-snippet, then modify the output using sed to add a scope for Rust, # and finally, save the modified output to a rust.code-snippets file in the .vscode directory of the workspace folder cargo snippet -t vscode | sed -r "s/\"prefix\"/\"scope\": \"rust\",\n \"prefix\"/" > $WORKSPACE_FOLDER/.vscode/rust.code-snippets +echo "Snippets generated."