Skip to content

Commit

Permalink
exec cmd in build folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lovestaco committed Jul 20, 2023
1 parent 73e12d9 commit 39d0b7d
Showing 1 changed file with 49 additions and 27 deletions.
76 changes: 49 additions & 27 deletions tests/env_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,58 @@ type EnvData struct {
}

func runL2CommandAndParseJSON(t *testing.T, cmdArgs ...string) {
// Store the original working directory
originalPath, err := os.Getwd()
if err != nil {
fmt.Println("Error getting the current working directory:", err)
return
}

// Store the current working directory
originalPath, err := os.Getwd()
if err != nil {
fmt.Println("Error getting the current working directory:", err)
return
}
listFilesInDir(originalPath)

// Change the current working directory to lama2Path
l2BinPath := "/home/runner/work/Lama2/Lama2"
err = os.Chdir(l2BinPath)
if err != nil {
fmt.Println("Error changing the current working directory:", err)
return
}

listFilesInDir(l2BinPath)

cmd := exec.Command("./../build/l2", cmdArgs...) // Use "./l2" as the executable name

var stdout bytes.Buffer
cmd.Stdout = &stdout

// Execute the command
err = cmd.Run() // Uncomment this line to execute the "l2" command
// Change the current working directory to lama2Path
l2BinPath := "/home/runner/work/Lama2/Lama2/build"
err = os.Chdir(l2BinPath)
if err != nil {
fmt.Println("Error changing the current working directory:", err)
return
}

// Print the current working directory to verify
wd, err := os.Getwd()
if err != nil {
fmt.Println("Error getting the current working directory:", err)
return
}
fmt.Println("Current working directory after changing:", wd)

// Now let's check if the l2 binary is present in the current working directory
fileInfo, err := os.Stat("./l2")
if err != nil {
fmt.Println("Error checking l2 binary:", err)
return
}
fmt.Println("Is l2 binary present:", fileInfo.Mode().IsRegular())

// Change back to the original working directory after debugging
defer func() {
err := os.Chdir(originalPath)
if err != nil {
// Handle the error if needed
fmt.Printf("Error running l2 command: %v\n", err)
fmt.Println("Error changing back to the original working directory:", err)
}
}()

// Your existing code to run the l2 command and parse JSON
cmd := exec.Command("./l2", cmdArgs...) // Use "./l2" as the executable name

var stdout bytes.Buffer
cmd.Stdout = &stdout

// Execute the command
err = cmd.Run() // Uncomment this line to execute the "l2" command
if err != nil {
// Handle the error if needed
fmt.Printf("Error running l2 command: %v\n", err)
return
}

// Retrieve the captured stdout
stdoutOutput := stdout.String()
Expand Down

0 comments on commit 39d0b7d

Please sign in to comment.