mikemirzayanov 7 hónapja
szülő
commit
abef2d687b
2 módosított fájl, 175 hozzáadás és 175 törlés
  1. 61 61
      tests/scripts/compile
  2. 114 114
      tests/scripts/test-ref

+ 61 - 61
tests/scripts/compile

@@ -1,61 +1,61 @@
-#!/bin/bash
-set -eo pipefail
-
-SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
-
-src_file=$1
-exe_file=$(basename "${src_file%.*}")
-
-if [[ -z "$MACHINE" ]]; then
-  echo "Must provide MACHINE for compile"
-  exit 1
-fi
-
-if [[ "$MACHINE" == "Windows" ]]; then
-  exe_file=$(basename "${src_file%.*}".exe)
-fi
-
-if [[ -z "$src_file" ]]; then
-  echo "Must provide \$1 for compile"
-  exit 1
-fi
-
-if [[ -z "$CPP_INCLUDE_DIR" ]]; then
-  echo "Must provide CPP_INCLUDE_DIR in environment"
-  exit 1
-fi
-
-if [[ -z "$CPP" ]]; then
-  echo "Must provide CPP in environment"
-  exit 1
-fi
-
-rm -f "$exe_file"
-
-EXTRA_ARGS=""
-
-if [[ "$CPP" == "cl.exe" ]]; then
-  echo "Compiling $src_file, running:" "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
-  "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
-else
-  "$CPP" --version
-  dir=$(dirname "$CPP")
-  if [[ "$dir" == *"/bin" ]] || [[ "$MACHINE" == "Windows" ]]; then
-    EXTRA_ARGS="${EXTRA_ARGS} -static"
-  fi
-  echo "Compiling $src_file, running:" "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
-  eval "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
-fi
-
-rm -f ./*.o ./*.obj
-
-if [ ! -f "$exe_file" ]; then
-  echo "Compilation failed: file $exe_file not found"
-  exit 1
-fi
-
-echo -e "${SUCCESS_TXT} $src_file compiled\n"
-
-if [[ "$2" == "--check-only" ]]; then
-  rm -rf "$exe_file"
-fi
+#!/bin/bash
+set -eo pipefail
+
+SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
+
+src_file=$1
+exe_file=$(basename "${src_file%.*}")
+
+if [[ -z "$MACHINE" ]]; then
+  echo "Must provide MACHINE for compile"
+  exit 1
+fi
+
+if [[ "$MACHINE" == "Windows" ]]; then
+  exe_file=$(basename "${src_file%.*}".exe)
+fi
+
+if [[ -z "$src_file" ]]; then
+  echo "Must provide \$1 for compile"
+  exit 1
+fi
+
+if [[ -z "$CPP_INCLUDE_DIR" ]]; then
+  echo "Must provide CPP_INCLUDE_DIR in environment"
+  exit 1
+fi
+
+if [[ -z "$CPP" ]]; then
+  echo "Must provide CPP in environment"
+  exit 1
+fi
+
+rm -f "$exe_file"
+
+EXTRA_ARGS=""
+
+if [[ "$CPP" == "cl.exe" ]]; then
+  echo "Compiling $src_file, running:" "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
+  "$CPP" "$CPP_STANDARD" "-F268435456" "-EHsc" "-O2" -I"${CPP_INCLUDE_DIR}" -Fe"$exe_file" "$src_file"
+else
+  "$CPP" --version
+  dir=$(dirname "$CPP")
+  if [[ "$dir" == *"/bin" ]] || [[ "$MACHINE" == "Windows" ]]; then
+    EXTRA_ARGS="${EXTRA_ARGS} -static"
+  fi
+  echo "Compiling $src_file, running:" "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
+  eval "$CPP" "$CPP_OPTS" "$CPP_STANDARD" -Wpedantic -Werror -I"${CPP_INCLUDE_DIR}""$EXTRA_ARGS" -o"$exe_file" -O2 "$src_file"
+fi
+
+rm -f ./*.o ./*.obj
+
+if [ ! -f "$exe_file" ]; then
+  echo "Compilation failed: file $exe_file not found"
+  exit 1
+fi
+
+echo -e "${SUCCESS_TXT} $src_file compiled\n"
+
+if [[ "$2" == "--check-only" ]]; then
+  rm -rf "$exe_file"
+fi

+ 114 - 114
tests/scripts/test-ref

@@ -1,114 +1,114 @@
-#!/bin/bash
-set -eo pipefail
-
-FAILED_TXT="${RED}[FAILED]${NC}"
-SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
-
-# Check $TESTS_DIR is given
-if [[ -z "$TESTS_DIR" ]]; then
-  echo "Must provide \$TESTS_DIR env variable"
-  exit 1
-fi
-
-# Check $INVOCATION_ID is given: we use it as cache key to be sure compiled tester-lcmp is actual (see file $TESTS_DIR/tester-lcmp/tester-lcmp.$INVOCATION_ID)
-if [[ -z "$INVOCATION_ID" ]]; then
-  echo "Must provide \$INVOCATION_ID env variable"
-  exit 1
-fi
-
-mkdir -p "$TESTS_DIR"/tester-lcmp
-
-# If compiled tester-lcmp is not actual
-if [ ! -f "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" ]; then
-  # Clear
-  rm -f "$TESTS_DIR"/tester-lcmp/*
-
-  # Compile it
-  CPP_INCLUDE_DIR_=$CPP_INCLUDE_DIR
-  export CPP_INCLUDE_DIR=$TESTS_DIR/lib
-  bash "$TESTS_DIR"/scripts/compile "$TESTS_DIR"/src/tester-lcmp.cpp
-  export CPP_INCLUDE_DIR=$CPP_INCLUDE_DIR_
-
-  # Move from current dir to /tester-lcmp
-  if [ ! -d ./tester-lcmp ]; then
-    mv -f ./tester-lcmp "$TESTS_DIR"/tester-lcmp
-  else
-    mv -f ./tester-lcmp.exe "$TESTS_DIR"/tester-lcmp
-  fi
-
-  # Create file to inform that it was compiled to this $INVOCATION_ID
-  touch "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID"
-fi
-
-# First argument as a subdirectory in ./refs
-ref_dir=$1
-if [[ -z "$ref_dir" ]]; then
-  echo "Must provide \$1 for test-ref"
-  exit 1
-fi
-
-refs=refs/$1
-
-shift 1
-
-# Check if we don't have invocation reference files
-if [ ! -d "$refs" ]; then
-  if [[ "$TEST_REF_FORBID_GEN_REFS" == "true" ]]; then
-    echo "You forgot to run push ref files for invocation: ""$*"""
-    echo "Run test locally, it will produce ref files and push it into the repo"
-    exit 1
-  fi
-  # Create them
-  mkdir -p "$refs"
-  echo Generating tester refs: "$*"
-  exit_code=0
-  # shellcheck disable=SC2048
-  $* 1>"$refs"/stdout 2>"$refs"/stderr || exit_code=$?
-  echo $exit_code >"$refs"/exit_code
-  echo -e "${SUCCESS_TXT} generated execution reference files (exit code: $exit_code)\n"
-else
-  # Do invocation
-  echo Testing refs: "$*"
-  exit_code=0
-  # shellcheck disable=SC2048
-  $* 1>"$refs"/stdout.aux 2>"$refs"/stderr.aux || exit_code=$?
-  echo "Program exit code: $exit_code, stdout size: $(stat -c %s "$refs"/stdout.aux) bytes, stderr size: $(stat -c %s "$refs"/stderr.aux) bytes"
-  echo $exit_code >"$refs"/exit_code.aux
-
-  # Check exit code is the same
-  tester_lcmp_exit_code=0
-  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/exit_code.aux "$refs"/exit_code 2>tester-lcmp.out || tester_lcmp_exit_code=$?
-  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
-    echo -e "${FAILED_TXT} exit_code mismatched: found $(cat < "$refs"/exit_code.aux) but expected $(cat "$refs"/exit_code)\n"
-    cat tester-lcmp.out
-    rm -f tester-lcmp.out
-    rm -f "$refs"/*.aux
-    exit 1
-  fi
-  echo $exit_code >"$refs"/exit_code.aux
-
-  # Check stdout is the same
-  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stdout.aux "$refs"/stdout 2>tester-lcmp.out || tester_lcmp_exit_code=$?
-  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
-    echo -e "${FAILED_TXT} stdout mismatched\n"
-    cat tester-lcmp.out
-    rm -f tester-lcmp.out
-    rm -f "$refs"/*.aux
-    exit 1
-  fi
-
-  # Check stderr is the same
-  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stderr.aux "$refs"/stderr 2>tester-lcmp.out || tester_lcmp_exit_code=$?
-  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
-    echo -e "${FAILED_TXT} stderr mismatched\n"
-    cat tester-lcmp.out
-    rm -f tester-lcmp.out
-    rm -f "$refs"/*.aux
-    exit 1
-  fi
-
-  # Invocation is the same!
-  echo -e "${SUCCESS_TXT} execution matched with reference (exit code: $exit_code)\n"
-  rm -f tester-lcmp.out
-  rm -f "$refs"/*.aux
-fi
+#!/bin/bash
+set -eo pipefail
+
+FAILED_TXT="${RED}[FAILED]${NC}"
+SUCCESS_TXT="${GREEN}[SUCCESS]${NC}"
+
+# Check $TESTS_DIR is given
+if [[ -z "$TESTS_DIR" ]]; then
+  echo "Must provide \$TESTS_DIR env variable"
+  exit 1
+fi
+
+# Check $INVOCATION_ID is given: we use it as cache key to be sure compiled tester-lcmp is actual (see file $TESTS_DIR/tester-lcmp/tester-lcmp.$INVOCATION_ID)
+if [[ -z "$INVOCATION_ID" ]]; then
+  echo "Must provide \$INVOCATION_ID env variable"
+  exit 1
+fi
+
+mkdir -p "$TESTS_DIR"/tester-lcmp
+
+# If compiled tester-lcmp is not actual
+if [ ! -f "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" ]; then
+  # Clear
+  rm -f "$TESTS_DIR"/tester-lcmp/*
+
+  # Compile it
+  CPP_INCLUDE_DIR_=$CPP_INCLUDE_DIR
+  export CPP_INCLUDE_DIR=$TESTS_DIR/lib
+  bash "$TESTS_DIR"/scripts/compile "$TESTS_DIR"/src/tester-lcmp.cpp
+  export CPP_INCLUDE_DIR=$CPP_INCLUDE_DIR_
+
+  # Move from current dir to /tester-lcmp
+  if [ ! -d ./tester-lcmp ]; then
+    mv -f ./tester-lcmp "$TESTS_DIR"/tester-lcmp
+  else
+    mv -f ./tester-lcmp.exe "$TESTS_DIR"/tester-lcmp
+  fi
+
+  # Create file to inform that it was compiled to this $INVOCATION_ID
+  touch "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID"
+fi
+
+# First argument as a subdirectory in ./refs
+ref_dir=$1
+if [[ -z "$ref_dir" ]]; then
+  echo "Must provide \$1 for test-ref"
+  exit 1
+fi
+
+refs=refs/$1
+
+shift 1
+
+# Check if we don't have invocation reference files
+if [ ! -d "$refs" ]; then
+  if [[ "$TEST_REF_FORBID_GEN_REFS" == "true" ]]; then
+    echo "You forgot to run push ref files for invocation: ""$*"""
+    echo "Run test locally, it will produce ref files and push it into the repo"
+    exit 1
+  fi
+  # Create them
+  mkdir -p "$refs"
+  echo Generating tester refs: "$*"
+  exit_code=0
+  # shellcheck disable=SC2048
+  $* 1>"$refs"/stdout 2>"$refs"/stderr || exit_code=$?
+  echo $exit_code >"$refs"/exit_code
+  echo -e "${SUCCESS_TXT} generated execution reference files (exit code: $exit_code)\n"
+else
+  # Do invocation
+  echo Testing refs: "$*"
+  exit_code=0
+  # shellcheck disable=SC2048
+  $* 1>"$refs"/stdout.aux 2>"$refs"/stderr.aux || exit_code=$?
+  echo "Program exit code: $exit_code, stdout size: $(stat -c %s "$refs"/stdout.aux) bytes, stderr size: $(stat -c %s "$refs"/stderr.aux) bytes"
+  echo $exit_code >"$refs"/exit_code.aux
+
+  # Check exit code is the same
+  tester_lcmp_exit_code=0
+  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/exit_code.aux "$refs"/exit_code 2>tester-lcmp.out || tester_lcmp_exit_code=$?
+  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
+    echo -e "${FAILED_TXT} exit_code mismatched: found $(cat < "$refs"/exit_code.aux) but expected $(cat "$refs"/exit_code)\n"
+    cat tester-lcmp.out
+    rm -f tester-lcmp.out
+    rm -f "$refs"/*.aux
+    exit 1
+  fi
+  echo $exit_code >"$refs"/exit_code.aux
+
+  # Check stdout is the same
+  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stdout.aux "$refs"/stdout 2>tester-lcmp.out || tester_lcmp_exit_code=$?
+  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
+    echo -e "${FAILED_TXT} stdout mismatched\n"
+    cat tester-lcmp.out
+    rm -f tester-lcmp.out
+    rm -f "$refs"/*.aux
+    exit 1
+  fi
+
+  # Check stderr is the same
+  "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stderr.aux "$refs"/stderr 2>tester-lcmp.out || tester_lcmp_exit_code=$?
+  if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
+    echo -e "${FAILED_TXT} stderr mismatched\n"
+    cat tester-lcmp.out
+    rm -f tester-lcmp.out
+    rm -f "$refs"/*.aux
+    exit 1
+  fi
+
+  # Invocation is the same!
+  echo -e "${SUCCESS_TXT} execution matched with reference (exit code: $exit_code)\n"
+  rm -f tester-lcmp.out
+  rm -f "$refs"/*.aux
+fi