mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-14 16:55:15 +01:00
ebbd4a4330
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"go/format"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestFormatting(t *testing.T) {
|
|
var wg sync.WaitGroup
|
|
filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
t.Errorf("unable to walk %s: %v", path, err)
|
|
return nil
|
|
}
|
|
if d.IsDir() || filepath.Ext(path) != ".go" {
|
|
return nil
|
|
}
|
|
wg.Add(1)
|
|
go func(path string) {
|
|
defer wg.Done()
|
|
src, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Errorf("unable to read %s: %v", path, err)
|
|
return
|
|
}
|
|
if runtime.GOOS == "windows" {
|
|
src = bytes.ReplaceAll(src, []byte{'\r', '\n'}, []byte{'\n'})
|
|
}
|
|
formatted, err := format.Source(src)
|
|
if err != nil {
|
|
t.Errorf("unable to format %s: %v", path, err)
|
|
return
|
|
}
|
|
if !bytes.Equal(src, formatted) {
|
|
t.Errorf("unformatted code: %s", path)
|
|
}
|
|
}(path)
|
|
return nil
|
|
})
|
|
wg.Wait()
|
|
}
|