Skip to content

[clang-format] Add test to ensure formatting options docs are updated #118154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

boomanaiden154
Copy link
Contributor

This patch adds a lit test to clang format to ensure that the ClangFormatStyleOptions doc page has been updated appropriately. The test just runs the automatic update script and diffs the outputs to ensure they are the same.

This patch adds a lit test to clang format to ensure that the
ClangFormatStyleOptions doc page has been updated appropriately. The
test just runs the automatic update script and diffs the outputs to
ensure they are the same.
@boomanaiden154 boomanaiden154 marked this pull request as ready for review December 5, 2024 06:53
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-format labels Dec 5, 2024
@boomanaiden154 boomanaiden154 requested a review from owenca December 5, 2024 06:53
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2024

@llvm/pr-subscribers-clang-format

@llvm/pr-subscribers-clang

Author: Aiden Grossman (boomanaiden154)

Changes

This patch adds a lit test to clang format to ensure that the ClangFormatStyleOptions doc page has been updated appropriately. The test just runs the automatic update script and diffs the outputs to ensure they are the same.


Full diff: https://github.com/llvm/llvm-project/pull/118154.diff

3 Files Affected:

  • (modified) clang/docs/tools/dump_format_style.py (+2-1)
  • (added) clang/test/Format/docs_updated.test (+2)
  • (modified) clang/test/Format/lit.local.cfg (+1)
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index af0e658fcdc55d..c82b4479f299d9 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -487,5 +487,6 @@ class State:
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)
 
-with open(DOC_FILE, "wb") as output:
+output_file_path = sys.argv[1] if len(sys.argv) == 2 else DOC_FILE
+with open(output_file_path, "wb") as output:
     output.write(contents.encode())
diff --git a/clang/test/Format/docs_updated.test b/clang/test/Format/docs_updated.test
new file mode 100644
index 00000000000000..fe2e4f1bd13a1b
--- /dev/null
+++ b/clang/test/Format/docs_updated.test
@@ -0,0 +1,2 @@
+// RUN: %python %S/../../docs/tools/dump_format_style.py %t
+// RUN: diff %t %S/../../docs/ClangFormatStyleOptions.rst
diff --git a/clang/test/Format/lit.local.cfg b/clang/test/Format/lit.local.cfg
index 3eb0f54ceaa6f9..8acf02725d701b 100644
--- a/clang/test/Format/lit.local.cfg
+++ b/clang/test/Format/lit.local.cfg
@@ -17,4 +17,5 @@ config.suffixes = [
     ".textpb",
     ".asciipb",
     ".td",
+    ".test"
 ]

@boomanaiden154 boomanaiden154 merged commit a9a4a83 into llvm:main Dec 5, 2024
14 checks passed
@boomanaiden154 boomanaiden154 deleted the clang-format-check-docs-updated branch December 5, 2024 07:41
@mikaelholmen
Copy link
Collaborator

Hello,

When running the new testcase the file plurals.txt, which is in the repo, is opened for writing? Is this really desired?

I noticed this when I tried to run top of tree lit tests in an environment setup with read-only access on the files in the repo.

@mikaelholmen
Copy link
Collaborator

Hello,

When running the new testcase the file plurals.txt, which is in the repo, is opened for writing? Is this really desired?

I noticed this when I tried to run top of tree lit tests in an environment setup with read-only access on the files in the repo.

Hm, or it's not related to the testcase, but it happens every time we build now due to 6bec180

[clang-format] Add plurals.txt to DEPENDS of style_options_depends

? So when we build, plurals.txt is opened for writing?

@boomanaiden154
Copy link
Contributor Author

Hm, or it's not related to the testcase, but it happens every time we build now due to 6bec180

That's more likely to be due to #111513. That got reverted. If it's still an issue here, let me know. Everything should be read only here, but that doesn't mean things aren't getting opened with inappropriate permissions.

@owenca
Copy link
Contributor

owenca commented Dec 6, 2024

When running the new testcase the file plurals.txt, which is in the repo, is opened for writing? Is this really desired?

Fixed in 74d29c6.

@mikaelholmen
Copy link
Collaborator

Thanks!

@owenca owenca removed the clang Clang issues not falling into any other category label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants