From mboxrd@z Thu Jan 1 00:00:00 1970 From: Junio C Hamano Subject: Re: [PATCH v3 1/9] t5520: fixup file contents comparisons Date: Sat, 16 May 2015 16:32:38 -0700 Message-ID: References: <1431508136-15313-1-git-send-email-pyokagan@gmail.com> <1431508136-15313-2-git-send-email-pyokagan@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Cc: Michael Blume , Git List , Stefan Beller , Johannes Schindelin To: Paul Tan X-From: git-owner@vger.kernel.org Sun May 17 01:32:45 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YtlZV-0006Fg-1Y for gcvg-git-2@plane.gmane.org; Sun, 17 May 2015 01:32:45 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751288AbbEPXck (ORCPT ); Sat, 16 May 2015 19:32:40 -0400 Received: from mail-ig0-f181.google.com ([209.85.213.181]:37299 "EHLO mail-ig0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbbEPXck (ORCPT ); Sat, 16 May 2015 19:32:40 -0400 Received: by igbsb11 with SMTP id sb11so23792476igb.0 for ; Sat, 16 May 2015 16:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=Y43Q0dbmzv+qCUvSbpkzcOru3+90qlCvWW/w6H/2fSs=; b=QtD6Tld+diTbWxWRkLSW7ArucdBIhuKsLiBfeM0j4XSCQiiuruANlOpx43E0ELa/gZ xUsSant1NNVOjB4QjQa+6r7yiQVqPW0YFfwv/cNm9Q2wlQZxwmAsr845QvKNUmolBY58 ft4IP/bnrTkl49WQOLaoHeyEgHaKXsXeO+SmCqIeflovwJNvF/VowBVDxL61Vyy1P3yJ CtNgZpzeKJRYrj/I+zFzm8yZCZFN/sVl2rCc4jMbX90DJAxrBoxOepKdZ6ljXALeogtD w4qRk+yxTKqVcskuwFtvHnT3JvTfHyUUs7hTRVHZ/6WTtu5DTSk1+K0kje2JGKStWAJ+ KsxA== X-Received: by 10.50.61.234 with SMTP id t10mr6431066igr.19.1431819159575; Sat, 16 May 2015 16:32:39 -0700 (PDT) Received: from localhost ([2620:0:10c2:1012:c1b0:922b:6b11:b020]) by mx.google.com with ESMTPSA id j4sm2356357igo.0.2015.05.16.16.32.38 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 16 May 2015 16:32:38 -0700 (PDT) In-Reply-To: (Junio C. Hamano's message of "Sat, 16 May 2015 11:57:14 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Junio C Hamano writes: > Paul Tan writes: > >> So the first example would be: >> >> test_output "git show HEAD:file2" new > > Simple things like that look fine, but when a variable is involved, > use of eval combined with the fact that the test body is inside sq, > makes the callers unnecessarily ugly. > > test_expect_success 'some title' ' > var=$(...) && > test_output "git show \$var:file2 | sed -e \"s/$old/$new/\"" new > ' > > Which is the concern this shares with the other one I sent about > counting the number of lines in the output from a command that made > me hesitate to suggest it. > > So I dunno. I actually think that "test" that compares output from command and a constant string, and "test" that compares outputs from two commands are lazyily written forms of these: echo constant string >expect && command >actual && test_cmp expect actual command1 >expect && command2 >actual && test_cmp expect actual The examples you gave in the earlier message were > > test new = "$(git show HEAD:file2)" > > or these: > > test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge) > and I suspect they match my observation. My earlier test_output_count was probably in the same "lazy" category. "test $(command | wc -l) = 20" is better written as command >output && test_line_count = 20 output instead of using the hypothetical test_output_count = 20 "command" that evals the command argument, not only because the quoting of 'command part will become complex for real world uses, but because the output itself would be the first thing we would want to inspect once the command fails. For that reason, I'd rather not to add the test_output_count I suggested earlier, so that we would encourage the more straight-forward form, i.e. command >output && test_line_count = 20 output to be used.