// compareFile writes a sound to file, compares it to a golden file, // and fails the test if anything goes wrong. func compareFile(t *testing.T, path string, sound sounds.Sound) { f, err := ioutil.TempFile("", "tmp_") os.Remove(f.Name()) t.Logf("Writing sound to %s\n", f.Name()) if err != nil { t.Fatalf("Error creating temp file: %s\n", err) return } if err = output.WriteSoundToWav(sound, f.Name()); err != nil { t.Fatalf("Error writing to temp file: %s\n", err) return } defer os.Remove(f.Name()) bE, errE := ioutil.ReadFile(path) if errE != nil { t.Fatalf("Error reading golden file: %s\n", errE) return } bA, errA := ioutil.ReadFile(f.Name()) if errA != nil { t.Fatalf("Error reading temp file: %s\n", errA) return } if !bytes.Equal(bE, bA) { t.Fatalf("File does not match %s! Please listen to the new version.\n", path) return } }
func Write(sound s.Sound, path string) { switch { case strings.HasSuffix(path, ".flac"): panic("FLAC support currently broken, please use something else") o.WriteSoundToFlac(sound, path) case strings.HasSuffix(path, ".wav"): o.WriteSoundToWav(sound, path) default: panic("Unsupported file type: " + path) } }
func generate(path string, sound sounds.Sound) { fmt.Printf("Generating sound at %s...\n", path) if err := output.WriteSoundToWav(sound, path); err != nil { fmt.Printf(" Skipped %s, path exists. Delete to regenerate.\n", path) } }