Skip to content

Commit

Permalink
✨ feature: implement a custom argparse with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneSemCalda committed May 24, 2024
1 parent e51e7a6 commit 9d6e735
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Go Testing

on:
push:
branches: ["master", "*"]
branches: ["third_version", "*"]
pull_request:
branches: ["master", "*"]
branches: ["third_version", "*"]

jobs:
build:
Expand All @@ -18,10 +18,10 @@ jobs:
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get dependencies
run: go get -v -t -d ./...

#- name: Test
# run: go test -v ./...
- name: Test
run: go test -v ./...
5 changes: 5 additions & 0 deletions cmd/animatic-v2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main(){
println("Hello World!")
}
19 changes: 19 additions & 0 deletions internal/argparse/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package argparse

import (
"flag"
"os"
)

/*
Parse the user input given a `flag.FlagSet` to be easy testing
*/
func ParseArgs(fs *flag.FlagSet) Args{
arguments := Args{}

fs.BoolVar(&arguments.DebugMode, "debug" , false, "this function enable debug")

fs.Parse(os.Args[1:])

return arguments
}
5 changes: 5 additions & 0 deletions internal/argparse/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package argparse

type Args struct {
DebugMode bool
}
35 changes: 35 additions & 0 deletions test/argparse/parse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package argparse_test

import (
"Animatic-v2/internal/argparse"
"flag"
"os"
"testing"

)

func TestArgparse(t *testing.T){
t.Run("Should return the struct if debug setted to false", func(t *testing.T) {
fs := flag.NewFlagSet("test", flag.ContinueOnError)

os.Args = []string{"cmd", "-debug=false"}

argv := argparse.ParseArgs(fs)

if argv.DebugMode != false {
t.Fatalf("expected %v instead %v\n", !argv.DebugMode, argv.DebugMode)
}
})

t.Run("Should return the struct if debug setted to true", func(t *testing.T) {
fs := flag.NewFlagSet("test", flag.ContinueOnError)

os.Args = []string{"cmd", "-debug"}

argv := argparse.ParseArgs(fs)

if argv.DebugMode != true {
t.Fatalf("expected %v instead %v\n", argv.DebugMode, !argv.DebugMode)
}
})
}

0 comments on commit 9d6e735

Please sign in to comment.