mikemirzayanov 7 月之前
父节点
当前提交
a047899821
共有 3 个文件被更改,包括 195 次插入203 次删除
  1. 20 20
      testlib.h
  2. 61 69
      tests/scripts/compile
  3. 114 114
      tests/scripts/test-ref

+ 20 - 20
testlib.h

@@ -3454,7 +3454,7 @@ static inline bool equals(unsigned long long integer, const char *s) {
 }
 
 static inline double stringToDouble(InStream &in, const char *buffer) {
-    double retval;
+    double result;
 
     size_t length = strlen(buffer);
 
@@ -3488,14 +3488,14 @@ static inline double stringToDouble(InStream &in, const char *buffer) {
 
     char *suffix = new char[length + 1];
     std::memset(suffix, 0, length + 1);
-    int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix);
+    int scanned = std::sscanf(buffer, "%lf%s", &result, suffix);
     bool empty = strlen(suffix) == 0;
     delete[] suffix;
 
     if (scanned == 1 || (scanned == 2 && empty)) {
-        if (__testlib_isNaN(retval))
+        if (__testlib_isNaN(result))
             in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str());
-        return retval;
+        return result;
     } else
         in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str());
 }
@@ -3516,7 +3516,7 @@ static inline double stringToStrictDouble(InStream &in, const char *buffer,
         in.quit(_fail,
                 "stringToStrictDouble: minAfterPointDigitCount should be less or equal to maxAfterPointDigitCount.");
 
-    double retval;
+    double result;
 
     size_t length = strlen(buffer);
 
@@ -3565,16 +3565,16 @@ static inline double stringToStrictDouble(InStream &in, const char *buffer,
 
     char *suffix = new char[length + 1];
     std::memset(suffix, 0, length + 1);
-    int scanned = std::sscanf(buffer, "%lf%s", &retval, suffix);
+    int scanned = std::sscanf(buffer, "%lf%s", &result, suffix);
     bool empty = strlen(suffix) == 0;
     delete[] suffix;
 
     if (scanned == 1 || (scanned == 2 && empty)) {
-        if (__testlib_isNaN(retval) || __testlib_isInfinite(retval))
+        if (__testlib_isNaN(result) || __testlib_isInfinite(result))
             in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str());
-        if (buffer[0] == '-' && retval >= 0)
+        if (buffer[0] == '-' && result >= 0)
             in.quit(_pe, ("Redundant minus in \"" + __testlib_part(buffer) + "\" found").c_str());
-        return retval;
+        return result;
     } else
         in.quit(_pe, ("Expected double, but \"" + __testlib_part(buffer) + "\" found").c_str());
 }
@@ -3606,19 +3606,19 @@ static inline long long stringToLongLong(InStream &in, const char *buffer) {
             in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
     }
 
-    long long int retval;
+    long long int result;
     try {
-        retval = std::stoll(buffer);
-    } catch (const std::out_of_range& ignored) {
+        result = std::stoll(buffer);
+    } catch (const std::exception&) {
         in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
-    } catch (const std::invalid_argument& ignored) {
+    } catch (...) {
         in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
     }
 
-    if ((zeroes > 0 && (retval != 0 || has_minus)) || zeroes > 1)
+    if ((zeroes > 0 && (result != 0 || has_minus)) || zeroes > 1)
         in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
 
-    return retval;
+    return result;
 }
 
 static inline long long stringToLongLong(InStream &in, const std::string& buffer) {
@@ -3641,16 +3641,16 @@ static inline unsigned long long stringToUnsignedLongLong(InStream &in, const ch
             in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
     }
 
-    unsigned long long retval;
+    unsigned long long result;
     try {
-        retval = std::stoull(buffer);
-    } catch (const std::out_of_range& ignored) {
+        result = std::stoull(buffer);
+    } catch (const std::exception&) {
         in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
-    } catch (const std::invalid_argument& ignored) {
+    } catch (...) {
         in.quit(_pe, ("Expected unsigned integer, but \"" + __testlib_part(buffer) + "\" found").c_str());
     }
 
-    return retval;
+    return result;
 }
 
 static inline long long stringToUnsignedLongLong(InStream &in, const std::string& buffer) {

+ 61 - 69
tests/scripts/compile

@@ -1,69 +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" == "clang++" && "$MACHINE" == "Windows" ]]; then
-#  msvc_version="2022"
-#  wk_version="10.0.19041.0"
-#  EXTRA_ARGS=" -I\"$TESTS_DIR/lib/msvc-$msvc_version-include\""
-#  for s in cppwinrt shared ucrt um winrt; do
-#    EXTRA_ARGS="$EXTRA_ARGS -I\"$TESTS_DIR/lib/windows-kit-$wk_version-include/$s\""
-#  done
-#fi
-
-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