compare revs (for testing)

This commit is contained in:
Egor Aristov 2025-01-27 19:21:54 +03:00
parent 728792da26
commit 036da153ba
2 changed files with 32 additions and 23 deletions

View File

@ -2,12 +2,12 @@ package main
import ( import (
"encoding/json" "encoding/json"
"flag"
"github.com/egor3f/rssalchemy/internal/config" "github.com/egor3f/rssalchemy/internal/config"
"github.com/egor3f/rssalchemy/internal/dateparser" "github.com/egor3f/rssalchemy/internal/dateparser"
"github.com/egor3f/rssalchemy/internal/extractors/pwextractor" "github.com/egor3f/rssalchemy/internal/extractors/pwextractor"
"github.com/egor3f/rssalchemy/internal/models" "github.com/egor3f/rssalchemy/internal/models"
"github.com/labstack/gommon/log" "github.com/labstack/gommon/log"
"github.com/yassinebenaid/godump"
"io" "io"
"os" "os"
"time" "time"
@ -15,16 +15,30 @@ import (
func main() { func main() {
log.SetLevel(log.DEBUG) log.SetLevel(log.DEBUG)
log.SetHeader(`${level}`) log.SetHeader(`${time_rfc3339_nano} ${level}`)
outFile := flag.String("o", "", "Output file name")
flag.Parse()
taskFileName := "task.json" taskFileName := "task.json"
if len(os.Args) > 1 { if flag.NArg() > 0 {
taskFileName = os.Args[1] taskFileName = flag.Arg(0)
}
out := os.Stdout
if len(*outFile) > 0 {
var err error
out, err = os.OpenFile(*outFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Panicf("open output file: %v", err)
}
//goland:noinspection GoUnhandledErrorResult
defer out.Close()
} }
taskFile, err := os.Open(taskFileName) taskFile, err := os.Open(taskFileName)
if err != nil { if err != nil {
log.Panicf("open file: %v", err) log.Panicf("open task file: %v", err)
} }
//goland:noinspection GoUnhandledErrorResult //goland:noinspection GoUnhandledErrorResult
defer taskFile.Close() defer taskFile.Close()
@ -74,20 +88,13 @@ func main() {
return return
} }
dumper := godump.Dumper{Theme: godump.Theme{ resultStr, err := json.MarshalIndent(result, "", "\t")
String: godump.RGB{117, 54, 217}, if err != nil {
Quotes: godump.RGB{143, 41, 0}, log.Panicf("marshal result: %v", err)
Bool: godump.RGB{6, 168, 199}, }
Number: godump.RGB{245, 77, 13}, n, err := out.Write(resultStr)
Types: godump.RGB{255, 105, 56}, if err != nil {
Address: godump.RGB{50, 162, 255}, log.Panicf("write output: %v", err)
PointerTag: godump.RGB{145, 145, 145}, }
Nil: godump.RGB{36, 198, 229}, log.Infof("Result written (%d bytes)", n)
Func: godump.RGB{95, 165, 35},
Fields: godump.RGB{66, 79, 61},
Chan: godump.RGB{60, 101, 179},
UnsafePointer: godump.RGB{166, 62, 75},
Braces: godump.RGB{70, 169, 169},
}}
_ = dumper.Println(result)
} }

View File

@ -32,14 +32,16 @@ for task in $task_dir/*; do
set +e set +e
cd $old_dir cd $old_dir
rm -f $old_dir/screenshot.png rm -f $old_dir/screenshot.png
go run github.com/egor3f/rssalchemy/cmd/extractor "$task" > $old_out 2>&1 sleep 2
go run github.com/egor3f/rssalchemy/cmd/extractor -o $old_out "$task"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Failed to run old version" echo "Failed to run old version"
cat $old_out cat $old_out
exit 1 exit 1
fi fi
cd - cd -
go run github.com/egor3f/rssalchemy/cmd/extractor "$task" > $cur_out 2>&1 sleep 2
go run github.com/egor3f/rssalchemy/cmd/extractor -o $cur_out "$task"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Failed to run new version" echo "Failed to run new version"
cat $cur_out cat $cur_out