Blob Blame History Raw
From 953aa33ab33ca6059f85dc8ebb40c3b6bbaae39c Mon Sep 17 00:00:00 2001
From: Greg Hurrell <greg@hurrell.net>
Date: Thu, 14 Aug 2014 07:40:39 -0700
Subject: [PATCH] Fix (spurious) test failure on big-endian architectures

Our example includes a int_64_t value (the PDU's length prefix), which
is endian-sensitive and so needs to be asserted using native endianness.

Fixes:

  https://github.com/wincent/Command-T/issues/101
  https://bugzilla.redhat.com/show_bug.cgi?id=1130079
---
 spec/command-t/watchman/utils_spec.rb | 45 ++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/spec/command-t/watchman/utils_spec.rb b/spec/command-t/watchman/utils_spec.rb
index 8f174f7..4bb5c4e 100644
--- a/spec/command-t/watchman/utils_spec.rb
+++ b/spec/command-t/watchman/utils_spec.rb
@@ -379,20 +379,37 @@ def roundtrip(value)
 
     it 'generates a correct serialization' do
       # in Ruby 1.8, hashes aren't ordered, so two serializations are possible
-      expected = [
-        binary(
-          "\x00\x01\x06\x49\x00\x00\x00\x00\x00\x00\x00\x00\x03\x03\x02\x03" \
-          "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x0aexpression" \
-          "\x00\x03\x02\x02\x03\x04type\x02\x03\x01f\x02\x03\x06fields\x00" \
-          "\x03\x01\x02\x03\x04name"
-        ),
-        binary(
-          "\x00\x01\x06\x49\x00\x00\x00\x00\x00\x00\x00\x00\x03\x03\x02\x03" \
-          "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x06fields\x00" \
-          "\x03\x01\x02\x03\x04name\x02\x03\x0aexpression\x00\x03\x02\x02" \
-          "\x03\x04type\x02\x03\x01f"
-        )
-      ]
+      if little_endian?
+        expected = [
+          binary(
+            "\x00\x01\x06\x49\x00\x00\x00\x00\x00\x00\x00\x00\x03\x03\x02\x03" \
+            "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x0a" \
+            "expression\x00\x03\x02\x02\x03\x04type\x02\x03\x01f\x02\x03\x06" \
+            "fields\x00\x03\x01\x02\x03\x04name"
+          ),
+          binary(
+            "\x00\x01\x06\x49\x00\x00\x00\x00\x00\x00\x00\x00\x03\x03\x02\x03" \
+            "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x06fields" \
+            "\x00\x03\x01\x02\x03\x04name\x02\x03\x0aexpression\x00\x03\x02" \
+            "\x02\x03\x04type\x02\x03\x01f"
+          )
+        ]
+      else
+        expected = [
+          binary(
+            "\x00\x01\x06\x00\x00\x00\x00\x00\x00\x00\x49\x00\x03\x03\x02\x03" \
+            "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x0a" \
+            "expression\x00\x03\x02\x02\x03\x04type\x02\x03\x01f\x02\x03\x06" \
+            "fields\x00\x03\x01\x02\x03\x04name"
+          ),
+          binary(
+            "\x00\x01\x06\x00\x00\x00\x00\x00\x00\x00\x49\x00\x03\x03\x02\x03" \
+            "\x05query\x02\x03\x0a/some/path\x01\x03\x02\x02\x03\x06fields" \
+            "\x00\x03\x01\x02\x03\x04name\x02\x03\x0aexpression\x00\x03\x02" \
+            "\x02\x03\x04type\x02\x03\x01f"
+          )
+        ]
+      end
       expect(expected).to include(described_class.dump(query))
     end
   end
-- 
2.0.3