From 76d6ed368609b76af0a4beea4dcd1518acb27e44 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Sun, 22 Dec 2024 21:54:21 +0530 Subject: [PATCH 1/3] refactor: consolidate test commands and update test cases --- Makefile | 99 ++++++++++++++++++++++---------------------------------- 1 file changed, 38 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 13dc913..7e8b1c0 100644 --- a/Makefile +++ b/Makefile @@ -17,29 +17,17 @@ build: test: TESTER_DIR=$(shell pwd) go test -count=1 -p 1 -v ./internal/... -test_base_w_bash: build - CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ - CODECRAFTERS_TEST_CASES_JSON="[ \ - {\"slug\":\"oo8\",\"tester_log_prefix\":\"tester::#oo8\",\"title\":\"Stage #1: Init\"}, \ - {\"slug\":\"cz2\",\"tester_log_prefix\":\"tester::#cz2\",\"title\":\"Stage #2: Invalid Command\"}, \ - {\"slug\":\"ff0\",\"tester_log_prefix\":\"tester::#ff0\",\"title\":\"Stage #3: REPL\"}, \ - {\"slug\":\"pn5\",\"tester_log_prefix\":\"tester::#pn5\",\"title\":\"Stage #4: Exit\"}, \ - {\"slug\":\"iz3\",\"tester_log_prefix\":\"tester::#iz3\",\"title\":\"Stage #5: Echo\"}, \ - {\"slug\":\"ez5\",\"tester_log_prefix\":\"tester::#ez5\",\"title\":\"Stage #6: Type built-in\"}, \ - {\"slug\":\"mg5\",\"tester_log_prefix\":\"tester::#mg5\",\"title\":\"Stage #7: Type for executables\"}, \ - {\"slug\":\"ip1\",\"tester_log_prefix\":\"tester::#ip1\",\"title\":\"Stage #8: Run a program\"} \ - ]" \ - dist/main.out +record_fixtures: + CODECRAFTERS_RECORD_FIXTURES=true make test -test_nav_w_bash: build - CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ - CODECRAFTERS_TEST_CASES_JSON="[ \ - {\"slug\":\"ei0\",\"tester_log_prefix\":\"tester::#ei0\",\"title\":\"Stage #9: PWD\"}, \ - {\"slug\":\"ra6\",\"tester_log_prefix\":\"tester::#ra6\",\"title\":\"Stage #10: CD-1\"}, \ - {\"slug\":\"gq9\",\"tester_log_prefix\":\"tester::#gq9\",\"title\":\"Stage #11: CD-2\"}, \ - {\"slug\":\"gp4\",\"tester_log_prefix\":\"tester::#gp4\",\"title\":\"Stage #12: CD-3\"} \ - ]" \ - dist/main.out +update_tester_utils: + go get -u github.com/codecrafters-io/tester-utils + +copy_course_file: + gh api repos/codecrafters-io/build-your-own-shell/contents/course-definition.yml \ + | jq -r .content \ + | base64 -d \ + > internal/test_helpers/course_definition.yml test_dash: build CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/dash \ @@ -59,20 +47,6 @@ test_dash: build ]" \ dist/main.out -test_ryan: build - CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/ryan_shell \ - CODECRAFTERS_TEST_CASES_JSON="[ \ - {\"slug\":\"cz2\",\"tester_log_prefix\":\"tester::#cz2\",\"title\":\"Stage #2: Invalid Command\"}, \ - {\"slug\":\"ff0\",\"tester_log_prefix\":\"tester::#ff0\",\"title\":\"Stage #3: REPL\"}, \ - {\"slug\":\"iz3\",\"tester_log_prefix\":\"tester::#iz3\",\"title\":\"Stage #5: Echo\"}, \ - {\"slug\":\"ez5\",\"tester_log_prefix\":\"tester::#ez5\",\"title\":\"Stage #6: Type built-in\"}, \ - {\"slug\":\"mg5\",\"tester_log_prefix\":\"tester::#mg5\",\"title\":\"Stage #7: Type for executables\"}, \ - {\"slug\":\"ip1\",\"tester_log_prefix\":\"tester::#ip1\",\"title\":\"Stage #8: Run a program\"} \ - ]" \ - dist/main.out - -test_all_success: test_bash test_dash - test_failure: build CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/failure \ CODECRAFTERS_TEST_CASES_JSON="[ \ @@ -94,18 +68,29 @@ test_zsh_dangerously: build ]" \ dist/main.out +test_base_w_bash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"oo8\",\"tester_log_prefix\":\"tester::#oo8\",\"title\":\"Stage #1: Init\"}, \ + {\"slug\":\"cz2\",\"tester_log_prefix\":\"tester::#cz2\",\"title\":\"Stage #2: Invalid Command\"}, \ + {\"slug\":\"ff0\",\"tester_log_prefix\":\"tester::#ff0\",\"title\":\"Stage #3: REPL\"}, \ + {\"slug\":\"pn5\",\"tester_log_prefix\":\"tester::#pn5\",\"title\":\"Stage #4: Exit\"}, \ + {\"slug\":\"iz3\",\"tester_log_prefix\":\"tester::#iz3\",\"title\":\"Stage #5: Echo\"}, \ + {\"slug\":\"ez5\",\"tester_log_prefix\":\"tester::#ez5\",\"title\":\"Stage #6: Type built-in\"}, \ + {\"slug\":\"mg5\",\"tester_log_prefix\":\"tester::#mg5\",\"title\":\"Stage #7: Type for executables\"}, \ + {\"slug\":\"ip1\",\"tester_log_prefix\":\"tester::#ip1\",\"title\":\"Stage #8: Run a program\"} \ + ]" \ + dist/main.out -record_fixtures: - CODECRAFTERS_RECORD_FIXTURES=true make test - -update_tester_utils: - go get -u github.com/codecrafters-io/tester-utils - -copy_course_file: - gh api repos/codecrafters-io/build-your-own-shell/contents/course-definition.yml \ - | jq -r .content \ - | base64 -d \ - > internal/test_helpers/course_definition.yml +test_nav_w_bash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"ei0\",\"tester_log_prefix\":\"tester::#ei0\",\"title\":\"Stage #9: PWD\"}, \ + {\"slug\":\"ra6\",\"tester_log_prefix\":\"tester::#ra6\",\"title\":\"Stage #10: CD-1\"}, \ + {\"slug\":\"gq9\",\"tester_log_prefix\":\"tester::#gq9\",\"title\":\"Stage #11: CD-2\"}, \ + {\"slug\":\"gp4\",\"tester_log_prefix\":\"tester::#gp4\",\"title\":\"Stage #12: CD-3\"} \ + ]" \ + dist/main.out test_quoting_w_bash: build CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ @@ -119,11 +104,13 @@ test_quoting_w_bash: build ]" \ dist/main.out -test_quoting_minimal: build +test_redirection_w_bash: build CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ CODECRAFTERS_TEST_CASES_JSON="[ \ - {\"slug\":\"ni6\",\"tester_log_prefix\":\"tester::#ni6\",\"title\":\"Stage #1: Quoting with single quotes\"}, \ - {\"slug\":\"yt5\",\"tester_log_prefix\":\"tester::#yt5\",\"title\":\"Stage #3: Quoting with backslashes\"} \ + {\"slug\":\"jv1\",\"tester_log_prefix\":\"tester::#jv1\",\"title\":\"Stage #13: Redirect stdout\"}, \ + {\"slug\":\"vz4\",\"tester_log_prefix\":\"tester::#vz4\",\"title\":\"Stage #14: Redirect stderr\"}, \ + {\"slug\":\"el9\",\"tester_log_prefix\":\"tester::#el9\",\"title\":\"Stage #15: Append stdout\"}, \ + {\"slug\":\"un3\",\"tester_log_prefix\":\"tester::#un3\",\"title\":\"Stage #16: Append stderr\"} \ ]" \ dist/main.out @@ -131,14 +118,4 @@ test_bash: make test_base_w_bash make test_nav_w_bash make test_quoting_w_bash - - -test_redirection_w_bash: build - CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/bash \ - CODECRAFTERS_TEST_CASES_JSON="[ \ - {\"slug\":\"jv1\",\"tester_log_prefix\":\"tester::#jv1\",\"title\":\"Stage #13: Redirect stdout\"}, \ - {\"slug\":\"vz4\",\"tester_log_prefix\":\"tester::#vz4\",\"title\":\"Stage #14: Redirect stderr\"}, \ - {\"slug\":\"el9\",\"tester_log_prefix\":\"tester::#el9\",\"title\":\"Stage #15: Append stdout\"}, \ - {\"slug\":\"un3\",\"tester_log_prefix\":\"tester::#un3\",\"title\":\"Stage #16: Append stderr\"} \ - ]" \ - dist/main.out \ No newline at end of file + make test_redirection_w_bash From 32f62549efa0eb14e62038558d2728732f413bb8 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Sun, 22 Dec 2024 21:56:38 +0530 Subject: [PATCH 2/3] chore: add tests against ash shell --- Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Makefile b/Makefile index 7e8b1c0..d1d17e7 100644 --- a/Makefile +++ b/Makefile @@ -119,3 +119,56 @@ test_bash: make test_nav_w_bash make test_quoting_w_bash make test_redirection_w_bash + + +test_base_w_ash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/ash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"oo8\",\"tester_log_prefix\":\"tester::#oo8\",\"title\":\"Stage #1: Init\"}, \ + {\"slug\":\"cz2\",\"tester_log_prefix\":\"tester::#cz2\",\"title\":\"Stage #2: Invalid Command\"}, \ + {\"slug\":\"ff0\",\"tester_log_prefix\":\"tester::#ff0\",\"title\":\"Stage #3: REPL\"}, \ + {\"slug\":\"pn5\",\"tester_log_prefix\":\"tester::#pn5\",\"title\":\"Stage #4: Exit\"}, \ + {\"slug\":\"iz3\",\"tester_log_prefix\":\"tester::#iz3\",\"title\":\"Stage #5: Echo\"}, \ + {\"slug\":\"ez5\",\"tester_log_prefix\":\"tester::#ez5\",\"title\":\"Stage #6: Type built-in\"}, \ + {\"slug\":\"mg5\",\"tester_log_prefix\":\"tester::#mg5\",\"title\":\"Stage #7: Type for executables\"}, \ + {\"slug\":\"ip1\",\"tester_log_prefix\":\"tester::#ip1\",\"title\":\"Stage #8: Run a program\"} \ + ]" \ + dist/main.out + +test_nav_w_ash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/ash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"ei0\",\"tester_log_prefix\":\"tester::#ei0\",\"title\":\"Stage #9: PWD\"}, \ + {\"slug\":\"ra6\",\"tester_log_prefix\":\"tester::#ra6\",\"title\":\"Stage #10: CD-1\"}, \ + {\"slug\":\"gq9\",\"tester_log_prefix\":\"tester::#gq9\",\"title\":\"Stage #11: CD-2\"}, \ + {\"slug\":\"gp4\",\"tester_log_prefix\":\"tester::#gp4\",\"title\":\"Stage #12: CD-3\"} \ + ]" \ + dist/main.out + +test_quoting_w_ash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/ash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"ni6\",\"tester_log_prefix\":\"tester::#ni6\",\"title\":\"Stage #1: Quoting with single quotes\"}, \ + {\"slug\":\"tg6\",\"tester_log_prefix\":\"tester::#tg6\",\"title\":\"Stage #2: Quoting with double quotes\"}, \ + {\"slug\":\"yt5\",\"tester_log_prefix\":\"tester::#yt5\",\"title\":\"Stage #3: Quoting with backslashes\"}, \ + {\"slug\":\"le5\",\"tester_log_prefix\":\"tester::#le5\",\"title\":\"Stage #4: Quoting with single and double quotes\"}, \ + {\"slug\":\"gu3\",\"tester_log_prefix\":\"tester::#gu3\",\"title\":\"Stage #5: Quoting with mixed quotes\"}, \ + {\"slug\":\"qj0\",\"tester_log_prefix\":\"tester::#qj0\",\"title\":\"Stage #6: Quoting program names\"} \ + ]" \ + dist/main.out + +test_redirection_w_ash: build + CODECRAFTERS_REPOSITORY_DIR=./internal/test_helpers/ash \ + CODECRAFTERS_TEST_CASES_JSON="[ \ + {\"slug\":\"jv1\",\"tester_log_prefix\":\"tester::#jv1\",\"title\":\"Stage #13: Redirect stdout\"}, \ + {\"slug\":\"vz4\",\"tester_log_prefix\":\"tester::#vz4\",\"title\":\"Stage #14: Redirect stderr\"}, \ + {\"slug\":\"el9\",\"tester_log_prefix\":\"tester::#el9\",\"title\":\"Stage #15: Append stdout\"}, \ + {\"slug\":\"un3\",\"tester_log_prefix\":\"tester::#un3\",\"title\":\"Stage #16: Append stderr\"} \ + ]" \ + dist/main.out + +test_ash: + make test_base_w_ash + make test_nav_w_ash + make test_quoting_w_ash + make test_redirection_w_ash From 2231fbf268e60976e97e1018c74ca9b0cf19888d Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Sun, 22 Dec 2024 21:56:50 +0530 Subject: [PATCH 3/3] feat: add submission packet for ash shell --- internal/test_helpers/ash/codecrafters.yml | 5 +++++ internal/test_helpers/ash/your_shell.sh | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 internal/test_helpers/ash/codecrafters.yml create mode 100755 internal/test_helpers/ash/your_shell.sh diff --git a/internal/test_helpers/ash/codecrafters.yml b/internal/test_helpers/ash/codecrafters.yml new file mode 100644 index 0000000..bff4295 --- /dev/null +++ b/internal/test_helpers/ash/codecrafters.yml @@ -0,0 +1,5 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: true diff --git a/internal/test_helpers/ash/your_shell.sh b/internal/test_helpers/ash/your_shell.sh new file mode 100755 index 0000000..4ab1be4 --- /dev/null +++ b/internal/test_helpers/ash/your_shell.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec ash \ No newline at end of file