-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update test commands to use explicit shell command syntax for …
…clarity
- Loading branch information
1 parent
58a5961
commit b9a5f59
Showing
14 changed files
with
214 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import os | ||
import zlib | ||
|
||
import hashlib | ||
import pathlib | ||
|
||
|
||
def main(): | ||
command = sys.argv[1] | ||
if command == "init": | ||
os.mkdir(".git") | ||
os.mkdir(".git/objects") | ||
os.mkdir(".git/refs") | ||
with open(".git/HEAD", "w") as f: | ||
f.write("ref: refs/heads/master\n") | ||
|
||
print("Initialized git directory") | ||
elif command == "hash-object": | ||
assert sys.argv[2] == "-w" | ||
filepath = sys.argv[3] | ||
contents = open(filepath).read() | ||
header = f"blob{len(contents)}\0" | ||
store = (header + contents).encode() | ||
sha = hashlib.sha1(store).hexdigest() | ||
print(sha) | ||
zlib_store = zlib.compress(store) | ||
path = f".git/objects/{sha[0:2]}/{sha[2:]}" | ||
os.makedirs(os.path.dirname(path), exist_ok=True) | ||
open(path, "wb").write(zlib_store) | ||
elif command == "cat-file": | ||
sha = sys.argv[3] | ||
obj_path = f".git/objects/{sha[0:2]}/{sha[2:]}" | ||
compressed = open(obj_path, "rb").read() | ||
uncompressed = zlib.decompress(compressed) | ||
sys.stdout.buffer.write(uncompressed.split(b"\0")[-1]) | ||
else: | ||
raise RuntimeError(f"Unknown command: #{command}") | ||
|
||
|
||
main() |
11 changes: 11 additions & 0 deletions
11
internal/test_helpers/stages/create_blob_failure/codecrafters.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is the current stage that you're on. | ||
# | ||
# Whenever you want to advance to the next stage, | ||
# bump this to the next number. | ||
current_stage: 1 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
export PYTHONPATH="$(dirname "$0")" | ||
exec python3 -m app "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
import os | ||
import zlib | ||
|
||
import hashlib | ||
import pathlib | ||
|
||
|
||
def main(): | ||
command = sys.argv[1] | ||
if command == "init": | ||
os.mkdir(".git") | ||
os.mkdir(".git/objects") | ||
os.mkdir(".git/refs") | ||
with open(".git/HEAD", "w") as f: | ||
f.write("ref: refs/heads/master\n") | ||
|
||
print("Initialized git directory") | ||
elif command == "hash-object": | ||
assert sys.argv[2] == "-w" | ||
print("afa8b20484a29b438370b623ced459c9409fcc05") # Dummy | ||
elif command == "cat-file": | ||
sha = sys.argv[3] | ||
obj_path = f".git/objects/{sha[0:2]}/{sha[2:]}" | ||
compressed = open(obj_path, "rb").read() | ||
uncompressed = zlib.decompress(compressed) | ||
sys.stdout.buffer.write(uncompressed.split(b"\0")[-1]) | ||
else: | ||
raise RuntimeError(f"Unknown command: #{command}") | ||
|
||
|
||
main() |
11 changes: 11 additions & 0 deletions
11
internal/test_helpers/stages/create_blob_no_file/codecrafters.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is the current stage that you're on. | ||
# | ||
# Whenever you want to advance to the next stage, | ||
# bump this to the next number. | ||
current_stage: 1 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
export PYTHONPATH="$(dirname "$0")" | ||
exec python3 -m app "$@" |