|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# check-deprecated-cookie-overload.sh — negative-compile gate pinning the |
| 4 | +# [[deprecated]] attribute on the legacy string-blob cookie overload |
| 5 | +# http_response::with_cookie(std::string, std::string) (TASK-064). |
| 6 | +# |
| 7 | +# test/unit/cookie_deprecation_sentinel_test.cpp pins the POSITIVE side |
| 8 | +# (the deprecated overload still compiles behind a #pragma suppression |
| 9 | +# block). The negative side — that the [[deprecated]] warning IS emitted |
| 10 | +# on a suppression-free compile — was previously unverified: if someone |
| 11 | +# removed the attribute, nothing would catch it (code-review finding on |
| 12 | +# TASK-064). This gate closes that hole: |
| 13 | +# |
| 14 | +# 1. Positive control: a TU calling the structured overload |
| 15 | +# with_cookie(cookie) MUST compile cleanly under |
| 16 | +# -Werror=deprecated-declarations. This proves a failure in step 2 |
| 17 | +# comes from the deprecation, not from a broken header or |
| 18 | +# environment. |
| 19 | +# 2. Negative check: a TU calling the deprecated overload |
| 20 | +# with_cookie(std::string, std::string) MUST FAIL to compile under |
| 21 | +# -Werror=deprecated-declarations, and the compiler output must |
| 22 | +# mention "deprecated" (so an unrelated compile error cannot fake a |
| 23 | +# pass). |
| 24 | +# |
| 25 | +# Both TUs include only the umbrella <httpserver.hpp> (public headers |
| 26 | +# reject direct inclusion) and are compiled with -fsyntax-only, so no |
| 27 | +# build tree, config.h, or libmicrohttpd is needed — the script runs |
| 28 | +# standalone from a fresh checkout. -std=c++20 matches the umbrella's |
| 29 | +# own version gate (httpserver.hpp #errors below C++20) and the |
| 30 | +# CHECK_HEADERS_CXX invocation in Makefile.am. |
| 31 | +# |
| 32 | +# The compiler is ${CXX:-c++}; the Makefile target passes the configured |
| 33 | +# $(CXX) through. |
| 34 | +# |
| 35 | +# Exit codes: |
| 36 | +# 0 attribute in place (positive control compiles, negative TU fails |
| 37 | +# with a deprecation diagnostic) |
| 38 | +# 1 regression (deprecated overload compiled cleanly, positive |
| 39 | +# control broke, or the negative TU failed for the wrong reason) |
| 40 | +set -euo pipefail |
| 41 | + |
| 42 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 43 | +# The configured $(CXX) may be multi-word (e.g. "g++ -std=c++20"), so |
| 44 | +# split it into an argv array rather than quoting it as one command name. |
| 45 | +read -r -a CXX_CMD <<< "${CXX:-c++}" |
| 46 | +COMMON_FLAGS=(-std=c++20 -fsyntax-only -I"$REPO_ROOT/src" |
| 47 | + -Werror=deprecated-declarations) |
| 48 | + |
| 49 | +WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/check-deprecated-cookie.XXXXXX")" |
| 50 | +trap 'rm -rf "$WORKDIR"' EXIT |
| 51 | + |
| 52 | +# Positive control: structured overload, must compile cleanly. |
| 53 | +cat > "$WORKDIR/positive.cpp" <<'EOF' |
| 54 | +#include <httpserver.hpp> |
| 55 | +void structured_overload_ok(httpserver::http_response& r) { |
| 56 | + r.with_cookie(httpserver::cookie{}.with_name("sid").with_value("v")); |
| 57 | +} |
| 58 | +EOF |
| 59 | + |
| 60 | +# Negative TU: deprecated legacy overload, must trip |
| 61 | +# -Werror=deprecated-declarations. |
| 62 | +cat > "$WORKDIR/negative.cpp" <<'EOF' |
| 63 | +#include <httpserver.hpp> |
| 64 | +#include <string> |
| 65 | +void deprecated_overload_trips(httpserver::http_response& r) { |
| 66 | + r.with_cookie(std::string("sid"), std::string("v")); |
| 67 | +} |
| 68 | +EOF |
| 69 | + |
| 70 | +echo "check-deprecated-cookie-overload: compiler: ${CXX_CMD[*]}" |
| 71 | + |
| 72 | +if ! "${CXX_CMD[@]}" "${COMMON_FLAGS[@]}" "$WORKDIR/positive.cpp" \ |
| 73 | + 2>"$WORKDIR/positive.log"; then |
| 74 | + echo "check-deprecated-cookie-overload: FAIL — positive control did not compile" >&2 |
| 75 | + echo " the structured with_cookie(cookie) TU must build cleanly under" >&2 |
| 76 | + echo " -Werror=deprecated-declarations; fix the header (or this gate) first:" >&2 |
| 77 | + sed 's/^/ /' "$WORKDIR/positive.log" >&2 |
| 78 | + exit 1 |
| 79 | +fi |
| 80 | +echo " positive control: structured with_cookie(cookie) compiles cleanly" |
| 81 | + |
| 82 | +if "${CXX_CMD[@]}" "${COMMON_FLAGS[@]}" "$WORKDIR/negative.cpp" \ |
| 83 | + 2>"$WORKDIR/negative.log"; then |
| 84 | + echo "check-deprecated-cookie-overload: FAIL — with_cookie(std::string, std::string) compiled without a deprecation error" >&2 |
| 85 | + echo " the [[deprecated]] attribute on the legacy overload in" >&2 |
| 86 | + echo " src/httpserver/http_response.hpp has been removed or no longer fires" >&2 |
| 87 | + exit 1 |
| 88 | +fi |
| 89 | + |
| 90 | +if ! grep -qi "deprecated" "$WORKDIR/negative.log"; then |
| 91 | + echo "check-deprecated-cookie-overload: FAIL — negative TU failed for the wrong reason" >&2 |
| 92 | + echo " expected a -Wdeprecated-declarations diagnostic; got:" >&2 |
| 93 | + sed 's/^/ /' "$WORKDIR/negative.log" >&2 |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | +echo " negative check: legacy with_cookie(string, string) trips -Werror=deprecated-declarations" |
| 97 | + |
| 98 | +echo "check-deprecated-cookie-overload: PASS — [[deprecated]] attribute is in place" |
0 commit comments