49 lines
863 B
Bash
Executable File
49 lines
863 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# ------------------
|
|
# This is a test script that initializes a new project.
|
|
# ------------------
|
|
|
|
|
|
set -e
|
|
set -x
|
|
|
|
PS4='+(${BASH_SOURCE}:${LINENO}): '
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
# Compile `gas`
|
|
gas="/tmp/gas"
|
|
go build -o $gas ./cmd
|
|
|
|
test_project="/memory/test_gasproj"
|
|
if [[ -e $test_project ]]; then
|
|
rm -r "$test_project"
|
|
fi
|
|
|
|
$gas init "$test_project" <<EOF
|
|
mymodule
|
|
mydb.db
|
|
prog
|
|
EOF
|
|
|
|
cd $test_project
|
|
|
|
# Create a new table in the schema
|
|
cat >> pkg/db/schema.sql <<EOF
|
|
create table items (
|
|
rowid integer primary key,
|
|
description text not null default ''
|
|
);
|
|
EOF
|
|
|
|
# Generate an item model and test file
|
|
$gas generate items > pkg/db/item.go
|
|
$gas generate items --test > pkg/db/item_test.go
|
|
go mod tidy
|
|
|
|
# Run the tests
|
|
go test ./...
|
|
|
|
# Notify success in green
|
|
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"
|