Add integration test example and project rename script

tests/greet.rs shows the tests/ convention alongside the existing
inline unit test in src/lib.rs, so both standard locations are covered.

scripts/rename-project.sh replaces the "rust_template" placeholder
throughout Cargo.toml, flake.nix, nix/rust.nix, src/main.rs,
benches/greet.rs, and tests/greet.rs, then regenerates Cargo.lock.
Verified in a scratch copy: renamed crate builds, tests pass, and the
Nix package builds and runs correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018ALEXkc7pTro7tF1WcUuKb
This commit is contained in:
2026-08-11 00:16:55 +08:00
parent 840cea1f10
commit 2583848813
2 changed files with 60 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Renames the "rust_template" placeholder throughout the project to a
# real crate name. Run from anywhere; it locates the repo root itself.
set -euo pipefail
old_name="rust_template"
usage() {
echo "Usage: $0 <new_name>" >&2
echo " <new_name> must be a valid snake_case Rust crate name (e.g. my_project)" >&2
exit 1
}
[[ $# -eq 1 ]] || usage
new_name="$1"
if ! [[ "$new_name" =~ ^[a-z][a-z0-9_]*$ ]]; then
echo "error: '$new_name' is not a valid snake_case crate name" >&2
exit 1
fi
if [[ "$new_name" == "$old_name" ]]; then
echo "already named '$old_name', nothing to do"
exit 0
fi
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
files=(
Cargo.toml
flake.nix
nix/rust.nix
src/main.rs
benches/greet.rs
tests/greet.rs
)
for f in "${files[@]}"; do
[[ -f "$f" ]] || continue
sed -i.bak "s/${old_name}/${new_name}/g" "$f"
rm -f "${f}.bak"
done
if command -v cargo >/dev/null 2>&1; then
cargo generate-lockfile
else
echo "warning: cargo not on PATH — run 'cargo generate-lockfile' yourself (e.g. inside 'nix develop')" >&2
fi
echo "Renamed '${old_name}' -> '${new_name}'."
echo
echo "Review the diff (git diff), then optionally rename the project directory:"
echo " cd .. && mv $(basename "$root") ${new_name}"
+6
View File
@@ -0,0 +1,6 @@
use rust_template::greet;
#[test]
fn greets_by_name() {
assert_eq!(greet("integration"), "Hello, integration!");
}