diff --git a/README.md b/README.md index 00a7c40..76c36a2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ # rusttest-to-dg Converts `rustc` testcases into dejagnu testcases for `gccrs` + +# Usage + +This tool was invoked by the script [run](./run.sh). Furthermore, we need the rustc and gccrs source code to be downloaded on the system. And add their paths to the environment variables `GCCRS_PATH`, `RUST_PATH` and `RUSTTEST_TO_DG_PATH` + +```bash +export GCCRS_PATH=/path/to/gccrs +export RUST_PATH=/path/to/rust +export RUSTTEST_TO_DG_PATH=/path/to/rusttest-to-dg +``` + +Then, simply run the script [run](./run.sh) + +```bash +bash run.sh +``` diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..3412415 --- /dev/null +++ b/run.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +set -e + +# if GCCRS_PATH is set +if [ -z "$GCCRS_PATH" ]; then + echo "Error: GCCRS_PATH environment variable is not set." + echo -e "Please set it using the command:\n\texport GCCRS_PATH=/path/to/gccrs" + exit 1 +fi + +# if RUST_PATH is set +if [ -z "$RUST_PATH" ]; then + echo "Error: RUST_PATH environment variable is not set." + echo -e "Please set it using the command:\n\texport RUST_PATH=/path/to/rust" + exit 1 +fi + +# check for rusttest-to-dg path +if [ -z "$RUSTTEST_TO_DG_PATH" ]; then + echo "Error: RUSTTEST_TO_DG_PATH environment variable is not set." + echo -e "Please set it using the command:\n\texport RUSTTEST_TO_DG_PATH=/path/to/rusttest-to-dg" + exit 1 +fi + +echo "GCCRS_PATH: $GCCRS_PATH" +echo "RUST_PATH: $RUST_PATH" +echo "RUSTTEST_TO_DG_PATH: $RUSTTEST_TO_DG_PATH" + +# Installing rusttest-to-dg +cd "$RUSTTEST_TO_DG_PATH" +echo -e "\nInstalling rusttest-to-dg\n" +cargo install --path . +echo -e "\nInstalled rusttest-to-dg\n" + + +# Check if the ui directory exists and remove it if it does +if [ -d "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui" ]; then + echo "Removing existing ui directory at $GCCRS_PATH/gcc/testsuite/rust/rustc/ui" + rm -rf "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui" +fi + + + +# Copying the RUST_PATH/tests/ui to GCCRS_PATH/gcc/testsuite/rust/rustc +echo -e "Copying tests from $RUST_PATH/tests/ui to $GCCRS_PATH/gcc/testsuite/rust/rustc" +cp -r "$RUST_PATH"/tests/ui "$GCCRS_PATH"/gcc/testsuite/rust/rustc +echo -e "Copied $RUST_PATH/tests/ui tests to $GCCRS_PATH/gcc/testsuite/rust/rustc/ui" +cd "$GCCRS_PATH"/gcc/testsuite/rust/rustc/ui + +process_files() { + # Recursively process rust files + for file in "$1"/*.rs; do + if [[ -f "$file" ]]; then + base_name="${file%.rs}" + stderr_file="${base_name}.stderr" + output_file="${base_name}_dg.rs" + + # if we have `.stderr` file + if [[ -f "$stderr_file" ]]; then + rusttest-to-dg "$file" --stderr "$stderr_file" > "$output_file" + else + rusttest-to-dg "$file" > "$output_file" + fi + mv "$output_file" "$file" + fi + done + + # Recursively process subdirectories + for dir in "$1"/*/; do + if [[ -d "$dir" ]]; then + process_files "$dir" + fi + done +} + +echo -e "Converting rustc source files to DejaGnu format..." +process_files "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui/" + +# Remove all files that don't end with .rs extension in the ui directory +echo "Removing non-.rs files in $GCCRS_PATH/gcc/testsuite/rust/rustc/ui" +find "$GCCRS_PATH/gcc/testsuite/rust/rustc/ui" -type f ! -name '*.rs' -exec rm -f {} + +echo "Removed non-.rs files in $GCCRS_PATH/gcc/testsuite/rust/rustc/ui" + +echo -e "Processing complete." \ No newline at end of file diff --git a/src/cli.rs b/src/cli.rs index c87dc4d..1db5fc6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,8 +15,7 @@ use { pub struct Arguments { /// The rust source file to convert into `DejaGnu` format #[arg( - short = 'f', - long = "file", + // positional argument value_name = "FILE", help = "The rust source file to convert into DejaGnu format" )] @@ -60,14 +59,14 @@ mod tests { #[test] fn test_required_argument_file() { - let args = Arguments::parse_from(["test", "-f", "test.rs"]); + let args = Arguments::parse_from(["test", "test.rs"]); assert_eq!(args.source_file, path::PathBuf::from("test.rs")); assert_eq!(args.stderr_file, None); } #[test] fn test_optional_argument_file() { - let args = Arguments::parse_from(["test", "-f", "test.rs", "-e", "test.stderr"]); + let args = Arguments::parse_from(["test", "test.rs", "-e", "test.stderr"]); assert_eq!(args.source_file, path::PathBuf::from("test.rs")); assert_eq!(args.stderr_file, Some(path::PathBuf::from("test.stderr"))); }