Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-1360: refactor logger command to include -n flag with echo #26

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ release:
git tag v$(next_version_number)
git push origin main v$(next_version_number)

record_fixtures:
CODECRAFTERS_RECORD_FIXTURES=true make test

build:
go build -o dist/main.out ./cmd/tester

Expand All @@ -17,8 +20,8 @@ test_and_watch:
onchange '**/*' -- go test -v ./internal/

test_with_grep: build
CODECRAFTERS_SUBMISSION_DIR=$(shell pwd)/internal/test_helpers/pass_all \
CODECRAFTERS_TEST_CASES_JSON="[{"slug":"cq2","tester_log_prefix":"stage-1","title":"Stage #1: Match a literal character"},{"slug":"oq2","tester_log_prefix":"stage-2","title":"Stage #2: Match digits"},{"slug":"mr9","tester_log_prefix":"stage-3","title":"Stage #3: Match alphanumeric characters"},{"slug":"tl6","tester_log_prefix":"stage-4","title":"Stage #4: Positive Character Groups"},{"slug":"rk3","tester_log_prefix":"stage-5","title":"Stage #5: Negative Character Groups"},{"slug":"sh9","tester_log_prefix":"stage-6","title":"Stage #6: Combining Character Classes"},{"slug":"rr8","tester_log_prefix":"stage-7","title":"Stage #7: Start of string anchor"},{"slug":"ao7","tester_log_prefix":"stage-8","title":"Stage #8: End of string anchor"},{"slug":"fz7","tester_log_prefix":"stage-9","title":"Stage #9: Match one or more times"},{"slug":"ny8","tester_log_prefix":"stage-10","title":"Stage #10: Match zero or one times"},{"slug":"zb3","tester_log_prefix":"stage-11","title":"Stage #11: Wildcard"},{"slug":"zm7","tester_log_prefix":"stage-12","title":"Stage #12: Alternation"}]" \
CODECRAFTERS_REPOSITORY_DIR=$(shell pwd)/internal/test_helpers/pass_all \
CODECRAFTERS_TEST_CASES_JSON="[{\"slug\":\"cq2\",\"tester_log_prefix\":\"stage-1\",\"title\":\"Stage #1: Match a literal character\"},{\"slug\":\"oq2\",\"tester_log_prefix\":\"stage-2\",\"title\":\"Stage #2: Match digits\"},{\"slug\":\"mr9\",\"tester_log_prefix\":\"stage-3\",\"title\":\"Stage #3: Match alphanumeric characters\"},{\"slug\":\"tl6\",\"tester_log_prefix\":\"stage-4\",\"title\":\"Stage #4: Positive Character Groups\"},{\"slug\":\"rk3\",\"tester_log_prefix\":\"stage-5\",\"title\":\"Stage #5: Negative Character Groups\"},{\"slug\":\"sh9\",\"tester_log_prefix\":\"stage-6\",\"title\":\"Stage #6: Combining Character Classes\"},{\"slug\":\"rr8\",\"tester_log_prefix\":\"stage-7\",\"title\":\"Stage #7: Start of string anchor\"},{\"slug\":\"ao7\",\"tester_log_prefix\":\"stage-8\",\"title\":\"Stage #8: End of string anchor\"},{\"slug\":\"fz7\",\"tester_log_prefix\":\"stage-9\",\"title\":\"Stage #9: Match one or more times\"},{\"slug\":\"ny8\",\"tester_log_prefix\":\"stage-10\",\"title\":\"Stage #10: Match zero or one times\"},{\"slug\":\"zb3\",\"tester_log_prefix\":\"stage-11\",\"title\":\"Stage #11: Wildcard\"},{\"slug\":\"zm7\",\"tester_log_prefix\":\"stage-12\",\"title\":\"Stage #12: Alternation\"}]" \
dist/main.out

copy_course_file:
Expand Down
2 changes: 1 addition & 1 deletion internal/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func RunTestCases(testCases []TestCase, stageHarness *test_case_harness.TestCase
executable := stageHarness.Executable

for _, testCase := range testCases {
logger.Infof("$ echo \"%s\" | ./%s -E \"%s\"", testCase.Input, path.Base(executable.Path), testCase.Pattern)
logger.Infof("$ echo -n \"%s\" | ./%s -E \"%s\"", testCase.Input, path.Base(executable.Path), testCase.Pattern)
result, err := executable.RunWithStdin([]byte(testCase.Input), "-E", testCase.Pattern)
if err != nil {
return err
Expand Down
68 changes: 34 additions & 34 deletions internal/test_helpers/fixtures/alternation/success
Original file line number Diff line number Diff line change
@@ -1,122 +1,122 @@
[stage-12] Running tests for Stage #12: zm7
[stage-12] $ echo "a cat" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] $ echo -n "a cat" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a cat
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo "a dog" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] $ echo -n "a dog" | ./your_grep.sh -E "a (cat|dog)"
[your_program] a dog
[stage-12] ✓ Received exit code 0.
[stage-12] $ echo "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] $ echo -n "a cow" | ./your_grep.sh -E "a (cat|dog)"
[stage-12] ✓ Received exit code 1.
[stage-12] Test passed.

[stage-11] Running tests for Stage #11: zb3
[stage-11] $ echo "cat" | ./your_grep.sh -E "c.t"
[stage-11] $ echo -n "cat" | ./your_grep.sh -E "c.t"
[your_program] cat
[stage-11] ✓ Received exit code 0.
[stage-11] $ echo "cot" | ./your_grep.sh -E "c.t"
[stage-11] $ echo -n "cot" | ./your_grep.sh -E "c.t"
[your_program] cot
[stage-11] ✓ Received exit code 0.
[stage-11] $ echo "car" | ./your_grep.sh -E "c.t"
[stage-11] $ echo -n "car" | ./your_grep.sh -E "c.t"
[stage-11] ✓ Received exit code 1.
[stage-11] Test passed.

[stage-10] Running tests for Stage #10: ny8
[stage-10] $ echo "cat" | ./your_grep.sh -E "ca?t"
[stage-10] $ echo -n "cat" | ./your_grep.sh -E "ca?t"
[your_program] cat
[stage-10] ✓ Received exit code 0.
[stage-10] $ echo "act" | ./your_grep.sh -E "ca?t"
[stage-10] $ echo -n "act" | ./your_grep.sh -E "ca?t"
[your_program] act
[stage-10] ✓ Received exit code 0.
[stage-10] $ echo "dog" | ./your_grep.sh -E "ca?t"
[stage-10] $ echo -n "dog" | ./your_grep.sh -E "ca?t"
[stage-10] ✓ Received exit code 1.
[stage-10] $ echo "cag" | ./your_grep.sh -E "ca?t"
[stage-10] $ echo -n "cag" | ./your_grep.sh -E "ca?t"
[stage-10] ✓ Received exit code 1.
[stage-10] Test passed.

[stage-9] Running tests for Stage #9: fz7
[stage-9] $ echo "caaats" | ./your_grep.sh -E "ca+t"
[stage-9] $ echo -n "caaats" | ./your_grep.sh -E "ca+t"
[your_program] caaats
[stage-9] ✓ Received exit code 0.
[stage-9] $ echo "cat" | ./your_grep.sh -E "ca+t"
[stage-9] $ echo -n "cat" | ./your_grep.sh -E "ca+t"
[your_program] cat
[stage-9] ✓ Received exit code 0.
[stage-9] $ echo "act" | ./your_grep.sh -E "ca+t"
[stage-9] $ echo -n "act" | ./your_grep.sh -E "ca+t"
[stage-9] ✓ Received exit code 1.
[stage-9] Test passed.

[stage-8] Running tests for Stage #8: ao7
[stage-8] $ echo "cat" | ./your_grep.sh -E "cat$"
[stage-8] $ echo -n "cat" | ./your_grep.sh -E "cat$"
[your_program] cat
[stage-8] ✓ Received exit code 0.
[stage-8] $ echo "cats" | ./your_grep.sh -E "cat$"
[stage-8] $ echo -n "cats" | ./your_grep.sh -E "cat$"
[stage-8] ✓ Received exit code 1.
[stage-8] Test passed.

[stage-7] Running tests for Stage #7: rr8
[stage-7] $ echo "log" | ./your_grep.sh -E "^log"
[stage-7] $ echo -n "log" | ./your_grep.sh -E "^log"
[your_program] log
[stage-7] ✓ Received exit code 0.
[stage-7] $ echo "slog" | ./your_grep.sh -E "^log"
[stage-7] $ echo -n "slog" | ./your_grep.sh -E "^log"
[stage-7] ✓ Received exit code 1.
[stage-7] Test passed.

[stage-6] Running tests for Stage #6: sh9
[stage-6] $ echo "sally has 3 apples" | ./your_grep.sh -E "\d apple"
[stage-6] $ echo -n "sally has 3 apples" | ./your_grep.sh -E "\d apple"
[your_program] sally has 3 apples
[stage-6] ✓ Received exit code 0.
[stage-6] $ echo "sally has 1 orange" | ./your_grep.sh -E "\d apple"
[stage-6] $ echo -n "sally has 1 orange" | ./your_grep.sh -E "\d apple"
[stage-6] ✓ Received exit code 1.
[stage-6] $ echo "sally has 124 apples" | ./your_grep.sh -E "\d\d\d apples"
[stage-6] $ echo -n "sally has 124 apples" | ./your_grep.sh -E "\d\d\d apples"
[your_program] sally has 124 apples
[stage-6] ✓ Received exit code 0.
[stage-6] $ echo "sally has 12 apples" | ./your_grep.sh -E "\d\\d\\d apples"
[stage-6] $ echo -n "sally has 12 apples" | ./your_grep.sh -E "\d\\d\\d apples"
[stage-6] ✓ Received exit code 1.
[stage-6] $ echo "sally has 3 dogs" | ./your_grep.sh -E "\d \w\w\ws"
[stage-6] $ echo -n "sally has 3 dogs" | ./your_grep.sh -E "\d \w\w\ws"
[your_program] sally has 3 dogs
[stage-6] ✓ Received exit code 0.
[stage-6] $ echo "sally has 4 dogs" | ./your_grep.sh -E "\d \w\w\ws"
[stage-6] $ echo -n "sally has 4 dogs" | ./your_grep.sh -E "\d \w\w\ws"
[your_program] sally has 4 dogs
[stage-6] ✓ Received exit code 0.
[stage-6] $ echo "sally has 1 dog" | ./your_grep.sh -E "\d \w\w\ws"
[stage-6] $ echo -n "sally has 1 dog" | ./your_grep.sh -E "\d \w\w\ws"
[stage-6] ✓ Received exit code 1.
[stage-6] Test passed.

[stage-5] Running tests for Stage #5: rk3
[stage-5] $ echo "apple" | ./your_grep.sh -E "[^xyz]"
[stage-5] $ echo -n "apple" | ./your_grep.sh -E "[^xyz]"
[your_program] apple
[stage-5] ✓ Received exit code 0.
[stage-5] $ echo "banana" | ./your_grep.sh -E "[^anb]"
[stage-5] $ echo -n "banana" | ./your_grep.sh -E "[^anb]"
[stage-5] ✓ Received exit code 1.
[stage-5] Test passed.

[stage-4] Running tests for Stage #4: tl6
[stage-4] $ echo "a" | ./your_grep.sh -E "[abcd]"
[stage-4] $ echo -n "a" | ./your_grep.sh -E "[abcd]"
[your_program] a
[stage-4] ✓ Received exit code 0.
[stage-4] $ echo "efgh" | ./your_grep.sh -E "[abcd]"
[stage-4] $ echo -n "efgh" | ./your_grep.sh -E "[abcd]"
[stage-4] ✓ Received exit code 1.
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: mr9
[stage-3] $ echo "word" | ./your_grep.sh -E "\w"
[stage-3] $ echo -n "word" | ./your_grep.sh -E "\w"
[your_program] word
[stage-3] ✓ Received exit code 0.
[stage-3] $ echo "$!?" | ./your_grep.sh -E "\w"
[stage-3] $ echo -n "$!?" | ./your_grep.sh -E "\w"
[stage-3] ✓ Received exit code 1.
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: oq2
[stage-2] $ echo "123" | ./your_grep.sh -E "\d"
[stage-2] $ echo -n "123" | ./your_grep.sh -E "\d"
[your_program] 123
[stage-2] ✓ Received exit code 0.
[stage-2] $ echo "apple" | ./your_grep.sh -E "\d"
[stage-2] $ echo -n "apple" | ./your_grep.sh -E "\d"
[stage-2] ✓ Received exit code 1.
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: cq2
[stage-1] $ echo "dog" | ./your_grep.sh -E "d"
[stage-1] $ echo -n "dog" | ./your_grep.sh -E "d"
[your_program] dog
[stage-1] ✓ Received exit code 0.
[stage-1] $ echo "dog" | ./your_grep.sh -E "f"
[stage-1] $ echo -n "dog" | ./your_grep.sh -E "f"
[stage-1] ✓ Received exit code 1.
[stage-1] Test passed.
Loading
Loading