fix tests

This commit is contained in:
Adrien Marquès 2018-11-14 11:38:21 +01:00
parent a6207e0a34
commit 2f95acb851
1 changed files with 21 additions and 17 deletions

View File

@ -15,7 +15,7 @@ func TestNullContext(t *testing.T) {
}
func TestIgnoreCommentsAndEmptyLines(t *testing.T) {
ctx, _ := instruction.CreateContext("apt-get", "")
buffer := bytes.NewBufferString("[ some comment ]\n\n \t \n\t \t\n[ other comment after empty lines ]")
buffer := bytes.NewBufferString("# some comment\n;other comment\n \t \n\t \t\n; other comment after empty lines")
r, err := NewReader(ctx, buffer)
if err != nil {
@ -33,24 +33,24 @@ func TestInstructionSyntax(t *testing.T) {
Line int
Err error
}{
{"install args\ndelete args\n", 0, nil},
{" install args\ndelete args\n", 0, nil},
{"\tinstall args\ndelete args\n", 0, nil},
{" \t install args\ndelete args\n", 0, nil},
{" \t install args\ndelete args\n", 0, nil},
{"[pre]\ninstall args\ndelete args\n", 1, nil},
{"[pre]\n install args\ndelete args\n", 1, nil},
{"[pre]\n\tinstall args\ndelete args\n", 1, nil},
{"[pre]\n \t install args\ndelete args\n", 1, nil},
{"[pre]\n \t install args\ndelete args\n", 1, nil},
{"cmd args\ncmd args\n", 1, instruction.ErrUnknownInstruction},
{"install args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{" cmd args\ncmd args\n", 1, instruction.ErrUnknownInstruction},
{"\tcmd args\ncmd args\n", 1, instruction.ErrUnknownInstruction},
{" \t cmd args\ncmd args\n", 1, instruction.ErrUnknownInstruction},
{" \t cmd args\ncmd args\n", 1, instruction.ErrUnknownInstruction},
{"[pre]\ncmd args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{"[pre]\ninstall args\ncmd args\n", 3, instruction.ErrUnknownInstruction},
{"[pre]\n cmd args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{"[pre]\n\tcmd args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{"[pre]\n \t cmd args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{"[pre]\n \t cmd args\ncmd args\n", 2, instruction.ErrUnknownInstruction},
{"cmd args\ncmd\n", 1, instruction.ErrUnknownInstruction},
{"install\ncmd args\n", 1, instruction.ErrInvalidSyntax},
{"[pre]\ncmd args\ncmd\n", 2, instruction.ErrUnknownInstruction},
{"[pre]\ninstall\ncmd args\n", 2, instruction.ErrInvalidSyntax},
{"install args\n cmd args\n", 2, instruction.ErrUnknownInstruction},
{"install args\ncmd\n", 2, instruction.ErrInvalidSyntax},
{"[pre]\ninstall args\n cmd args\n", 3, instruction.ErrUnknownInstruction},
{"[pre]\ninstall args\ncmd\n", 3, instruction.ErrInvalidSyntax},
}
ctx, _ := instruction.CreateContext("apt-get", "")
@ -64,7 +64,11 @@ func TestInstructionSyntax(t *testing.T) {
// no error expected
if test.Err == nil {
if err != nil {
lineerr := err.(LineError)
lineerr, ok := err.(LineError)
if !ok {
t.Errorf("[%d] expect error to be of type <LineError>", i)
continue
}
t.Errorf("[%d] expect no error, got <%s>", i, lineerr.Err)
}
continue