Skip to content

Commit

Permalink
Use SQLite for testing
Browse files Browse the repository at this point in the history
It is easier to install and more widely available.
The change also more than halves the test runtime from 1:32
to 0:44.
  • Loading branch information
dspinellis committed Jul 13, 2024
1 parent e898a92 commit a2cf876
Show file tree
Hide file tree
Showing 61 changed files with 5,987 additions and 6,743 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential make perl default-jre
sudo apt-get install -y build-essential make perl sqlite3
- name: Verify installations
run: |
make --version
perl --version
java -version
sqlite3 -version
- name: Compile the project
run: make
Expand All @@ -43,13 +43,13 @@ jobs:
run: |
brew install make
brew install perl
brew install openjdk
brew install sqlite
- name: Verify installations
run: |
make --version
perl --version
java -version
sqlite3 -version
- name: Compile the project
run: make
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
btyacc
swill
hsqldb-2.4.1
hsqldb-2.4.1.zip
notes
old
13 changes: 1 addition & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#

export CSCOUT_DIR=$(shell pwd)
HSQLDB_VERSION=2.4.1
HSQLDB_URL=http://downloads.sourceforge.net/project/hsqldb/hsqldb/hsqldb_2_4/hsqldb-$(HSQLDB_VERSION).zip
DEFAULT_HSQLDB_DIR=$(CSCOUT_DIR)/hsqldb-$(HSQLDB_VERSION)/hsqldb
export HSQLDB_DIR?=$(DEFAULT_HSQLDB_DIR)

.PHONY: src/build/cscout swill/libswill.a btyacc/btyacc

Expand All @@ -43,14 +39,7 @@ btyacc/btyacc: btyacc
btyacc:
git clone https://github.com/dspinellis/btyacc

# Default installation of HSQLDB
$(DEFAULT_HSQLDB_DIR): hsqldb-$(HSQLDB_VERSION).zip
unzip $< && touch $@

hsqldb-$(HSQLDB_VERSION).zip:
wget $(HSQLDB_URL) || curl -O $(HSQLDB_URL)

test: src/build/cscout $(HSQLDB_DIR)
test: src/build/cscout
cd src && $(MAKE) test

clean:
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ CScout has been compiled and tested on GNU/Linux (Debian jessie),
Apple OS X (El Capitan), FreeBSD (11.0), and Cygwin. In order to
build and use CScout you need a Unix (like) system
with a modern C++ compiler, GNU make, and Perl.
To test CScout you also need to be able to run Java from the command line,
in order to use the HSQLDB database.
To test CScout you also need to be able to have SQLite installed.
To view CScout's diagrams you must have the
[GraphViz](http://www.graphviz.org) dot command in
your executable file path.
Expand All @@ -37,12 +36,7 @@ your executable file path.

Under FreeBSD use `gmake` rather than `make`.

Testing requires an installed version of _HSQLDB_.
If this is already installed in your system, specify to _make_
the absolute path of the *hsqldb* directory, e.g.
`make HSQLDB_DIR=/usr/local/lib/hsqldb-2.3.3/hsqldb`.
Otherwise, _make_ will automatically download and unpack a local
copy of _HSQLDB_ in the current directory.
Testing requires an installed version of _SQLite_.

## Contributing
* You can contribute to any of the [open issues](https://github.com/dspinellis/cscout/issues) or you can open a new one describing what you want to do.
Expand Down
2 changes: 1 addition & 1 deletion doc/qeg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tr -d '\n' |
sed 's/\\u0000d/\
/g'
</fmtcode>
The above script will massage the HSQLDB output removing the trailing
The above script will massage the SQLite HSQLDB output removing the trailing
<code>N rows</code> line and all existing newlines,
and changing the embedded <code>\u0000d</code> sequences into newlines.
For the Windows line-end conventions the same script would be:
Expand Down
4 changes: 2 additions & 2 deletions doc/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Have an installation of the AT&amp;T
program in the executable file path, and a Web browser supporting,
directly or via a plugin, the display of SVG (scalable vector graphics)
content.
<li> Run Java from the command line.
(This is required for running HSQLDB during testing.)
<li> Have SQLite installed.
(This is required for testing.)
</ul>

<h2>Installation and Configuration</h2>
Expand Down
5 changes: 5 additions & 0 deletions doc/sql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ allowing you to directly pipe the results into the database's
client.
For example, say the database you would want to create for your project
was called <code>myproj</code>.<br />
For SQLite you would write:
<fmtcode ext="sh">
rm -f myproj.db
cscout -s sqlite myproj.cs | sqlite3 myproj.db
</fmtcode>
For MySQL you would write:
<fmtcode ext="sh">
(
Expand Down
93 changes: 43 additions & 50 deletions src/runtest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# (C) Copyright 2001-2019 Diomidis Spinellis
# (C) Copyright 2001-2024 Diomidis Spinellis
#
# This file is part of CScout.
#
Expand Down Expand Up @@ -50,14 +50,6 @@ if ! [ "$CSCOUT_DIR" ] ; then
fi
fi

if ! [ "$HSQLDB_DIR" ] ; then
HSQLDB_DIR=$(echo $CSCOUT_DIR/hsqldb-*/hsqldb)
if ! [ -r "$HSQLDB_DIR/lib/sqltool.jar" ] ; then
echo "Bail out! Unable to find lib/sqltool.jar under $HSQLDB_DIR."
exit 1
fi
fi

# Start a test (arguments directory, name)
start_test()
{
Expand All @@ -81,11 +73,11 @@ end_compare()
fi
mkdir -p test/err/diff
if { test -r test/out/$NAME.err &&
diff -ib test/out/$NAME.out test/nout/$NAME.out >test/err/diff/$NAME &&
diff -iw test/out/$NAME.out test/nout/$NAME.out >test/err/diff/$NAME &&
sed "s|[^ ]*$(/bin/pwd)||" test/nout/$NAME.err |
diff -ib test/out/$NAME.err - >>test/err/diff/$NAME ; } ||
diff -iw test/out/$NAME.err - >>test/err/diff/$NAME ; } ||
{ test -r test/out/$NAME &&
diff -ib test/out/$NAME test/nout/$NAME >test/err/diff/$NAME ; }
diff -iw test/out/$NAME test/nout/$NAME >test/err/diff/$NAME ; }
then
end_test $2 1
else
Expand Down Expand Up @@ -125,12 +117,17 @@ runtest_c()
start_test $DIR $NAME
mkdir -p test/err/chunk
(
echo '\p Loading database'
(cd $DIR ; $SRCPATH/$CSCOUT -s hsqldb $CSFILE) 2>test/err/chunk/$NAME.cs
echo '.print "Loading database"'
(cd $DIR ; $SRCPATH/$CSCOUT -s sqlite $CSFILE) 2>test/err/chunk/$NAME.cs
cat <<\EOF
\p Fixing EIDs
PRAGMA synchronous = OFF;
PRAGMA journal_mode = OFF;
PRAGMA locking_mode = EXCLUSIVE;
.separator "\t"
.headers on
SET DATABASE REFERENTIAL INTEGRITY FALSE;
.print "Fixing EIDs"
CREATE TABLE FixedIds(EID BIGINT primary key, fixedid integer);
Expand Down Expand Up @@ -163,7 +160,7 @@ UPDATE IdProj SET Eid=(SELECT FixedId FROM FixedIds WHERE FixedIds.Eid = IdProj.
UPDATE FunctionId SET Eid=(SELECT FixedId FROM FixedIds WHERE FixedIds.Eid = FunctionId.Eid);
DROP TABLE FixedIds;
\p Fixing FUNCTION IDs
.print "Fixing FUNCTION IDs"
CREATE TABLE FixedIds(FunId BIGINT primary key, FixedId integer);
INSERT INTO FixedIds
Expand All @@ -184,50 +181,52 @@ DestId=(SELECT FixedId FROM FixedIds WHERE FixedIds.FunId = Fcalls.DestId);
DROP TABLE FixedIds;
SET DATABASE REFERENTIAL INTEGRITY TRUE;
\p Running selections
\p Table: Ids
.print "Running selections"
.print "Table: Ids"
SELECT * from Ids WHERE Name != 'PRJ2' ORDER BY Eid;
\p Table: Tokens
.print "Table: Tokens"
SELECT * from Tokens WHERE Fid != 1 ORDER BY Fid, Foffset;
\p Table: Rest
.print "Table: Rest"
SELECT * from Rest WHERE Fid != 1 ORDER BY Fid, Foffset;
\p Table: Projects
.print "Table: Projects"
SELECT * from Projects ORDER BY Pid;
\p Table: IdProj
.print "Table: IdProj"
-- All identifiers but PRJ2, which is at variable offsets and hence EIDs
SELECT DISTINCT IdProj.* FROM (
IdProj LEFT OUTER JOIN (SELECT Eid from Ids WHERE Name = 'PRJ2') X
on IdProj.Eid = X.Eid) WHERE X.Eid IS NULL
ORDER BY IdProj.Pid, IdProj.Eid;
\p Table: Files
SELECT FID, REGEXP_SUBSTRING(NAME, '[^/]*$') as NAME,
RO, NCHAR, NCCOMMENT, NSPACE, NLCOMMENT, NBCOMMENT, NLINE, MAXLINELEN, NSTRING, NULINE, NPPDIRECTIVE, NPPCOND, NPPFMACRO, NPPOMACRO, NPPTOKEN, NCTOKEN, NCOPIES, NSTATEMENT, NPFUNCTION, NFFUNCTION, NPVAR, NFVAR, NAGGREGATE, NAMEMBER, NENUM, NEMEMBER, NINCFILE
.print "Table: Files"
SELECT FID,
-- HSQLDB:
-- REGEXP_SUBSTRING(NAME, '[^/]*$') as NAME,
-- SQLite: (see https://stackoverflow.com/a/38330814/20520)
Replace(name, rtrim(name, replace(name, '/', '')), '') AS NAME,
RO, NCHAR, NCCOMMENT, NSPACE, NLCOMMENT, NBCOMMENT, NLINE, MAXLINELEN, NSTRING, NULINE, NPPDIRECTIVE, NPPCOND, NPPFMACRO, NPPOMACRO, NPPTOKEN, NCTOKEN, NCOPIES, NSTATEMENT, NPFUNCTION, NFFUNCTION, NPVAR, NFVAR, NAGGREGATE, NAMEMBER, NENUM, NEMEMBER, NINCFILE
from Files WHERE Fid != 1 ORDER BY Fid;
\p Table: FileProj
.print "Table: FileProj"
SELECT * from FileProj ORDER BY Pid, Fid;
\p Table: Definers
.print "Table: Definers"
SELECT * from Definers ORDER BY PID, CUID, BASEFILEID, DEFINERID;
\p Table: Includers
.print "Table: Includers"
SELECT * from Includers ORDER BY PID, CUID, BASEFILEID, IncluderID;
\p Table: Providers
.print "Table: Providers"
SELECT * from Providers ORDER BY PID, CUID, Providerid;
\p Table: IncTriggers
.print "Table: IncTriggers"
SELECT * from IncTriggers WHERE Definerid != 1
ORDER BY PID, CUID, Basefileid, Definerid, FOffset;
\p Table: Functions
.print "Table: Functions"
SELECT * from Functions ORDER BY ID;
\p Table: FunctionMetrics
.print "Table: FunctionMetrics"
SELECT * from FunctionMetrics ORDER BY FUNCTIONID;
\p Table: FunctionId
.print "Table: FunctionId"
SELECT * from FunctionId ORDER BY FUNCTIONID, ORDINAL;
\p Table: Fcalls
.print "Table: Fcalls"
SELECT * from Fcalls ORDER BY SourceID, DESTID;
\p Done
.print "Done"
EOF
) |
$HSQLDB mem - |
sqlite3 |
sed -e '1,/^Running selections/d' >test/nout/$NAME
end_compare $DIR $NAME
}
Expand All @@ -242,11 +241,12 @@ runtest_chunk()
start_test $DIR "chunk $NAME"
mkdir -p test/chunk
(
echo '\p Loading database'
echo '.print "Loading database"'
mkdir -p test/err/chunk
(cd $DIR ; $CSCOUT -s hsqldb $CSFILE) 2>test/err/chunk/$NAME.cs
(cd $DIR ; $CSCOUT -s sqlite $CSFILE) 2>test/err/chunk/$NAME.cs
echo '
\p Starting dump
.print "Starting dump"
select s from
(select name as s, foffset from ids inner join tokens on
ids.eid = tokens.eid where fid = 4
Expand All @@ -257,7 +257,7 @@ union select string as s, foffset from strings where fid = 4
order by foffset;
'
) |
$HSQLDB mem - |
sqlite3 |
sed -e '1,/^Starting dump/d;/^[0-9][0-9]* rows/d' |
tr -d "\n\r" |
perl -pe 's/\\u0000d\\u0000a/\n/g;s/\\u0000a/\n/g' >test/chunk/$NAME
Expand Down Expand Up @@ -373,13 +373,6 @@ done

CSCOUT=$(dirname $0)/build/cscout

# Adjust HSQLDB_DIR for native Windows Java
if cygpath -a / >/dev/null 2>&1 &&
! java -jar $HSQLDB_DIR/lib/sqltool.jar </dev/null >/dev/null 2>&1; then
HSQLDB_DIR=$(cygpath -w $HSQLDB_DIR)
fi

HSQLDB="java -jar $HSQLDB_DIR/lib/sqltool.jar --rcfile $HSQLDB_DIR/sample/sqltool.rc"
IPATH=$CSCOUT_DIR/include/stdc
CPPTESTS=$CSCOUT_DIR/src/test/cpp
DOTCSCOUT=$CSCOUT_DIR/example/.cscout
Expand Down
15 changes: 15 additions & 0 deletions src/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ Hsqldb::escape(char c)
}
}

const char *
Sqlite::escape(char c)
{
static char str[2];

switch (c) {
case '\'': return "''";
case '\n': return "\\u0000a";
case '\r': return "\\u0000d";
default:
str[0] = c;
return str;
}
}

string
Sql::escape(string s)
{
Expand Down
1 change: 1 addition & 0 deletions src/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Postgres: public Sql {
class Sqlite: public Sql {
public:
const char *begin_commands();
const char * escape(char c);
};


Expand Down
Loading

0 comments on commit a2cf876

Please sign in to comment.