Skip to content

Commit

Permalink
Fix testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
TrafeX committed Sep 28, 2024
1 parent 375be3b commit 243ac5b
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
package main

import (
"flag"
"os"
"testing"
)

func TestBasicWorking(t *testing.T) {
os.Args = []string{"./videotranscoder", "-help"}
main()
func TestParseCliArguments(t *testing.T) {
// Save original command-line arguments and defer their restoration
oldArgs := os.Args
defer func() { os.Args = oldArgs }()

// Simulate command-line arguments
os.Args = []string{"cmd", "-source", "/some/source", "-target", "/some/target"}
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) // Reset flags

// Run the function and recover from os.Exit
exitCode := runTestWithoutExit(t, func() {
parseCliArguments() // You can call main() here if needed.
})

if exitCode != 0 {
t.Errorf("Unexpected exit code: %d", exitCode)
}
}

func runTestWithoutExit(t *testing.T, f func()) (exitCode int) {
// Capture calls to os.Exit
defer func() {
if r := recover(); r != nil {
if code, ok := r.(int); ok {
exitCode = code
} else {
t.Errorf("Unexpected panic: %v", r)
}
}
}()

// Run the function that might call os.Exit()
f()

return 0 // No exit, return 0 as the default "exit code"
}

0 comments on commit 243ac5b

Please sign in to comment.