Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,23 @@ target_link_libraries(hype_core PUBLIC
target_compile_options(hype_core PUBLIC -Wall -Wextra)
set_target_properties(hype_core PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)

# The version comes from the release, never from the code: a tag's tarball unpacks as hype-<version>, and a checkout asks git.
get_filename_component(source_dir_name "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
if(source_dir_name MATCHES "^hype-([0-9][0-9.]*)$")
set(HYPE_VERSION "${CMAKE_MATCH_1}")
else()
execute_process(COMMAND git describe --tags --always --dirty
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE HYPE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
string(REGEX REPLACE "^v" "" HYPE_VERSION "${HYPE_VERSION}")
if(NOT HYPE_VERSION)
set(HYPE_VERSION dev)
endif()
endif()

add_executable(hype src/main.cpp src/resources.qrc)
target_link_libraries(hype PRIVATE hype_core)
target_compile_definitions(hype PRIVATE HYPE_VERSION="${HYPE_VERSION}")
set_target_properties(hype PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)

enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char **argv) {
qputenv("QT_QPA_PLATFORM", "offscreen");
QGuiApplication app(argc, argv);
app.setApplicationName("hype");
app.setApplicationVersion("0.6.0");
app.setApplicationVersion(HYPE_VERSION);
app.setDesktopFileName(qEnvironmentVariable("HYPE_DESKTOP_FILE", "hype"));
if (command)
return runCli(app.arguments());
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_new_starts_a_themed_presentation_without_overwriting(self):
self.assertIn('already exists', self.hype('new', self.deck, code=1).stderr)
self.assertIn('paper', self.hype('new', self.root / 'other.md', '--theme', 'nope', code=1).stderr)

def test_version_comes_from_the_build(self):
self.assertRegex(self.hype('--version').stdout, r'^hype [0-9a-z][^\s]*\n$')
Comment on lines +56 to +57

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Wrong versions pass the test

test_version_comes_from_the_build also passes with the old hardcoded version or with dev on a release build. It cannot catch a failure in the version selection this PR adds. Add focused checks that configure a hype-1.2.3 source tree, a Git checkout, and a Git-free source tree, then assert their expected versions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


def test_save_applies_a_theme_and_exits(self):
self.write('# One\n')
self.hype(self.deck, '--theme', 'paper', '--save')
Expand Down
Loading