-
Notifications
You must be signed in to change notification settings - Fork 487
test: regression guard for cross-lib reads of pre-pp source #14400
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
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
58251d0
test: regression guard for cross-lib reads of pre-pp source
robinbb c331433
test: bump cross-lib-walk-pre-pp-source.t to (lang dune 3.24)
robinbb 3491acd
test: also assert the registered cross-lib dep shape
robinbb 939b6f2
test: use make_dune_project helper in cross-lib-walk-pre-pp-source.t
robinbb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
test/blackbox-tests/test-cases/per-module-lib-deps/cross-lib-walk-pre-pp-source.t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| A consumer of a library that uses [(preprocess (action ...))] must | ||
| still build when the dep's pre-preprocessing source is not valid | ||
| OCaml on its own. Concretely: if any code path runs ocamldep on the | ||
| raw, pre-[Module.pped] form of the dep's [.ml] (the [Module.t] from | ||
| [Dir_contents.modules_of_local_lib], whose [Module.source] points | ||
| at the unprocessed [.ml] and whose [Module.pp_flags] is [None]), | ||
| ocamldep rejects the source with a syntax error and the build | ||
| fails. | ||
|
|
||
| The neighbour test [cross-lib-action-preprocess.t] covers the same | ||
| scenario with a pass-through preprocessor and plain-OCaml sources, | ||
| so a code path that runs ocamldep on the pre-pp form goes | ||
| undetected. This test plugs that gap: [pp.exe] strips [#]-prefixed | ||
| lines, and [dep/foo.ml] starts with a [#if]/[#endif] block. | ||
| Ocamldep on the post-pp output is fine; ocamldep on the pre-pp | ||
| input is a syntax error. | ||
|
|
||
| $ cat > dune-project <<EOF | ||
| > (lang dune 3.0) | ||
| > EOF | ||
|
|
||
| A trivial preprocessor that drops every line starting with [#]. | ||
| This mimics cppo's behaviour without needing an external tool: the | ||
| [.ml] holds [#if]/[#endif]-style markers; the preprocessor's output | ||
| is plain OCaml. | ||
|
|
||
| $ mkdir pp | ||
| $ cat > pp/dune <<EOF | ||
| > (executable (name pp)) | ||
| > EOF | ||
| $ cat > pp/pp.ml <<'EOF' | ||
| > let () = | ||
| > let ic = open_in_bin Sys.argv.(1) in | ||
| > try | ||
| > while true do | ||
| > let line = input_line ic in | ||
| > if String.length line = 0 || line.[0] <> '#' | ||
| > then print_endline line | ||
| > done | ||
| > with End_of_file -> () | ||
| > EOF | ||
|
|
||
| [dep] is an unwrapped, multi-module library whose modules are | ||
| preprocessed. [foo.ml] has a [#]-prefixed directive that ocamldep | ||
| cannot parse but the preprocessor strips. [bar.ml] is the second | ||
| module: keeping the lib multi-module ensures any future per-module | ||
| code path that short-circuits single-module stanzas doesn't mask | ||
| the regression this test guards against. | ||
|
|
||
| $ mkdir dep | ||
| $ cat > dep/dune <<EOF | ||
| > (library | ||
| > (name dep) | ||
| > (wrapped false) | ||
| > (preprocess (action (run %{exe:../pp/pp.exe} %{input-file})))) | ||
| > EOF | ||
| $ cat > dep/foo.ml <<'EOF' | ||
| > #if FAKE_DIRECTIVE | ||
| > let v = 1 | ||
| > #endif | ||
| > EOF | ||
| $ cat > dep/bar.ml <<EOF | ||
| > let helper = 42 | ||
| > EOF | ||
|
|
||
| [consumer] references [Foo] from [dep]. Any cross-library | ||
| dependency-tracking code path that resolves [Foo]'s deps against | ||
| the dep's pre-pp source would fail here: | ||
|
|
||
| $ mkdir consumer | ||
| $ cat > consumer/dune <<EOF | ||
| > (library (name consumer) (wrapped false) (libraries dep)) | ||
| > EOF | ||
| $ cat > consumer/c.ml <<EOF | ||
| > let _ = Foo.v | ||
| > EOF | ||
| $ cat > consumer/d.ml <<EOF | ||
| > let _ = () | ||
| > EOF | ||
|
|
||
| The build must succeed. If a future change reintroduces a cross- | ||
| library code path that runs ocamldep on the pre-[Module.pped] form | ||
| of a foreign-lib module without re-applying that lib's preprocessor, | ||
| this test will fail with a syntax error from [dep/foo.ml]. | ||
|
|
||
| $ dune build @check | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.