Improve fuzzing function
We not only want to prevent panics, we also want rendering org -> org to not change the meaning of the file. One easy way to check that (for the nodes that print to html) whether that holds is to compare the html output.
This commit is contained in:
parent
bc9c496f97
commit
854f8e181a
1 changed files with 12 additions and 5 deletions
17
org/fuzz.go
17
org/fuzz.go
|
@ -2,18 +2,25 @@
|
|||
|
||||
package org
|
||||
|
||||
import "bytes"
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Fuzz function to be used by https://github.com/dvyukov/go-fuzz
|
||||
func Fuzz(data []byte) int {
|
||||
d := NewDocument().Silent().Parse(bytes.NewReader(data))
|
||||
_, err := d.Write(NewOrgWriter())
|
||||
func Fuzz(input []byte) int {
|
||||
d := NewDocument().Silent().Parse(bytes.NewReader(input))
|
||||
orgOutput, err := d.Write(NewOrgWriter())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = d.Write(NewHTMLWriter())
|
||||
htmlOutputA, err := d.Write(NewHTMLWriter())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
htmlOutputB, err := NewDocument().Silent().Parse(strings.NewReader(orgOutput)).Write(NewHTMLWriter())
|
||||
if htmlOutputA != htmlOutputB {
|
||||
panic("rendered org results in different html than original input")
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue