-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Prototype docs examples doubling as tests (#3977)
New theory of code examples in the docs: every one should live in the testsuite somewhere, and merely be included by reference in the docs. This ensures that every code example works, stays current with the evolution of the APIs, and never breaks. It also beefs up our test cases for more thorough code overage in the testsuite. I've done this with just two examples here, but hopefully it serves as an example for others to -- bit by bit -- convert all the other code examples in the docs into tests in a similar manner. Doing this for any one example is a perfect "good first issue," since it's bite sized and can easily be done in a day, it doesn't require any knowledge of deep OIIO internals, and in the process it also teaches you something about how both the docs and the testsuite are set up. A few notes: * I'm structuring it (for now?) as two testsuite entry for each chapter of the documentation (one for C++ and one for Python). * Note how I can have many code snippets in a test source file, and use the Sphinx `:start-after:` and `:end-before:` modifiers of `literalinclude` to clip particular subsections of the file, using special comment markers in the code. While I was there, I also fixed some typos I noticed in the text of the chapter, oops. --------- Signed-off-by: Larry Gritz <[email protected]>
- Loading branch information
Showing
17 changed files
with
246 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright Contributors to the OpenImageIO project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# https://github.com/OpenImageIO/oiio | ||
|
||
cmake_minimum_required (VERSION 3.15) | ||
project (oiio-docs-examples | ||
LANGUAGES CXX) | ||
|
||
if (NOT CMAKE_BUILD_TYPE) | ||
set (CMAKE_BUILD_TYPE "Release") | ||
endif () | ||
|
||
message (STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} - ${CMAKE_BUILD_TYPE}") | ||
|
||
# Use C++14 | ||
set (CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to prefer (14, 17, etc.)") | ||
set (CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set (CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
|
||
# Make sure we have dependencies we need | ||
find_package (OpenImageIO CONFIG REQUIRED) | ||
|
||
# Special for OIIO testsuite when running in sanitize mode | ||
if (DEFINED ENV{SANITIZE}) | ||
add_compile_options (-fsanitize=$ENV{SANITIZE}) | ||
add_link_options (-fsanitize=$ENV{SANITIZE}) | ||
endif() | ||
|
||
add_executable(docs-examples-imageoutput src/docs-examples-imageoutput.cpp) | ||
target_link_libraries (docs-examples-imageoutput | ||
PRIVATE OpenImageIO::OpenImageIO) | ||
|
||
# Chapters we haven't done yet: | ||
# add_executable(docs-imageinput src/docs-examples-imageinput.cpp) | ||
# target_link_libraries (docs-examples-imageinput | ||
# PRIVATE OpenImageIO::OpenImageIO) | ||
# | ||
# add_executable(docs-imagebuf src/docs-examples-imagebuf.cpp) | ||
# target_link_libraries (docs-examples-imagebuf | ||
# PRIVATE OpenImageIO::OpenImageIO) | ||
# | ||
# add_executable(docs-imagebufalgo src/docs-examples-imagebufalgo.cpp) | ||
# target_link_libraries (docs-examples-imagebufalgo | ||
# PRIVATE OpenImageIO::OpenImageIO) |
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,4 @@ | ||
Comparing "simple.tif" and "ref/simple.tif" | ||
PASS | ||
Comparing "scanlines.tif" and "ref/scanlines.tif" | ||
PASS |
Binary file not shown.
Binary file not shown.
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,17 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright Contributors to the OpenImageIO project. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# https://github.com/OpenImageIO/oiio | ||
|
||
|
||
# command += "echo test_source_dir=" + test_source_dir + " >> build.txt ;" | ||
command += run_app("cmake " + test_source_dir + " -DCMAKE_BUILD_TYPE=Release >> build.txt 2>&1", silent=True) | ||
command += run_app("cmake --build . --config Release >> build.txt 2>&1", silent=True) | ||
if platform.system() == 'Windows' : | ||
command += run_app("Release\\docs-examples-imageoutput") | ||
else : | ||
command += run_app("./docs-examples-imageoutput") | ||
|
||
outputs = [ "simple.tif", "scanlines.tif", | ||
"out.txt" ] |
Oops, something went wrong.