|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +cd $(dirname $0) |
| 4 | +source "../utils.sh" |
| 5 | + |
| 6 | +bold "Test: A module reached only through its own namespace is a dependency" |
| 7 | + |
| 8 | +fixture=$(mktemp -d 2>/dev/null || mktemp -d -t rewatch-qualified-own-namespace) |
| 9 | +trap "rm -rf '$fixture'" EXIT |
| 10 | + |
| 11 | +mkdir -p "$fixture/src" |
| 12 | + |
| 13 | +cat > "$fixture/rescript.json" <<'JSON' |
| 14 | +{ |
| 15 | + "name": "rewatch-qualified-own-namespace", |
| 16 | + "namespace": "Ns", |
| 17 | + "sources": { "dir": "src" }, |
| 18 | + "package-specs": { "module": "esmodule", "in-source": true }, |
| 19 | + "suffix": ".mjs" |
| 20 | +} |
| 21 | +JSON |
| 22 | + |
| 23 | +# User names Target only as Ns.Target, so its AST header must say so: the |
| 24 | +# bare namespace does not tell the build system which module to wait for. |
| 25 | +cat > "$fixture/src/Target.res" <<'RES' |
| 26 | +let value = 1 |
| 27 | +RES |
| 28 | + |
| 29 | +cat > "$fixture/src/User.res" <<'RES' |
| 30 | +let value = Ns.Target.value + 1 |
| 31 | +RES |
| 32 | + |
| 33 | +cd "$fixture" |
| 34 | +if ! compiler_output=$("$REWATCH_EXECUTABLE" build 2>&1); then |
| 35 | + error "Clean build compiled User before Target" |
| 36 | + printf "%s\n" "$compiler_output" >&2 |
| 37 | + exit 1 |
| 38 | +fi |
| 39 | + |
| 40 | +# Changing Target must recompile User and report its new type error. |
| 41 | +cat > src/Target.res <<'RES' |
| 42 | +let value = "not an int" |
| 43 | +RES |
| 44 | + |
| 45 | +if compiler_output=$("$REWATCH_EXECUTABLE" build 2>&1); then |
| 46 | + error "Incremental build did not recompile User after Target changed" |
| 47 | + printf "%s\n" "$compiler_output" >&2 |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | + |
| 51 | +if ! printf '%s\n' "$compiler_output" | grep -q "User.res"; then |
| 52 | + error "Incremental build did not report the error in User" |
| 53 | + printf "%s\n" "$compiler_output" >&2 |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +success "Modules reached through their own namespace are dependencies" |
0 commit comments