From 5a2fd67074be8d3366a97ac3e2a474d40dc2c2fa Mon Sep 17 00:00:00 2001 From: sarfaraz siddiqui Date: Mon, 22 Apr 2024 01:21:32 +0530 Subject: [PATCH] added a script to check for warnings --- .../standard_library_tests_and_examples.yml | 4 +- stdlib/scripts/check-file-is-empty.py | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 stdlib/scripts/check-file-is-empty.py diff --git a/.github/workflows/standard_library_tests_and_examples.yml b/.github/workflows/standard_library_tests_and_examples.yml index c45614056..0e660a10c 100644 --- a/.github/workflows/standard_library_tests_and_examples.yml +++ b/.github/workflows/standard_library_tests_and_examples.yml @@ -99,12 +99,14 @@ jobs: - name: Validate documentation strings run: | - mojo doc -warn-missing-doc-strings -o /dev/null stdlib/src/ + mojo doc -warn-missing-doc-strings -o /dev/null stdlib/src/ > warnings.txt 2>&1 + ./check-file-is-empty.py warnings.txt if [ $? -ne 0 ]; then echo "::error::Documentation string validation failed. Please fix the issues and try again." exit 1 fi + - name: Run standard library tests and examples run: | ./stdlib/scripts/run-tests.sh diff --git a/stdlib/scripts/check-file-is-empty.py b/stdlib/scripts/check-file-is-empty.py new file mode 100644 index 000000000..6e45c0ff9 --- /dev/null +++ b/stdlib/scripts/check-file-is-empty.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# ===----------------------------------------------------------------------=== # +# Copyright (c) 2024, Modular Inc. All rights reserved. +# +# Licensed under the Apache License v2.0 with LLVM Exceptions: +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ===----------------------------------------------------------------------=== # + +import argparse +import os +import sys + + +def main(): + parser = argparse.ArgumentParser( + description=( + "Exits successfully if the file at the given path is empty or does" + " not exist. Otherwise, prints the file's contents, then exits" + " unsuccessfully." + ) + ) + parser.add_argument("path") + args = parser.parse_args() + + if not os.path.exists(args.path): + return + + with open(args.path, "r") as f: + content = f.read().strip() + if content: + print( + f"error: '{args.path}' is not empty:\n{content}", + file=sys.stderr, + ) + exit(1) + + +if __name__ == "__main__": + main() \ No newline at end of file