Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a shell script to run tests #2

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
'';
};
};
Expand Down
7 changes: 1 addition & 6 deletions gixsql-tests-nunit/CompilerConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Xml;
Expand All @@ -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; }
Expand Down Expand Up @@ -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")));
Expand Down
10 changes: 3 additions & 7 deletions gixsql-tests-nunit/CompilerConfig2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Xml;
Expand All @@ -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; }
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion gixsql-tests-nunit/GixSqlDynamicTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ private void compile(GixSqlTestData td)
.WithArguments(cobc_args)
.WithEnvironmentVariables(new Dictionary<string, string>
{
["COB_CONFIG_DIR"] = cc.cobc_config_dir_path,
["PATH"] = Environment.GetEnvironmentVariable("PATH") + $"{Path.PathSeparator}{cc.cobc_bin_dir_path}"
})
.WithValidation(CommandResultValidation.None)
Expand Down
4 changes: 2 additions & 2 deletions gixsql-tests-nunit/Runner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using gixsql_tests;
using gixsql_tests;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions gixsql-tests-nunit/data/gixsql_test_data.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<test-data>

<tests>

<test name="TSQL001A" enabled="true">
<description>Open connection, cursor</description>
<issue-coverage>#000</issue-coverage>
Expand Down Expand Up @@ -234,7 +234,7 @@
<compile value="true" />
<run value="true" />

<additional-preprocess-params value="-N 2" />
<!-- <additional-preprocess-params value="-N 2" /> -->

<expected-output>
<line>employee #: [+0123]</line>
Expand Down Expand Up @@ -2293,7 +2293,7 @@
<pre-run-sql-statement data-source-index="1">CREATE TABLE TAB02 (CID INTEGER, FLD CHAR(100))</pre-run-sql-statement>
<pre-run-sql-statement data-source-index="1">CREATE TABLE TAB03 (CID INTEGER, FLD CHAR(100))</pre-run-sql-statement>
<pre-run-sql-statement data-source-index="1">CREATE TABLE TAB04 (CID INTEGER, FLD CHAR(100))</pre-run-sql-statement>

<preprocess value="true" />
<compile value="true" />
<run value="true" />
Expand Down Expand Up @@ -2785,7 +2785,7 @@
<expected-preprocessed-file-content>
</expected-preprocessed-file-content>
</test>

<test name="TSQL037B" enabled="true" applies-to="pgsql">
<description>Implementation of updatable cursors (with parameters)</description>
<issue-coverage>#000</issue-coverage>
Expand Down Expand Up @@ -3223,7 +3223,7 @@
<expected-preprocessed-file-content>
</expected-preprocessed-file-content>
</test>

<test name="TSQL038A" enabled="false">
<description>Implementation of updatable cursors (with parameters)</description>
<issue-coverage>#000</issue-coverage>
Expand Down
6 changes: 3 additions & 3 deletions libgixpp/ESQLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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_
Expand All @@ -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;
Expand Down
133 changes: 133 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/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}

TEST_VERBOSITY=${TEST_VERBOSITY:=0}
TEST_DIR=${TEST_DIR:=/tmp/gixsql-test}
export GIXTEST_LOCAL_CONFIG="$TEST_DIR/config.xml"

INSTALL_PATH="$PWD/$BUILD_DIR/$INSTALL_DIR"

# 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 <<EOF >> $TEST_DIR/config.xml
<?xml version="1.0" encoding="utf-8" ?>
<test-local-config>

<global>
<gixsql-install-base>$INSTALL_PATH</gixsql-install-base>
<keep-temps>1</keep-temps>
<verbose>$TEST_VERBOSITY</verbose>
<test-filter></test-filter>
<dbtype-filter>pgsql</dbtype-filter>
<mem-check></mem-check>
<temp-dir>$TEST_DIR</temp-dir>
<environment>
<variable key="GIXSQL_FIXUP_PARAMS" value="on" />
</environment>
</global>

<architectures>
<architecture id="x64" />
</architectures>
<compiler-types>
<compiler-type id="gcc" />
</compiler-types>

<compilers>
<compiler type="gcc" architecture="x64" id="gnucobol-3.1.2-linux-gcc-x64">
<bin_dir_path>$GNUCOBOL_BIN</bin_dir_path>
<lib_dir_path>$GNUCOBOL_LIB</lib_dir_path>
<config_dir_path>$GNUCOBOL_SHARE/gnucobol/config</config_dir_path>
<environment>
</environment>
</compiler>
</compilers>

<data-source-clients>
<data-source-client type="pgsql" architecture="x64">
<environment>
</environment>
<provider value="Npgsql" />
</data-source-client>
</data-source-clients>

<data-sources>
<data-source type="pgsql" index="1">
<hostname>localhost</hostname>
<type>pgsql</type>
<port>$POSTGRE_PORT</port>
<dbname>$POSTGRE_DB1</dbname>
<username>$POSTGRE_USER</username>
<password>$POSTGRE_PWD</password>
<options>native_cursors=off</options>
</data-source>
<data-source type="pgsql" index="2">
<hostname>localhost</hostname>
<type>pgsql</type>
<port>$POSTGRE_PORT</port>
<dbname>$POSTGRE_DB2</dbname>
<username>$POSTGRE_USER</username>
<password>$POSTGRE_PWD</password>
<options>native_cursors=off</options>
</data-source>
</data-sources>
</test-local-config>
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"