aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--exercises/if/if1/main_test.go25
-rw-r--r--golings/cmd/run.go3
-rw-r--r--golings/cmd/verify.go3
-rw-r--r--golings/exercises/runner.go15
-rw-r--r--info.toml7
5 files changed, 50 insertions, 3 deletions
diff --git a/exercises/if/if1/main_test.go b/exercises/if/if1/main_test.go
new file mode 100644
index 0000000..589cf7f
--- /dev/null
+++ b/exercises/if/if1/main_test.go
@@ -0,0 +1,25 @@
+// if1
+// Make me compile!
+
+// I AM NOT DONE
+package main_test
+
+import "testing"
+
+func bigger(a int, b int) int {
+ // Complete this function to return the bigger number
+ // Use only if statements
+ return 0
+}
+
+func TestTwoIsBiggerThanOne(t *testing.T) {
+ if bigger(2, 1) != 2 {
+ t.Errorf("2 is bigger than 1")
+ }
+}
+
+func TestTenIsBiggerThanFive(t *testing.T) {
+ if bigger(5, 10) != 10 {
+ t.Errorf("10 is bigger than 5")
+ }
+}
diff --git a/golings/cmd/run.go b/golings/cmd/run.go
index 21204c9..ad61793 100644
--- a/golings/cmd/run.go
+++ b/golings/cmd/run.go
@@ -20,8 +20,9 @@ var cmdRun = &cobra.Command{
result, err := exercises.Run(args[0])
if err != nil {
color.Cyan("Failed to compile the exercise %s\n\n", result.Exercise.Path)
- color.White("Check the error below: \n\n")
+ color.White("Check the output below: \n\n")
color.Red(result.Err)
+ color.Red(result.Out)
color.Yellow("If you feel stuck, ask a hint by executing `golings hint %s`", result.Exercise.Name)
os.Exit(1)
} else {
diff --git a/golings/cmd/verify.go b/golings/cmd/verify.go
index fc419c3..9f8d415 100644
--- a/golings/cmd/verify.go
+++ b/golings/cmd/verify.go
@@ -48,8 +48,9 @@ var cmdVerify = &cobra.Command{
if result.Err != "" {
fmt.Print("\n\n")
color.Cyan("Failed to compile the exercise %s\n\n", e.Path)
- color.White("Check the error below: \n\n")
+ color.White("Check the output below: \n\n")
color.Red(result.Err)
+ color.Red(result.Out)
os.Exit(1)
}
}
diff --git a/golings/exercises/runner.go b/golings/exercises/runner.go
index d034093..63ae6d3 100644
--- a/golings/exercises/runner.go
+++ b/golings/exercises/runner.go
@@ -18,7 +18,8 @@ func Run(name string) (Result, error) {
return Result{}, err
}
- cmd := exec.Command("go", "run", fmt.Sprintf("./%s", exercise.Path))
+ args := BuildArgs(exercise)
+ cmd := exec.Command("go", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
@@ -27,3 +28,15 @@ func Run(name string) (Result, error) {
return Result{Exercise: exercise, Out: stdout.String(), Err: stderr.String()}, err
}
+
+func BuildArgs(e Exercise) []string {
+ args := []string{}
+ if e.Mode == "compile" {
+ args = append(args, "run")
+ } else {
+ args = append(args, "test", "-v")
+ }
+
+ args = append(args, fmt.Sprintf("./%s", e.Path))
+ return args
+}
diff --git a/info.toml b/info.toml
index 23abc4b..309eabe 100644
--- a/info.toml
+++ b/info.toml
@@ -68,3 +68,10 @@ path = "exercises/functions/functions4/main.go"
mode = "compile"
hint = """
Functions that return values must have return types declared in the function signature."""
+
+[[exercises]]
+name = "if1"
+path = "exercises/if/if1/main_test.go"
+mode = "test"
+hint = """
+"""