diff --git a/internal/buildfile/reader_test.go b/internal/buildfile/reader_test.go index 6654b92..6a18a9b 100644 --- a/internal/buildfile/reader_test.go +++ b/internal/buildfile/reader_test.go @@ -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 ", i) + continue + } t.Errorf("[%d] expect no error, got <%s>", i, lineerr.Err) } continue