From 854f8e181a3f73a019b586ead6cc84c81fbac9f6 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Thu, 20 Dec 2018 15:52:51 +0100 Subject: [PATCH] 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. --- org/fuzz.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/org/fuzz.go b/org/fuzz.go index 8fad1dc..58e0d62 100644 --- a/org/fuzz.go +++ b/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 }