From d54ea7ac5127faa71f7f7f0a39cf522d0f05caab Mon Sep 17 00:00:00 2001 From: Pierre Villemot Date: Fri, 11 Oct 2024 17:38:21 +0200 Subject: [PATCH 1/3] Fix the tests --- gixsql-tests-nunit/Runner.cs | 4 +- gixsql-tests-nunit/data/gixsql_test_data.xml | 12 +- .../gixsql_test_local_ocamlpro.xml | 161 ++++++++++++++++++ libgixpp/ESQLDefinitions.h | 6 +- 4 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml diff --git a/gixsql-tests-nunit/Runner.cs b/gixsql-tests-nunit/Runner.cs index 512583f..4920eae 100644 --- a/gixsql-tests-nunit/Runner.cs +++ b/gixsql-tests-nunit/Runner.cs @@ -1,4 +1,4 @@ -using gixsql_tests; +using gixsql_tests; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using System; using System.Collections.Generic; @@ -42,7 +42,7 @@ public static int Main(string[] args) } } - int num_results_ok = results.Count(a => a.Value == "KO"); + int num_results_ok = results.Count(a => a.Value == "OK"); int num_results_ko = results.Count(a => a.Value == "KO"); int mlen = results.Select(a => a.Key.Length).Max(); diff --git a/gixsql-tests-nunit/data/gixsql_test_data.xml b/gixsql-tests-nunit/data/gixsql_test_data.xml index 7680b50..7f3c5b2 100644 --- a/gixsql-tests-nunit/data/gixsql_test_data.xml +++ b/gixsql-tests-nunit/data/gixsql_test_data.xml @@ -1,8 +1,8 @@ - + - + Open connection, cursor #000 @@ -234,7 +234,7 @@ - + employee #: [+0123] @@ -2293,7 +2293,7 @@ CREATE TABLE TAB02 (CID INTEGER, FLD CHAR(100)) CREATE TABLE TAB03 (CID INTEGER, FLD CHAR(100)) CREATE TABLE TAB04 (CID INTEGER, FLD CHAR(100)) - + @@ -2785,7 +2785,7 @@ - + Implementation of updatable cursors (with parameters) #000 @@ -3223,7 +3223,7 @@ - + Implementation of updatable cursors (with parameters) #000 diff --git a/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml b/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml new file mode 100644 index 0000000..8f2ce32 --- /dev/null +++ b/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml @@ -0,0 +1,161 @@ + + + + + /usr/local + 1 + 1 + + pgsql + + /tmp/gixsql-test + + + + + + + + + + + + + + + + + /usr/local/gnucobol/bin + /usr/local/gnucobol/lib + /tmp/gnucobol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + pgsql + 5432 + testdb1 + test + test + native_cursors=off + + + localhost + pgsql + 5432 + testdb2 + test + test + native_cursors=off + + + + 192.168.1.171 + 3306 + testdb1 + test + test + + + + 192.168.1.171 + 3306 + testdb2 + test + test + + + + + 192.168.56.135 + 1521 + orcl + test1 + test1 + + + + 192.168.56.135 + 1521 + orcl + test2 + test2 + + + + + /tmp/gixsql-test/test_sqlite_1.db + + + + + + + + /tmp/gixsql-test/test_sqlite_2.db + + + + + + + + + ODBC_TEST1 + + + test + test + + + + ODBC_TEST2 + + + test + test + + + + diff --git a/libgixpp/ESQLDefinitions.h b/libgixpp/ESQLDefinitions.h index eb3cbf4..8b9ba12 100644 --- a/libgixpp/ESQLDefinitions.h +++ b/libgixpp/ESQLDefinitions.h @@ -113,7 +113,7 @@ struct esql_connection_info_t hostref_or_literal_t *data_source = nullptr; hostref_or_literal_t *username = nullptr; hostref_or_literal_t *password = nullptr; - + // for compatibility hostref_or_literal_t *dbname = nullptr; }; @@ -239,7 +239,7 @@ struct connect_to_info_t }; // This will disappear when the standalone debugger will be the only option -// For now this quick hack prevents compilation errors and having to +// For now this quick hack prevents compilation errors and having to // refactor this into an external file #ifndef _GIXPP_BLOCK_ #define _GIXPP_BLOCK_ @@ -262,7 +262,7 @@ struct PreprocessedBlockInfo { int pp_end_line = 0; int pp_gen_start_line = 0; int pp_gen_end_line = 0; - + PreprocessedBlockType type; std::string command; From ba69f4e3a8cdaa7124415a713cbf1229ee70557f Mon Sep 17 00:00:00 2001 From: Pierre Villemot Date: Fri, 11 Oct 2024 19:01:14 +0200 Subject: [PATCH 2/3] Add a script shell to run tests --- .../gixsql_test_local_ocamlpro.xml | 161 ------------------ run_test.sh | 136 +++++++++++++++ 2 files changed, 136 insertions(+), 161 deletions(-) delete mode 100644 gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml create mode 100755 run_test.sh diff --git a/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml b/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml deleted file mode 100644 index 8f2ce32..0000000 --- a/gixsql-tests-nunit/gixsql_test_local_ocamlpro.xml +++ /dev/null @@ -1,161 +0,0 @@ - - - - - /usr/local - 1 - 1 - - pgsql - - /tmp/gixsql-test - - - - - - - - - - - - - - - - - /usr/local/gnucobol/bin - /usr/local/gnucobol/lib - /tmp/gnucobol - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - pgsql - 5432 - testdb1 - test - test - native_cursors=off - - - localhost - pgsql - 5432 - testdb2 - test - test - native_cursors=off - - - - 192.168.1.171 - 3306 - testdb1 - test - test - - - - 192.168.1.171 - 3306 - testdb2 - test - test - - - - - 192.168.56.135 - 1521 - orcl - test1 - test1 - - - - 192.168.56.135 - 1521 - orcl - test2 - test2 - - - - - /tmp/gixsql-test/test_sqlite_1.db - - - - - - - - /tmp/gixsql-test/test_sqlite_2.db - - - - - - - - - ODBC_TEST1 - - - test - test - - - - ODBC_TEST2 - - - test - test - - - - diff --git a/run_test.sh b/run_test.sh new file mode 100755 index 0000000..61242a5 --- /dev/null +++ b/run_test.sh @@ -0,0 +1,136 @@ +#!/bin/env bash +set -o errexit +set -o nounset +set -o pipefail + +# Default configuration +BUILD_DIR=${BUILD_DIR:=./_build} +INSTALL_DIR=${INSTALL_DIR:=install} + +POSTGRE_HOST=${POSTGRE_HOST:=localhost} +POSTGRE_PORT=${POSTGRE_PORT:=5432} +POSTGRE_USER=${POSTGRE_USER:=test} +POSTGRE_PWD=${POSTGRE_PWD:=test} +POSTGRE_DB1=${POSTGRE_DB1:=testdb1} +POSTGRE_DB2=${POSTGRE_DB2:=testdb2} + +GNUCOBOL_DIR=${GNUCOBOL_DIR:=/usr/local/gnucobol} +TEST_VERBOSITY=${TEST_VERBOSITY:=0} +TEST_DIR=${TEST_DIR:=/tmp/gixsql-test} +GIXTEST_LOCAL_CONFIG="$TEST_DIR/config.xml" + +INSTALL_PATH="$PWD/$BUILD_DIR/$INSTALL_DIR" +LD_LIBRARY_PATH="$GNUCOBOL_DIR/lib" + +# Build and locally install the project +if [ ! -f "./extra_files.mk" ]; then + touch "extra_files.mk" +fi + +if [ ! -d "$BUILD_DIR" ]; then + mkdir "$BUILD_DIR" + echo "Create directory $BUILD_DIR" +fi + +echo "Compiling gixsql..." +cd $BUILD_DIR + +if [ ! -d "$INSTALL_DIR" ]; then + mkdir "$INSTALL_DIR" + echo "Install gixsql in $INSTALL_PATH" +fi + +../configure --prefix="$INSTALL_PATH" > /dev/null +make -j 8 > /dev/null +make install > /dev/null +cd .. + +echo "Preparing tests..." +if [ -d "$TEST_DIR" ]; then + while true; do + read -p "We need to erase the directory $TEST_DIR. Remove it? " yn + case $yn in + [Yy]* ) rm -Rf $TEST_DIR; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac + done +fi + +mkdir "$TEST_DIR" + +# Output the configuration file for the runner +cat <> $TEST_DIR/config.xml + + + + + $INSTALL_PATH + 1 + $TEST_VERBOSITY + + pgsql + + $TEST_DIR + + + + + + + + + + + + + + + + $GNUCOBOL_DIR/bin + $GNUCOBOL_DIR/lib + $GNUCOBOL_DIR/share/gnucobol/config + + + + + + + + + + + + + + + + localhost + pgsql + $POSTGRE_PORT + $POSTGRE_DB1 + $POSTGRE_USER + $POSTGRE_PWD + native_cursors=off + + + localhost + pgsql + $POSTGRE_PORT + $POSTGRE_DB2 + $POSTGRE_USER + $POSTGRE_PWD + native_cursors=off + + + +EOF + +echo "Building runner..." +# We have to rebuild the test runner because it includes test files... +dotnet build "gixsql-tests-nunit/gixsql-tests-nunit.csproj" > /dev/null + +# Start the runner +dotnet "gixsql-tests-nunit/bin/Debug/net6.0/gixsql-tests-nunit.dll" + +echo "Results of the tests can found in $TEST_DIR" From 7e2cf67902f646f4c10ddaa79a6330ef6ac59823 Mon Sep 17 00:00:00 2001 From: Pierre Villemot Date: Mon, 14 Oct 2024 16:38:12 +0200 Subject: [PATCH 3/3] Update for Nix Now the `run_test` script uses environment variables from the flake. --- flake.nix | 7 ++++++- gixsql-tests-nunit/CompilerConfig.cs | 7 +------ gixsql-tests-nunit/CompilerConfig2.cs | 10 +++------- gixsql-tests-nunit/GixSqlDynamicTestRunner.cs | 1 - run_test.sh | 11 ++++------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 1f19f07..517f42f 100644 --- a/flake.nix +++ b/flake.nix @@ -26,10 +26,15 @@ spdlog fmt postgresql + gmp ]; shellHook = '' - PATH="${pkgs.gnucobol}/bin:$PATH" + export PATH="${pkgs.gnucobol.bin}/bin:$PATH" + export LD_LIBRARY_PATH="${pkgs.gnucobol.lib}/lib:$LD_LIBRARY_PATH" + export GNUCOBOL_BIN="${pkgs.gnucobol.bin}/bin" + export GNUCOBOL_LIB="${pkgs.gnucobol.lib}/lib" + export GNUCOBOL_SHARE="${pkgs.gnucobol.bin}/share" ''; }; }; diff --git a/gixsql-tests-nunit/CompilerConfig.cs b/gixsql-tests-nunit/CompilerConfig.cs index f1f0bc7..4b40724 100644 --- a/gixsql-tests-nunit/CompilerConfig.cs +++ b/gixsql-tests-nunit/CompilerConfig.cs @@ -1,4 +1,4 @@ -//using Microsoft.VisualStudio.TestTools.UnitTesting; +//using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; using System.Xml; @@ -18,7 +18,6 @@ internal class CompilerConfig public string cobc_homedir { get; private set; } public string cobc_bin_dir_path { get; private set; } public string cobc_lib_dir_path { get; private set; } - public string cobc_config_dir_path { get; private set; } public string link_lib_dir_path { get; private set; } public string link_lib_name { get; private set; } @@ -68,10 +67,6 @@ public static CompilerConfig init(CompilerType ctype, string configuration, stri cc.cobc_lib_dir_path = cc.cobc_lib_dir_path.Replace("${homedir}", cc.cobc_homedir).Replace("${gixdata}", cc.gix_data_dir); Assert.IsTrue(Directory.Exists(cc.cobc_lib_dir_path)); - cc.cobc_config_dir_path = xp.SelectSingleNode("config_dir_path")?.InnerText; - cc.cobc_config_dir_path = cc.cobc_config_dir_path.Replace("${homedir}", cc.cobc_homedir).Replace("${gixdata}", cc.gix_data_dir); - Assert.IsTrue(Directory.Exists(cc.cobc_config_dir_path)); - cc.gix_copy_path = Path.Combine(gix_base_path, "lib", "copy"); Assert.IsTrue(Directory.Exists(cc.gix_copy_path)); Assert.IsTrue(File.Exists(Path.Combine(cc.gix_copy_path, "SQLCA.cpy"))); diff --git a/gixsql-tests-nunit/CompilerConfig2.cs b/gixsql-tests-nunit/CompilerConfig2.cs index 3596ad6..7dc3a1a 100644 --- a/gixsql-tests-nunit/CompilerConfig2.cs +++ b/gixsql-tests-nunit/CompilerConfig2.cs @@ -1,4 +1,4 @@ -//using Microsoft.VisualStudio.TestTools.UnitTesting; +//using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; using System.Xml; @@ -12,7 +12,6 @@ public class CompilerConfig2 public string cobc_bin_dir_path { get; private set; } public string cobc_lib_dir_path { get; private set; } - public string cobc_config_dir_path { get; private set; } public string gixsql_bin_path { get; private set; } public string gixsql_lib_path { get; private set; } @@ -50,9 +49,6 @@ public static CompilerConfig2 init(XmlElement xc) cc.cobc_lib_dir_path = Environment.ExpandEnvironmentVariables(xc.SelectSingleNode("lib_dir_path")?.InnerText); if (!Directory.Exists(cc.cobc_lib_dir_path)) throw new Exception(cc.cobc_lib_dir_path); - cc.cobc_config_dir_path = Environment.ExpandEnvironmentVariables(xc.SelectSingleNode("config_dir_path")?.InnerText); - if (!Directory.Exists(cc.cobc_config_dir_path)) throw new Exception(cc.cobc_config_dir_path); - if (isWindows) cc.gixsql_copy_path = Path.Combine(gix_base_path, "lib", "copy"); else @@ -61,8 +57,8 @@ public static CompilerConfig2 init(XmlElement xc) if (!Directory.Exists(cc.gixsql_copy_path)) throw new Exception(cc.gixsql_copy_path); if (!File.Exists(Path.Combine(cc.gixsql_copy_path, "SQLCA.cpy"))) throw new Exception(); - cc.gixsql_bin_path = Path.Combine(gix_base_path, "bin"); - + cc.gixsql_bin_path = Path.Combine(gix_base_path, "bin"); + cc.gixsql_lib_path = Path.Combine(gix_base_path, "lib"); if (isWindows) cc.gixsql_link_lib_dir_path = Path.Combine(cc.gixsql_lib_path, compiler_arch, compiler_type); diff --git a/gixsql-tests-nunit/GixSqlDynamicTestRunner.cs b/gixsql-tests-nunit/GixSqlDynamicTestRunner.cs index 61e456e..3a27e27 100644 --- a/gixsql-tests-nunit/GixSqlDynamicTestRunner.cs +++ b/gixsql-tests-nunit/GixSqlDynamicTestRunner.cs @@ -370,7 +370,6 @@ private void compile(GixSqlTestData td) .WithArguments(cobc_args) .WithEnvironmentVariables(new Dictionary { - ["COB_CONFIG_DIR"] = cc.cobc_config_dir_path, ["PATH"] = Environment.GetEnvironmentVariable("PATH") + $"{Path.PathSeparator}{cc.cobc_bin_dir_path}" }) .WithValidation(CommandResultValidation.None) diff --git a/run_test.sh b/run_test.sh index 61242a5..2d86ecb 100755 --- a/run_test.sh +++ b/run_test.sh @@ -14,13 +14,11 @@ POSTGRE_PWD=${POSTGRE_PWD:=test} POSTGRE_DB1=${POSTGRE_DB1:=testdb1} POSTGRE_DB2=${POSTGRE_DB2:=testdb2} -GNUCOBOL_DIR=${GNUCOBOL_DIR:=/usr/local/gnucobol} TEST_VERBOSITY=${TEST_VERBOSITY:=0} TEST_DIR=${TEST_DIR:=/tmp/gixsql-test} -GIXTEST_LOCAL_CONFIG="$TEST_DIR/config.xml" +export GIXTEST_LOCAL_CONFIG="$TEST_DIR/config.xml" INSTALL_PATH="$PWD/$BUILD_DIR/$INSTALL_DIR" -LD_LIBRARY_PATH="$GNUCOBOL_DIR/lib" # Build and locally install the project if [ ! -f "./extra_files.mk" ]; then @@ -74,7 +72,6 @@ cat <> $TEST_DIR/config.xml $TEST_DIR - @@ -87,9 +84,9 @@ cat <> $TEST_DIR/config.xml - $GNUCOBOL_DIR/bin - $GNUCOBOL_DIR/lib - $GNUCOBOL_DIR/share/gnucobol/config + $GNUCOBOL_BIN + $GNUCOBOL_LIB + $GNUCOBOL_SHARE/gnucobol/config