Revise fpp-syntax tests

This commit is contained in:
bocchino 2020-03-25 09:31:02 -07:00
parent b166e0c79f
commit ec06b24c28
23 changed files with 514 additions and 30 deletions

View File

@ -9,8 +9,8 @@ object ResolveSpecInclude extends AstTransformer {
def default(in: Unit) = ()
def transUnit(tuIn: Ast.TransUnit): Result.Result[Ast.TransUnit] = {
for { result <- transUnit((), tuIn) }
def transUnit(tu: Ast.TransUnit): Result.Result[Ast.TransUnit] = {
for { result <- transUnit((), tu) }
yield result._2
}

View File

@ -28,3 +28,9 @@ run()
fi
}
# Remove local path prefix
remove_path_prefix()
{
local_path_prefix=`cd ../../../..; echo $PWD`
sed "s;$local_path_prefix;[ local path prefix ];"
}

View File

@ -3,7 +3,7 @@
tests=`find . -name run | grep test | sed 's;^\./;;'`
for t in $tests
do
echo $t
echo "[ $t ]"
dir=`dirname $t`
base=`basename $t`
(cd $dir; ./$base)

View File

@ -1 +1,2 @@
*.out.txt
*.diff.txt

View File

@ -0,0 +1,3 @@
@ Included constant
constant x = 0
@< Included constant

View File

@ -0,0 +1,3 @@
constant x = 1
include "include-constant-2.fpp"

View File

@ -0,0 +1,9 @@
def constant
ident z
literal int 3
def constant
ident y
literal int 2
def constant
ident x
literal int 1

View File

@ -0,0 +1,3 @@
constant y = 2
include "include-constant-3.fpp"

View File

@ -0,0 +1 @@
constant z = 3

View File

@ -1,11 +1,11 @@
fpp-syntax
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-3.fpp: 1.1
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-3.fpp: 1.1
include "cycle-1.fpp"
^
included at /Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-2.fpp: 1.1
included at /Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-1.fpp: 1.1
included at [ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-2.fpp: 1.1
included at [ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-1.fpp: 1.1
error: include cycle:
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-1.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-2.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-3.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-1.fpp
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-1.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-2.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-3.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-1.fpp

View File

@ -1,11 +1,11 @@
fpp-syntax
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-1.fpp: 1.1
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-1.fpp: 1.1
include "cycle-2.fpp"
^
included at /Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-3.fpp: 1.1
included at /Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-2.fpp: 1.1
included at [ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-3.fpp: 1.1
included at [ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-2.fpp: 1.1
error: include cycle:
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-2.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-3.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-1.fpp includes
/Users/bocchino/JPL/Tools/fpp/compiler/tools/fpp-syntax/test/cycle-2.fpp
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-2.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-3.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-1.fpp includes
[ local path prefix ]/compiler/tools/fpp-syntax/test/cycle-2.fpp

View File

@ -0,0 +1,5 @@
module M {
include "constant.fpp"
}

View File

@ -0,0 +1,7 @@
def module
ident M
@ Included constant
def constant
ident x
literal int 0
@< Included constant

View File

@ -0,0 +1 @@
include "parse-error.fpp"

View File

@ -0,0 +1,6 @@
fpp-syntax
[ local path prefix ]/compiler/tools/fpp-syntax/test/parse-error.fpp: 1.1
onstant x = 1
^
included at [ local path prefix ]/compiler/tools/fpp-syntax/test/include-parse-error.fpp: 1.1
error: unexpected token

View File

@ -0,0 +1 @@
onstant x = 1

View File

@ -0,0 +1,5 @@
fpp-syntax
[ local path prefix ]/compiler/tools/fpp-syntax/test/parse-error.fpp: 1.1
onstant x = 1
^
error: unexpected token

View File

@ -4,28 +4,69 @@
fpp_syntax=../../../bin/fpp-syntax
ast_no_include()
run_test()
{
$fpp_syntax -a ast-no-include.fpp > ast-no-include.out.txt
diff -u ast-no-include.ref.txt ast-no-include.out.txt
args=$1
infile=$2
if test -n "$3"
then
outfile=$3
else
outfile=$infile
fi
$fpp_syntax $args $infile.fpp 2>&1 | remove_path_prefix > $outfile.out.txt
diff -u $outfile.ref.txt $outfile.out.txt > $outfile.diff.txt 2>&1
}
include_constant_1()
{
run_test -ia include-constant-1
}
include_cycle_1()
{
$fpp_syntax -i cycle-1.fpp > include-cycle-1.out.txt 2>&1
diff -u include-cycle-1.ref.txt include-cycle-1.out.txt
run_test -i cycle-1 include-cycle-1
}
include_cycle_2()
{
$fpp_syntax -i cycle-2.fpp > include-cycle-2.out.txt 2>&1
diff -u include-cycle-2.ref.txt include-cycle-2.out.txt
run_test -i cycle-2 include-cycle-2
}
include_parse_error()
{
run_test -i include-parse-error
}
parse_error()
{
run_test "" parse-error
}
syntax()
{
run_test "" syntax
}
syntax_ast()
{
run_test -a syntax syntax-ast
}
syntax_include_ast()
{
run_test -ia syntax syntax-include-ast
}
tests="
ast_no_include
include_constant_1
include_cycle_1
include_cycle_2
include_parse_error
parse_error
syntax
syntax_ast
syntax_include_ast
"
for t in $tests

View File

@ -151,7 +151,7 @@ def module
@< Module definition
@ Include specifier
spec include
file file.fpp
file constant.fpp
@< Include specifier
@ Init specifier
spec init

View File

@ -0,0 +1,365 @@
@ Expressions
def module
ident Expressions
@ Struct
def constant
ident structExp
expr struct
struct member
ident a
literal int 1
struct member
ident b
literal int 2
struct member
ident c
literal int 3
@< Struct
@ String literal multi
def constant
ident stringLiteralMultExp
literal string line 1
line 2
line 3
@< String literal multi
@ String literal single
def constant
ident stringLiteralSingleExp
literal string This is a string.
@< String literal single
@ Paren
def constant
ident parenExp
expr binop
expr paren
expr binop
literal int 1
binop +
literal int 2
binop *
literal int 3
@< Paren
@ Int literal
def constant
ident intLiteralExp
literal int 1234
@< Int literal
@ Identifier
def constant
ident identExp
ident x
@< Identifier
@ FP literal
def constant
ident fpLiteralExp
literal float 0.1234
@< FP literal
@ Dot
def constant
ident dotExp
expr dot
expr dot
ident a
ident b
ident c
@< Dot
@ Boolean literal
def constant
ident booleanLiteralExp
literal bool true
@< Boolean literal
@ Array
def constant
ident arrayExp
expr array
literal int 1
literal int 2
literal int 3
@< Array
@ Arithmetic
def constant
ident arithExp
expr binop
expr binop
expr binop
literal int 1
binop +
expr binop
literal int 2
binop *
literal int 3
binop -
expr binop
expr unop
unop -
literal int 4
binop *
literal int 5
binop +
literal int 6
@< Arithmetic
@< Expressions
@ Type names
def module
ident TypeNames
def array
ident typeNameQID
size literal int 10
type name qual ident a.b.c
def array
ident typeNameString
size literal int 10
type name string
def array
ident typeNameBool
size literal int 10
type name bool
def array
ident typeNameF32
size literal int 10
type name F32
def array
ident typeNameU32
size literal int 10
type name U32
@< Type names
@ Definitions and specifiers
def module
ident DefinitionsAndSpecifiers
@ Location specifier
spec loc
kind component instance
symbol qual ident i
file instances.fpp
@< Location specifier
@ Topology definition
def topology
ident T
@ Public instance specifier
spec comp instance
public
qual ident i1
@< Public instance specifier
@ Private instance specifier
spec comp instance
private
qual ident i2
@< Private instance specifier
@ Direct connection graph specifier
spec connection graph direct
ident C
connection
from port qual ident i1.p
index literal int 0
to port qual ident i2.p
index literal int 1
@< Direct connection graph specifier
@ Graph pattern specifier
spec connection graph pattern
source qual ident i1
target qual ident i2
target qual ident i3
target qual ident i4
pattern ident COMMAND
@< Graph pattern specifier
@ Topology import specifier
spec top import
qual ident T1
@< Topology import specifier
@ Unused port specifier
spec unused ports
qual ident a.p
qual ident b.p
qual ident c.p
@< Unused port specifier
@< Topology definition
@ Struct definition
def struct
ident S
@ x
struct type member
ident x
type name U32
format {} s
@< x
@ y
struct type member
ident y
type name F32
format {} m/s
@< y
@< Struct definition
@ Port definition
def port
ident P
formal param
kind value
ident a
type name U32
formal param
kind value
ident b
type name F32
return type name U32
@< Port definition
@ Init specifier
spec init
instance qual ident i
phase ident CONSTRUCTION
code line 1
line 2
line 3
@ Included constant
def constant
ident x
literal int 0
@< Included constant
@ Module definition
def module
ident M
def constant
ident x
literal int 0
@< Module definition
@ Enum definition
def enum
ident E
type name I32
@ X
def enum constant
ident X
literal int 1
@< X
@ Y
def enum constant
ident Y
literal int 2
@< Y
@< Enum definition
@ Constant definition
def constant
ident x
literal int 0
@< Constant definition
@ Component instance definition
def component instance
ident c
component qual ident C
base id literal int 0x100
queue size literal int 0x100
stack size literal int 0x100
priority literal int 0x100
@< Component instance definition
@ Component definition
def component
kind active
ident C
@ Internal port specifier
spec internal port
ident I
formal param
kind value
ident a
type name U32
formal param
kind value
ident b
type name F32
priority literal int 10
queue full assert
@< Internal port specifier
@ Event specifier
spec event
ident E
formal param
kind value
ident a
type name U32
formal param
kind value
ident b
type name F32
severity activity low
id literal int 0x00
format {} counts
throttle literal int 10
@< Event specifier
@ Telemetry channel specifier
spec tlm channel
ident T
type name U32
id literal int 0x00
update on change
format {} s
low limit
red
literal int 0
low limit
orange
literal int 1
low limit
yellow
literal int 2
high limit
yellow
literal int 10
high limit
orange
literal int 11
high limit
red
literal int 12
@< Telemetry channel specifier
@ Special port instance specifier
spec port instance special
kind command recv
ident cmdIn
@< Special port instance specifier
@ General port instance specifier
spec port instance general
kind sync input
ident p
array size literal int 10
port type qual ident P
priority literal int 10
queue full assert
@< General port instance specifier
@ Parameter specifier
spec param
ident P
type name U32
default literal int 0
id literal int 0x00
set opcode literal int 0x01
save opcode literal int 0x02
@< Parameter specifier
@ Command specifier
spec command
kind async
name ident C
formal param
kind value
ident a
type name U32
formal param
kind value
ident b
type name F32
opcode literal int 0x00
priority literal int 10
queue full assert
@< Command specifier
@< Component definition
@ Array definition
def array
ident A
size literal int 10
type name U32
default literal int 0
format {} counts
@< Array definition
@ Abstract type definition
def abs type
ident T
@< Abstract type definition
@< Definitions and specifiers

View File

@ -73,7 +73,7 @@ module DefinitionsAndSpecifiers {
@< Module definition
@ Include specifier
include "file.fpp"
include "constant.fpp"
@< Include specifier
@ Init specifier

View File

@ -1,6 +1,33 @@
#!/bin/sh
. ../../../scripts/test-utils.sh
fpp_syntax=../../../bin/fpp-syntax
$fpp_syntax -a ast-no-include.fpp > ast-no-include.ref.txt
$fpp_syntax -i cycle-1.fpp > include-cycle-1.ref.txt 2>&1
$fpp_syntax -i cycle-2.fpp > include-cycle-2.ref.txt 2>&1
update()
{
args=$1
infile=$2
if test -n "$3"
then
outfile=$3
else
outfile=$infile
fi
$fpp_syntax $args $infile.fpp 2>&1 | remove_path_prefix > $outfile.ref.txt
}
for file in `find . -name '*.ref.txt'`
do
rm $file
done
update "" parse-error
update "" syntax
update -a syntax syntax-ast
update -i cycle-1 include-cycle-1
update -i cycle-2 include-cycle-2
update -i include-parse-error
update -ia include-constant-1 include-constant-1
update -ia include-module
update -ia syntax syntax-include-ast