Exercism에서 ReScript 연습 문제를 테스트하는 방법을 알아봐요
작업하고 싶은 연습 문제는 Exercism CLI로 다운로드해요.
exercism download --track=rescript --exercise=hello-world
그런 다음 연습 문제 디렉터리로 이동해요.
cd /path/to/exercism/rescript/hello-world
테스트를 실행하기 전에 연습 문제의 의존성을 먼저 설치해요.
npm install
exercism test나 npm run test를 사용해서 제공된 테스트 스위트를 컴파일하고 실행해요.
테스트 러너는 각 테스트 실행을 통과/실패 상태와 함께 보여줘요.
1/3: no name given
PASS - no name given
2/3: a name given
FAIL - a name given
---
operator: equal
left: One for you, one for me.
right: One for Alice, one for me.
...
3/3: another name given
FAIL - another name given
---
operator: equal
left: One for you, one for me.
right: One for Bob, one for me.
...
# Ran 3 tests (3 assertions)
# 1 passed
# 2 failed
left는 코드가 반환한 값이에요. right는 테스트가 기대한 값이에요.
two-fer/
├── src/
│ ├── TwoFer.res // your solution goes here
│ └── TwoFer.resi // the optional interface file containing signatures
├── tests/
│ └── TwoFer_test.res // your test suite
├── package.json // used to install project dependencies
└── ...
여기서 TwoFer.resi는 선택적인 인터페이스 파일이에요.
이 파일이 있으면 작성한 풀이가 만족해야 하는 함수 시그니처를 정의하고, 무엇을 구현해야 하는지에 대한 힌트가 될 수 있어요.
예를 들어, 인터페이스가 다음과 같이 선언한다면:
let hello: unit => string
구현은 다음과 같이 정의해야 해요:
let hello = () => "Hello, World!"
코드가 컴파일되지 않으면 ReScript 컴파일러는 정확한 위치와 기대 타입을 담은 자세한 오류 메시지를 만들어요.
We've found a bug for you!
1 │ let x: string = 42
This has type: int
But it's expected to have type: string
You can convert int to string with Int.toString.
오류 메시지를 자세히 읽어봐요. 보통 문제를 바로 가리키거든요.