From 2bd609afe38516dc7e4112fd6e4e6f62c7103098 Mon Sep 17 00:00:00 2001 From: Will R S Hansen Date: Mon, 8 Jul 2024 20:22:14 -0700 Subject: [PATCH] Export tasks in a deterministic order (#3549) fix issue #3527 --- src/commands/CmdExport.cpp | 2 +- test/CMakeLists.txt | 1 + test/tw-3527.test.py | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 test/tw-3527.test.py diff --git a/src/commands/CmdExport.cpp b/src/commands/CmdExport.cpp index f5c43f128..e758c9078 100644 --- a/src/commands/CmdExport.cpp +++ b/src/commands/CmdExport.cpp @@ -118,7 +118,7 @@ int CmdExport::execute (std::string& output) // if no sort order, sort by id if (!sortOrder.size ()) { - reportSort = "id"; + reportSort = "id,uuid"; } // Sort the tasks. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 877bb6863..26a18b1ce 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -170,6 +170,7 @@ set (pythonTests tw-2575.test.py tw-262.test.py tw-295.test.py + tw-3527.test.py uda.test.py uda_orphan.test.py uda_report.test.py diff --git a/test/tw-3527.test.py b/test/tw-3527.test.py new file mode 100755 index 000000000..a6674f60c --- /dev/null +++ b/test/tw-3527.test.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import sys +import os +import unittest +import re +import json +import string + +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Task, TestCase + + +class TestExport(TestCase): + def setUp(self): + self.t = Task() + + # pretty arbitrary, just need several unique tasks + for letter in string.ascii_lowercase: + self.t(f"add test_task +{letter}") + self.t(f"+{letter} done") + + def test_export_stability_for_multiple_id_0(self): + exports = [self.t("export")[1] for _ in range(2)] + json_lists = [json.loads(s.strip()) for s in exports] + # to rule out a typo causing two failed exports + self.assertEqual(len(json_lists[0]), len(string.ascii_lowercase)) + # for better diff view + self.assertEqual(json_lists[0], json_lists[1]) + # the real test + self.assertEqual(exports[0], exports[1]) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) +