diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e75e36e..dd368e0 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -22,8 +22,6 @@ archives: 386: i386 amd64: x86_64 format: binary - builds_info: - mode: 0777 checksum: name_template: 'checksums.txt' snapshot: diff --git a/cmd/scatr/version.go b/cmd/scatr/version.go index a365af4..9379e43 100644 --- a/cmd/scatr/version.go +++ b/cmd/scatr/version.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -const version = "0.3.3" +const version = "0.3.4" var versionCmd = &cobra.Command{ Use: "version", diff --git a/runner/run.go b/runner/run.go index 0aa80f6..cd4304e 100644 --- a/runner/run.go +++ b/runner/run.go @@ -2,6 +2,7 @@ package runner import ( "errors" + "fmt" "log" "os" "os/exec" @@ -100,6 +101,37 @@ func testAutofix( return nil, nil, false, err } + diff, identical, passed, err := runAutofixTests(config, autofixDir, backup) + if err != nil { + log.Println("Autofix run error:", err) + restoreErr := restoreBackup(backup) + if restoreErr != nil { + return nil, nil, false, + fmt.Errorf("autofix err: %s, restore err: %s", err.Error(), restoreErr.Error()) + } + + return nil, nil, false, err + } + + return diff, identical, passed, restoreBackup(backup) +} + +func restoreBackup(backup *AutofixBackup) error { + log.Println("Restoring the Autofix backup") + err := backup.RestoreAndDestroy() + if err != nil { + log.Println("Unable to restore Autofix backup, err:", err) + return err + } + + return nil +} + +func runAutofixTests( + config *Config, + autofixDir string, + backup *AutofixBackup, +) (autofixDiff, identicalGoldenFiles, bool, error) { log.Println("Checking for identical original and golden files") identical, passed, err := checkIdenticalGoldenFile(config.CodePath, config.ExcludedDirs, backup) if err != nil { diff --git a/runner/testdata/autofix/go_failing_code_path/main.go b/runner/testdata/autofix/go_failing_code_path/main.go new file mode 100644 index 0000000..6d9f2ea --- /dev/null +++ b/runner/testdata/autofix/go_failing_code_path/main.go @@ -0,0 +1,17 @@ +package code + +var foo int = 10 + +func bar() { + a := 10 + a = a +} + +func baz() { + a := 10 + a = a +} + +func lorem() { + _ = 10 +} diff --git a/runner/testdata/autofix/go_restore/.scatr.toml b/runner/testdata/autofix/go_restore/.scatr.toml new file mode 100644 index 0000000..6013cfc --- /dev/null +++ b/runner/testdata/autofix/go_restore/.scatr.toml @@ -0,0 +1,16 @@ +files = "*.go" +comment_prefix = ["//"] + +[autofix] +script = """ +cat main.go.golden > main.go +exit 0 +""" +interpreter = "sh" +output_file = "analysis_result.json" + +[processor] +skip_processing = false +script = """ +cat $INPUT_FILE +""" diff --git a/runner/testdata/autofix/go_restore/files.json b/runner/testdata/autofix/go_restore/files.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/runner/testdata/autofix/go_restore/files.json @@ -0,0 +1 @@ +[] diff --git a/runner/testdata/autofix/go_restore/files_failing.json b/runner/testdata/autofix/go_restore/files_failing.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/runner/testdata/autofix/go_restore/files_failing.json @@ -0,0 +1 @@ +[] diff --git a/runner/testdata/autofix/go_restore/files_identical.json b/runner/testdata/autofix/go_restore/files_identical.json new file mode 100644 index 0000000..c3e5bd0 --- /dev/null +++ b/runner/testdata/autofix/go_restore/files_identical.json @@ -0,0 +1 @@ +["main.go"] \ No newline at end of file diff --git a/runner/testdata/autofix/go_restore/go.mod b/runner/testdata/autofix/go_restore/go.mod new file mode 100644 index 0000000..e36d28f --- /dev/null +++ b/runner/testdata/autofix/go_restore/go.mod @@ -0,0 +1,3 @@ +module github.com/deepsourcelabs/SCATR/testdata/autofix/go_restore + +go 1.19 diff --git a/runner/testdata/autofix/go_restore/main.go b/runner/testdata/autofix/go_restore/main.go new file mode 100644 index 0000000..269429e --- /dev/null +++ b/runner/testdata/autofix/go_restore/main.go @@ -0,0 +1,18 @@ +package main + +var foo int = 10 + +func bar() { + a := 10 + a = a +} + +func baz() { + a := 10 + a = a +} + +func lorem() { + a := 10 + a = a +} diff --git a/runner/testdata/autofix/go_restore/main.go.golden b/runner/testdata/autofix/go_restore/main.go.golden new file mode 100644 index 0000000..57dd105 --- /dev/null +++ b/runner/testdata/autofix/go_restore/main.go.golden @@ -0,0 +1,16 @@ +package main + +func bar() { + a := 10 + a = a +} + +func baz() { + a := 10 + a = a +} + +func lorem() { + a := 10 + a = a +}