# Generating input files for a test case

**URL:** https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496
**Category:** Development
**Created:** [July 6, 2020, 9:34pm UTC](https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496 "2020-07-06T21:34:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Holger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@Holger](https://discourse.cmake.org/u/Holger)
#### Post date: [July 6, 2020, 9:34pm UTC](https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496/1 "2020-07-06T21:34:06Z")

</div>

Hi,

I am writing a test case for which I need several input files. All of these files are fairly trivial, they just need to be there so that CMake actually generates something; so I think checking them in would not be a great idea.

Currently I am doing this in `RunCMakeTest.cmake`:

```cmake
set(test_bindir ${RunCMake_BINARY_DIR}/MyTestName-build)
file(WRITE ${test_bindir}/foo.cpp "int foo(int a) { return a*a; }")
file(WRITE ${test_bindir}/samplefile.txt.in "1")
file(WRITE ${test_bindir}/CMakeLists.txt
  "cmake_minimum_required(VERSION 3.18)\n"
  "project(MyTestName)\n"
  "add_library(foo ${test_bindir}/foo.cpp)\n"
  "configure_file(${test_bindir}/samplefile.txt.in ${test_bindir}/samplefile.txt.tmp)\n"
  "file(GENERATE OUTPUT ${test_bindir}/samplefile.txt INPUT ${test_bindir}/samplefile.txt.tmp)\n")
...
<snip>

```

@brad.king suggested to use the `file-GENERATE.cmake` facility for this, but I cannot find any documentation or examples. I read `Tests/RunCMake/README.rst` but didn’t find anything in that regard.

What is the clean way to generate input files for a test case using the CMake test infrastructure?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [July 7, 2020, 12:57pm UTC](https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496/2 "2020-07-07T12:57:45Z")

</div>

For reference, this comes from review [here](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4939#note_788853). What I meant is that you should just create `file-GENERATE.cmake` in an editor and put it in the source tree. This is documented in `Tests/RunCMake/README.rst`:

- Create a `<Test>/<SubTest>.cmake` file

---

<div class="post-metadata">

### Author: ![Holger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@Holger](https://discourse.cmake.org/u/Holger)
#### Post date: [July 8, 2020, 6:25pm UTC](https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496/3 "2020-07-08T18:25:10Z")

</div>

@brad.king Thanks for this clarification! Makes sense.

I am currently quite busy, but hope to find some time to do this on this weekend.

Best.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [July 8, 2020, 6:42pm UTC](https://discourse.cmake.org/t/generating-input-files-for-a-test-case/1496/4 "2020-07-08T18:42:55Z")

</div>

In this particular case, I’ve already re-opened your merge request and added the needed tests.
