diff --git a/modules/compiler_V2/data/OS.go b/modules/compiler_V2/data/OS.go index b1f2338c5f9b4f3821bb76c14ad8bafca33259eb..ee712afa2147823e95aab4c403b526034729d08a 100644 --- a/modules/compiler_V2/data/OS.go +++ b/modules/compiler_V2/data/OS.go @@ -1,6 +1,6 @@ package data -type OS string +type OS = string const ( Windows OS = "windows" diff --git a/modules/compiler_V2/go-compiler2/go_compiler.go b/modules/compiler_V2/go-compiler2/go_compiler.go index ead1ae18f53b4db9f9bac06e62503e81bb994078..2e70452e15f2c0f929f77770f7bbb4faec0b7b32 100644 --- a/modules/compiler_V2/go-compiler2/go_compiler.go +++ b/modules/compiler_V2/go-compiler2/go_compiler.go @@ -2,23 +2,16 @@ package go_compiler2 import ( "compiler_V2/consts" - "compiler_V2/data" "compiler_V2/utils" "os" ) const fileName = "main.go" -type GoCompiler struct { - OS data.OS - Language data.Language -} +type GoCompiler struct{} -func NewGoCompiler(OS data.OS) *GoCompiler { - return &GoCompiler{ - OS: OS, - Language: data.Go, - } +func NewGoCompiler() *GoCompiler { + return &GoCompiler{} } func (gb *GoCompiler) CheckCompileErrors(srcCode []byte) ([]byte, error) { @@ -38,7 +31,7 @@ func (gb *GoCompiler) CheckCompileErrors(srcCode []byte) ([]byte, error) { cmdString += " && go build -o main " + fileName //cmdSlice := strings.Fields(cmdString) - cmd := utils.MakeCommand(gb.OS, cmdString) + cmd := utils.MakeCommand(cmdString) cmd.Dir = consts.TempOutputDir return cmd.CombinedOutput() } diff --git a/modules/compiler_V2/go-compiler2/go_compiler_test.go b/modules/compiler_V2/go-compiler2/go_compiler_test.go index ab38ecc663ba2c6610ce9e66277fdf99380e2b25..16b9dc5defb947d6b8d67304c45005311761b0a6 100644 --- a/modules/compiler_V2/go-compiler2/go_compiler_test.go +++ b/modules/compiler_V2/go-compiler2/go_compiler_test.go @@ -1,7 +1,6 @@ package go_compiler2 import ( - "compiler_V2/data" "os" "testing" ) @@ -35,7 +34,7 @@ func TestCompileStringToGo(t *testing.T) { // Read the code from the file code, err := os.ReadFile(test.filename) - output, err := NewGoCompiler(data.Windows).CheckCompileErrors(code) + output, err := NewGoCompiler().CheckCompileErrors(code) if err != nil && test.shouldCompile { t.Errorf("Expected the code to compile, but got an output: %v \n error: %v", string(output), err) diff --git a/modules/compiler_V2/rust-compiler2/rust_compiler.go b/modules/compiler_V2/rust-compiler2/rust_compiler.go index 52f18b4999ce26942d4d5279e9f18f2f313808a4..0f92af645e6027b0e1c494a336617e5cacda06b4 100644 --- a/modules/compiler_V2/rust-compiler2/rust_compiler.go +++ b/modules/compiler_V2/rust-compiler2/rust_compiler.go @@ -2,7 +2,6 @@ package rust_compiler2 import ( "compiler_V2/consts" - "compiler_V2/data" "compiler_V2/utils" "os" "strings" @@ -10,16 +9,10 @@ import ( const fileName = "main.rs" -type RustCompiler struct { - OS data.OS - Language data.Language -} +type RustCompiler struct{} -func NewRustCompiler(OS data.OS) *RustCompiler { - return &RustCompiler{ - OS: OS, - Language: data.Rust, - } +func NewRustCompiler() *RustCompiler { + return &RustCompiler{} } func (gb *RustCompiler) CheckCompileErrors(srcCode []byte, dependencies ...string) ([]byte, error) { @@ -28,7 +21,7 @@ func (gb *RustCompiler) CheckCompileErrors(srcCode []byte, dependencies ...strin defer utils.RemoveTempFolders(consts.TempOutputDir) // Init cargo - if err := initCargo(gb.OS); err != nil { + if err := initCargo(); err != nil { return nil, err } @@ -47,14 +40,14 @@ func (gb *RustCompiler) CheckCompileErrors(srcCode []byte, dependencies ...strin cmdString += " cargo check" //cmdSlice := strings.Fields(cmdString) - cmd := utils.MakeCommand(gb.OS, cmdString) + cmd := utils.MakeCommand(cmdString) cmd.Dir = consts.TempOutputDir return cmd.CombinedOutput() } -func initCargo(OS data.OS) error { +func initCargo() error { // Init cargo - cmd := utils.MakeCommand(OS, "cargo init --bin") + cmd := utils.MakeCommand("cargo init --bin") cmd.Dir = consts.TempOutputDir return cmd.Run() } diff --git a/modules/compiler_V2/rust-compiler2/rust_compiler_test.go b/modules/compiler_V2/rust-compiler2/rust_compiler_test.go index 87533db8b1afc9b08692d11eadae8d244ede247a..6fc5cda265eadbd04425dcec48f9b71cf2445c62 100644 --- a/modules/compiler_V2/rust-compiler2/rust_compiler_test.go +++ b/modules/compiler_V2/rust-compiler2/rust_compiler_test.go @@ -1,7 +1,6 @@ package rust_compiler2 import ( - "compiler_V2/data" "os" "testing" ) @@ -35,7 +34,7 @@ func TestCompileStringToRust(t *testing.T) { // Read the code from the file code, err := os.ReadFile(test.filename) - output, err := NewRustCompiler(data.Windows).CheckCompileErrors(code, test.dependencies...) + output, err := NewRustCompiler().CheckCompileErrors(code, test.dependencies...) if err != nil && test.shouldCompile { t.Errorf("Expected the code to compile, but got an output: %v \n error: %v", string(output), err) diff --git a/modules/compiler_V2/utils/make_command.go b/modules/compiler_V2/utils/make_command.go index cffa76c6501efc965d13d64e3ecb7b492080939f..83f0deddfc5c563b12a3e970b82e49fa66ffef8e 100644 --- a/modules/compiler_V2/utils/make_command.go +++ b/modules/compiler_V2/utils/make_command.go @@ -3,9 +3,12 @@ package utils import ( "compiler_V2/data" "os/exec" + "runtime" ) -func MakeCommand(OS data.OS, cmd string) *exec.Cmd { +// MakeCommand creates a command based on the runtime OS +func MakeCommand(cmd string) *exec.Cmd { + OS := runtime.GOOS switch OS { case data.Windows: return exec.Command("cmd", "/c", cmd)