Skip to content

Commit

Permalink
Add hello-world exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
bergjohan committed Jan 8, 2020
1 parent 17300bc commit fa7e914
Show file tree
Hide file tree
Showing 12 changed files with 3,465 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
.DS_Store
bin/configlet
bin/configlet.exe
build/
**/tests
**/*.o
*.pyc
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
language: bash
language: c

arch:
- arm64

os:
- linux

compiler:
- gcc

script:
- bin/fetch-configlet
- bin/configlet lint --track-id arm64-assembly .
- bin/verify-exercises
39 changes: 39 additions & 0 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

run_tests() {
local file="${1//-/_}"

cd "$1"

sed -i.bak 's#TEST_IGNORE();#// &#' "${file}"_test.c
mv example.s "${file}".s

make clean
make

cd ..
}

main() {
cd "$(dirname "$0")"/..

rm -rf build
cp -r exercises build

cd build

if [[ $# -gt 0 ]]; then
for exercise in "$@"; do
run_tests "${exercise}"
done
else
for exercise in *; do
run_tests "${exercise}"
done
fi

}

main "$@"
14 changes: 13 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@
"ignore_pattern": "[Ee]xample",
"solution_pattern": "[Ee]xample",
"test_pattern": "[Tt]est",
"exercises": null
"exercises": [
{
"slug": "hello-world",
"uuid": "669a233b-b6c3-4d18-81d8-41b906ad5eb1",
"core": true,
"auto_approve": true,
"unlocked_by": null,
"difficulty": 1,
"topics": [
"strings"
]
}
]
}
35 changes: 35 additions & 0 deletions exercises/hello-world/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
AS = as

CFLAGS = -g -Wall -Wextra -pedantic -Werror
LDFLAGS =

ALL_LDFLAGS = -pie -Wl,--fatal-warnings

ALL_CFLAGS = -std=c99 -fPIE $(CFLAGS)
ALL_LDFLAGS += $(LDFLAGS)

C_OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
AS_OBJS = $(patsubst %.s,%.o,$(wildcard *.s))
ALL_OBJS = $(filter-out example.o,$(C_OBJS) $(AS_OBJS) vendor/unity.o)

CC_CMD = $(CC) $(ALL_CFLAGS) -c -o $@ $<

all: tests
@./$<

tests: $(ALL_OBJS)
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) -o $@ $(ALL_OBJS)

%.o: %.s
@$(AS) -o $@ $<

%.o: %.c
@$(CC_CMD)

vendor/unity.o: vendor/unity.c vendor/unity.h vendor/unity_internals.h
@$(CC_CMD)

clean:
@rm -f *.o vendor/*.o tests

.PHONY: all clean
21 changes: 21 additions & 0 deletions exercises/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Hello World

The classical introductory exercise. Just say "Hello, World!".

["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.

The objectives are simple:

- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.

If everything goes well, you will be ready to fetch your first real exercise.
## Source

This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
9 changes: 9 additions & 0 deletions exercises/hello-world/example.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.section .rodata
msg: .string "Hello, World!"

.text
.global hello
hello:
adrp x0, msg
add x0, x0, :lo12:msg
ret
9 changes: 9 additions & 0 deletions exercises/hello-world/hello_world.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.section .rodata
msg: .string ""

.text
.global hello
hello:
adrp x0, msg
add x0, x0, :lo12:msg
ret
21 changes: 21 additions & 0 deletions exercises/hello-world/hello_world_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Version: 1.1.0

#include "vendor/unity.h"

extern const char *hello(void);

void setUp(void) {
}

void tearDown(void) {
}

void test_say_hi(void) {
TEST_ASSERT_EQUAL_STRING("Hello, World!", hello());
}

int main(void) {
UNITY_BEGIN();
RUN_TEST(test_say_hi);
return UNITY_END();
}
Loading

0 comments on commit fa7e914

Please sign in to comment.