Skip to content

Commit e0fce56

Browse files
committed
feat: Fixed major and minor bugs such as incorrect arg parsing and argc flushing, implemented full testing for builtins, aswell as new builtins, such as pwd and cd.
1 parent 3cf2327 commit e0fce56

26 files changed

+4202
-142
lines changed

.pre-commit-config.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ repos:
1212
hooks:
1313
- id: clang-format
1414
- id: clang-tidy
15-
- id: oclint
16-
- id: uncrustify
17-
- id: cppcheck
18-
- id: cpplint
19-
- id: include-what-you-use
2015
- repo: https://github.com/pre-commit/pre-commit-hooks
2116
rev: v4.4.0
2217
hooks:

defaults.cfg

+3,723
Large diffs are not rendered by default.

justfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ default:
1313
@test:
1414
scripts/build.sh -t
1515

16+
@setup-testing:
17+
scripts/build.sh -st
18+
1619
@build name="hsh":
1720
just compile {{name}}
1821
just link {{name}}

scripts/build.sh

+27-13
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ Compiles ${CYAN}${SRC}/main.c${CLEAR} & all files in ${CYAN}${DIR}/${CLEAR}.
106106
${RED}-l${CLEAR} | ${RED}--link${CLEAR}
107107
Links all the files in ${CYAN}${OUT}/${CLEAR} to an executable with ${BLUE}{EXECUTABLE_NA}ME}${CLEAR}
108108
109+
${RED}-st${CLEAR} | ${RED}--setup-testing${CLEAR}
110+
Sets up and installs unity in the correct path.
111+
(Automatically runs if not already installed during --test)
112+
109113
${RED}-t${CLEAR} | ${RED}--test${CLEAR}
110114
Runs unit tests in ${TEST}
111115
@@ -194,17 +198,34 @@ link() {
194198
echo -ne "${YELLOW}!${CLEAR} ${CYAN}${EXECUTABLE_NAME}${CLEAR} seems to already exist, you wanna relink it? [${GREEN}Y${CLEAR}/${RED}n${CLEAR}]: "
195199
read -r RELINK
196200
if [[ ! ${RELINK} =~ [Nn] ]]; then
201+
# shellcheck disable=SC2086,SC2048
197202
"${CC}" -fuse-ld=mold ${CFLAGS} ${LINKER_FLAGS} -o "${BIN}/${EXECUTABLE_NAME}" ${TRIMMED_FILES[*]}
198203
echo -e "${GREEN}${CLEAR} Linked ${CYAN}${TRIMMED_FILES}${CLEAR} successfully"
199204
fi
200205
else
206+
# shellcheck disable=SC2086,SC2048
201207
"${CC}" -fuse-ld=mold ${CFLAGS} ${LINKER_FLAGS} -o "${BIN}/${EXECUTABLE_NAME}" ${TRIMMED_FILES[*]}
202208
echo -e "${GREEN}${CLEAR} Linked ${CYAN}${TRIMMED_FILES}${CLEAR} successfully"
203209
fi
204210

205211
popd >/dev/null || handle_failure "Failed to popd" # || echo "Failed to popd" && exit 1
206212
}
207213

214+
setup_unity() {
215+
mkdir "${TEST}/unity"
216+
mkdir temp_dir
217+
218+
pushd temp_dir >/dev/null || handle_failure "Failed to pushd"
219+
git clone https://github.com/ThrowTheSwitch/Unity
220+
221+
rm Unity/src/meson.build
222+
mv Unity/src/* "${TEST}/unity"
223+
224+
popd >/dev/null || handle_failure "Failed to popd"
225+
226+
rm -fr temp_dir
227+
}
228+
208229
unit_test() {
209230
local -a TESTS
210231
local TEST_FILE
@@ -222,18 +243,7 @@ unit_test() {
222243
local TRIMMED_BINARY_NAME
223244

224245
if [[ ! -d ${TEST}/unity ]]; then
225-
mkdir "${TEST}/unity"
226-
mkdir temp_dir
227-
228-
pushd temp_dir >/dev/null || handle_failure "Failed to pushd"
229-
git clone https://github.com/ThrowTheSwitch/Unity
230-
231-
rm Unity/src/meson.build
232-
mv Unity/src/* "${TEST}/unity"
233-
234-
popd >/dev/null || handle_failure "Failed to popd"
235-
236-
rm -fr temp_dir
246+
setup_unity
237247
fi
238248

239249
if [[ ! -d ${TEST_OUT} ]]; then
@@ -283,6 +293,7 @@ unit_test() {
283293
TRIMMED_TEST_OBJ_FILENAME="${TRIMMED_TEST_OBJ_FILE##*/}"
284294

285295
echo -e "${BLUE}>${CLEAR} Linking ${CYAN}${TRIMMED_TEST_FILENAME}.o${CLEAR} & ${CYAN}unity.o${CLEAR} to ${TRIMMED_TEST_OBJ_FILENAME}"
296+
# shellcheck disable=SC2086,SC2048
286297
"${CC}" -fuse-ld=mold ${CFLAGS} ${LINKER_FLAGS} -o "${TEST_BIN}/${TRIMMED_TEST_OBJ_FILENAME}" "${TRIMMED_TEST_OBJ_FILENAME}.o" "./deps/${TRIMMED_TEST_OBJ_FILENAME:5}.o" "${TEST_OUT}/unity/unity.o"
287298
echo -e "${GREEN}${CLEAR} Successfully linked ${CYAN}${TRIMMED_TEST_FILENAME}.o${CLEAR} & ${CYAN}unity.o${CLEAR} to ${TRIMMED_TEST_OBJ_FILENAME}"
288299
done
@@ -345,7 +356,7 @@ clean() {
345356
LOCALBIN=${2}
346357
CONFIRMATION=${3}
347358
LOG=${4:true}
348-
359+
349360
if ${LOG}; then
350361
echo -e "${RED}!${CLEAR} Cleaning ${CYAN}${LOCALOUT}${CLEAR} & ${CYAN}${LOCALBIN}${CLEAR}."
351362
fi
@@ -395,6 +406,9 @@ case $1 in
395406
clean_dangling "${DIR}" "${OUT}"
396407
link "${2}"
397408
;;
409+
"-st" | "--setup-testing")
410+
setup_unity
411+
;;
398412
"-t" | "--test")
399413
unit_test
400414
;;

shell.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
{ pkgs ? import <nixpkgs> {}}:
2-
1+
{pkgs ? import <nixpkgs> {}}:
32
pkgs.mkShell {
43
allowUnfree = true;
54
name = "hamon!";
@@ -18,8 +17,9 @@ pkgs.mkShell {
1817
mdformat
1918
beautysh
2019
shfmt
21-
uncrustify
20+
shellcheck
2221
];
2322
shellHook = ''
23+
pre-commit install
2424
'';
2525
}

0 commit comments

Comments
 (0)