Enhance QueryGenerator.m to test functions in generated queries; Fix a longstanding issue in reading pastas.zwr
-
The main changes are to
QueryGenerator.m
where the generated sql queries now randomly include SQL function invocations in the WHERE clause in places where string/numeric/boolean/integer literals would have been used previously. This increases the test coverage for Octo's implementation of SQL functions.The function chosen is a simple one (
samevalue
). One that returns the single input parameter as the output parameter. Different functions are defined, one for each possible input parameter type.These function definitions are done for Octo in
tests/fixtures/QueryGenerator.sql
and for Postgres intests/fixtures/postgres-QueryGenerator.sql
.The
TCF018
bats subtest previously used a similar functiontests/fixtures/samestr.m
and that is now renamed totests/fixtures/functions.m
so the new M file can have a list of other functions too in case the need for more functions arises in the future. Thisfunctions.m
is now used by theTCF018
bats subtest as well as all subtests in thetest_query_generator
bats test. -
While doing these changes, it was noticed that in case a table has only one non-key column (e.g.
pastas
table), the logic to read the*.zwr
file (tests/fixtures/pastas.zwr
file in this case) had a bug where it used to not strip out the trailing double quote at the end of the line. For example, a line^pastas(0)="Fettucine"
would be read with thepastaName
column value beingFettucine"
. This is because the start of the column value would be marked as after the="
but the end would be marked as the$PIECE
output using|
as the delimiter. And when there is just one non-key column, there would be no|
occurrence resulting in the trailing"
at the end of the line also getting included in the column value resulting in queries incorrectly using pastaName literal values which do not correspond to actual pastaName values resulting in unintended reduction of test coverage in thepastas
table case. This is now fixed intests/fixtures/QueryGenerator.m
by first removing the trailing double quote from theline(i)
variable before trying to derive the column values. This also simplified the logic in case there were more than one non-key column. That case had logic to remove any double quote whereas it intended to only remove the trailing double quote. That potentially unsafe logic is also now removed and will let us have double quotes in the middle of column values without issues (in case such a situation arises in the future).