Skip to content

Commit

Permalink
feat: add -system flag to ls tests for optional system ls usage
Browse files Browse the repository at this point in the history
This commit introduces a new command-line flag, -system, to the ls test suite, allowing users to opt for the system 'ls' command instead of the custom implementation. The tests are updated to skip execution when the system flag is used, ensuring compatibility and flexibility in testing scenarios.
  • Loading branch information
ryan-gang committed Jan 8, 2025
1 parent e327409 commit 339bf9d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/custom_executable/ls/ls_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -11,6 +12,10 @@ import (
"testing"
)

// Pass the -system flag to use system ls instead of custom implementation
// go test ./... -system
var useSystemLs = flag.Bool("system", false, "Use system ls instead of custom implementation")

// testFile represents a file or directory to be created for testing
type testFile struct {
name string
Expand All @@ -37,6 +42,10 @@ func createTestFiles(t *testing.T, dir string, files []testFile) {
}

func getLsExecutable(t *testing.T) string {
if *useSystemLs {
return "ls"
}

switch runtime.GOOS {
case "darwin":
switch runtime.GOARCH {
Expand Down Expand Up @@ -301,6 +310,9 @@ func TestLsWithDashOneFlag(t *testing.T) {
}

func TestLsWithUnsupportedFlag(t *testing.T) {
if *useSystemLs {
t.Skip("Skipping test because system ls is used")
}
// Create a temporary directory for testing
tmpDir, err := os.MkdirTemp("", "ls-test-*")
if err != nil {
Expand All @@ -323,6 +335,10 @@ func TestLsWithUnsupportedFlag(t *testing.T) {
}

func TestLsWithUnsupportedFlag2(t *testing.T) {
if *useSystemLs {
t.Skip("Skipping test because system ls is used")
}

// Run ls and get output
output, err := runLs(t, "-n")
if err == nil {
Expand All @@ -339,6 +355,10 @@ func TestLsWithUnsupportedFlag2(t *testing.T) {
}

func TestLsWithUnsupportedFlag3(t *testing.T) {
if *useSystemLs {
t.Skip("Skipping test because system ls is used")
}

// Run ls and get output
output, err := runLs(t, "-l -a")
if err == nil {
Expand Down

0 comments on commit 339bf9d

Please sign in to comment.