<?xml version='1.0' ?>
<test-cases xmlns='http://zero-install.sourceforge.net/2004/injector/interface'
            xmlns:compile='http://zero-install.sourceforge.net/2006/namespaces/0compile'>
  <test name='trivial' add-downloads='true'>
    <interface uri='http://example.com/prog.xml' min-injector-version='1'>
      <name>0install</name>
      <implementation id='v1' version='1'><command name='run' path='main'/></implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='v1' interface='http://example.com/prog.xml' version='1'>
        <command name="run" path="main"/>
      </selection>
    </selections>
  </test>

  <test name="simple-dependency" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml"/>
      </selection>
      <selection version="1.0" id="lib1" interface="http://example.com/lib.xml"/>
    </selections>
  </test>

  <test name="optional-dependency-satisfiable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml" importance="recommended"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml" importance="recommended"/>
      </selection>
      <selection version="1.0" id="lib1" interface="http://example.com/lib.xml"/>
    </selections>
  </test>

  <test name="optional-dependency-not-satisfiable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml" importance="recommended"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml" importance="recommended"/>
      </selection>
    </selections>
  </test>

  <test name="os-specific-dependency-applicable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires os="Windows" interface="http://example.com/lib.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml" os="Windows"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires os="Windows" interface="http://example.com/lib.xml"/>
      </selection>
      <selection version="1.0" id="lib1" interface="http://example.com/lib.xml"/>
    </selections>
  </test>

  <test name="os-specific-dependency-not-applicable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires os="Windows" interface="http://example.com/lib.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml" os="Linux"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
      </selection>
    </selections>
  </test>

  <test name="cyclic-dependency" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1">
        <requires interface="http://example.com/app.xml"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml"/>
      </selection>
      <selection version="1.0" id="lib1" interface="http://example.com/lib.xml">
        <requires interface="http://example.com/app.xml"/>
      </selection>
    </selections>
  </test>

  <test name="transitive-dependency" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/liba.xml">
      <name>libA</name>
      <implementation version="1.0" id="libA1">
        <requires interface="http://example.com/libb.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/libb.xml">
      <name>libB</name>
      <implementation version="1.0" id="libB1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
      </selection>
      <selection version="1.0" id="libA1" interface="http://example.com/liba.xml">
        <requires interface="http://example.com/libb.xml"/>
      </selection>
      <selection version="1.0" id="libB1" interface="http://example.com/libb.xml"/>
    </selections>
  </test>

  <test name="runner-dependency" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app">
          <runner interface="http://example.com/runner.xml"/>
        </command>
      </implementation>
    </interface>
    <interface uri="http://example.com/runner.xml">
      <name>runner</name>
      <implementation version="1.0" id="runner1">
        <command name="run" path="test-runner"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app">
          <runner interface="http://example.com/runner.xml"/>
        </command>
      </selection>
      <selection version="1.0" id="runner1" interface="http://example.com/runner.xml">
        <command name="run" path="test-runner"/>
      </selection>
    </selections>
  </test>

  <test name="dependency-with-binding" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml">
          <environment name="var1" insert="."/>
        </requires>
      </implementation>
    </interface>
    <interface uri="http://example.com/lib.xml">
      <name>lib</name>
      <implementation version="1.0" id="lib1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/lib.xml">
          <environment name="var1" insert="."/>
        </requires>
      </selection>
      <selection version="1.0" id="lib1" interface="http://example.com/lib.xml"/>
    </selections>
  </test>

  <test name="self-command-dependencies" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="commandA" path="helperA"/>
        <command name="run" path="test-app">
          <executable-in-path command="commandA" name="helperA"/>
        </command>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="commandA" path="helperA"/>
        <command name="run" path="test-app">
          <executable-in-path command="commandA" name="helperA"/>
        </command>
      </selection>
    </selections>
  </test>

  <test name="multiple-command-dependencies" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path command="commandA" name="helperA"/>
          <executable-in-path command="commandB" name="helperB"/>
        </requires>
      </implementation>
    </interface>
    <interface uri="http://example.com/helper.xml">
      <name>helper</name>
      <implementation version="1.0" id="helper1">
        <command name="commandA" path="helperA"/>
        <command name="commandB" path="helperB">
          <runner interface="http://example.com/runner.xml"/>
        </command>
        <command name="commandC" path="helperC"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/runner.xml">
      <name>runner</name>
      <implementation version="1.0" id="runner1">
        <command name="run" path="test-runner"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path command="commandA" name="helperA"/>
          <executable-in-path command="commandB" name="helperB"/>
        </requires>
      </selection>
      <selection version="1.0" id="helper1" interface="http://example.com/helper.xml">
        <command name="commandA" path="helperA"/>
        <command name="commandB" path="helperB">
          <runner interface="http://example.com/runner.xml"/>
        </command>
      </selection>
      <selection version="1.0" id="runner1" interface="http://example.com/runner.xml">
        <command name="run" path="test-runner"/>
      </selection>
    </selections>
  </test>

  <test name="executable-binding-in-dependency" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path name="helper"/>
        </requires>
      </implementation>
    </interface>
    <interface uri="http://example.com/helper.xml">
      <name>helper</name>
      <implementation version="1.0" id="helper1">
        <command name="run" path="test-helper"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path name="helper"/>
        </requires>
      </selection>
      <selection version="1.0" id="helper1" interface="http://example.com/helper.xml">
        <command name="run" path="test-helper"/>
      </selection>
    </selections>
  </test>

  <test name="executable-binding-in-dependency-triggering-additional-requirements" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path command="helper" name="helper"/>
        </requires>
      </implementation>
    </interface>
    <interface uri="http://example.com/helper.xml">
      <name>helper</name>
      <implementation version="1.0" id="helper1">
        <command name="helper" path="helper-app"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/helper.xml">
          <executable-in-path command="helper" name="helper"/>
        </requires>
      </selection>
      <selection version="1.0" id="helper1" interface="http://example.com/helper.xml">
        <command name="helper" path="helper-app"/>
      </selection>
    </selections>
  </test>

  <test name="executable-binding-in-implementation-triggering-additional-requirements" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <executable-in-path command="helper" name="helper"/>
        <command name="run" path="test-app"/>
        <command name="helper" path="helper-app">
          <requires interface="http://example.com/helper.xml"/>
        </command>
      </implementation>
    </interface>
    <interface uri="http://example.com/helper.xml">
      <name>helper</name>
      <implementation version="1.0" id="helper1"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="helper" path="helper-app">
          <requires interface="http://example.com/helper.xml"/>
        </command>
        <command name="run" path="test-app"/>
        <executable-in-path command="helper" name="helper"/>
      </selection>
      <selection version="1.0" id="helper1" interface="http://example.com/helper.xml"/>
    </selections>
  </test>

  <test name="simple-restriction" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/liba.xml">
      <name>libA</name>
      <implementation version="1.0" id="liba1">
        <restricts interface="http://example.com/libb.xml" version="1.0"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/libb.xml">
      <name>libB</name>
      <implementation version="1.0" id="libb1"/>
      <implementation version="2.0" id="libb2"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </selection>
      <selection version="1.0" id="liba1" interface="http://example.com/liba.xml"/>
      <selection version="1.0" id="libb1" interface="http://example.com/libb.xml"/>
    </selections>
  </test>

  <test name="os-specific-restriction-applicable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/liba.xml">
      <name>libA</name>
      <implementation version="1.0" id="liba1">
        <restricts os="Windows" interface="http://example.com/libb.xml" version="1.0"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/libb.xml">
      <name>libB</name>
      <implementation version="1.0" id="libb1"/>
      <implementation version="2.0" id="libb2"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml" os="Windows"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </selection>
      <selection version="1.0" id="liba1" interface="http://example.com/liba.xml"/>
      <selection version="1.0" id="libb1" interface="http://example.com/libb.xml"/>
    </selections>
  </test>

  <test name="os-specific-restriction-not-applicable" add-downloads="true">
    <interface uri="http://example.com/app.xml">
      <name>prog</name>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/liba.xml">
      <name>libA</name>
      <implementation version="1.0" id="liba1">
        <restricts os="Windows" interface="http://example.com/libb.xml" version="1.0"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/libb.xml">
      <name>libB</name>
      <implementation version="1.0" id="libb1"/>
      <implementation version="2.0" id="libb2"/>
    </interface>
    <requirements command="run" interface="http://example.com/app.xml" os="Linux"/>
    <selections source="false" command="run" interface="http://example.com/app.xml">
      <selection version="1.0" id="app1" interface="http://example.com/app.xml">
        <command name="run" path="test-app"/>
        <requires interface="http://example.com/liba.xml"/>
        <requires interface="http://example.com/libb.xml"/>
      </selection>
      <selection version="1.0" id="liba1" interface="http://example.com/liba.xml"/>
      <selection version="2.0" id="libb2" interface="http://example.com/libb.xml"/>
    </selections>
  </test>

  <test name="simple-feed-reference" add-downloads="true">
    <interface uri="http://example.com/prog1.xml">
      <name>prog1</name>
      <feed src="http://example.com/prog2.xml"/>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app1"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/prog2.xml">
      <name>prog2</name>
      <implementation version="2.0" id="app2">
        <command name="run" path="test-app2"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/prog1.xml"/>
    <selections source="false" command="run" interface="http://example.com/prog1.xml">
      <selection version="2.0" id="app2" interface="http://example.com/prog1.xml" from-feed="http://example.com/prog2.xml">
        <command name="run" path="test-app2"/>
      </selection>
    </selections>
  </test>

  <test name="cyclic-feed-reference" add-downloads="true">
    <interface uri="http://example.com/prog1.xml">
      <name>prog1</name>
      <feed src="http://example.com/prog2.xml"/>
      <implementation version="1.0" id="app1">
        <command name="run" path="test-app1"/>
      </implementation>
    </interface>
    <interface uri="http://example.com/prog2.xml">
      <name>prog2</name>
      <feed src="http://example.com/prog1.xml"/>
      <implementation version="2.0" id="app2">
        <command name="run" path="test-app2"/>
      </implementation>
    </interface>
    <requirements command="run" interface="http://example.com/prog1.xml"/>
    <selections source="false" command="run" interface="http://example.com/prog1.xml">
      <selection version="2.0" id="app2" interface="http://example.com/prog1.xml" from-feed="http://example.com/prog2.xml">
        <command name="run" path="test-app2"/>
      </selection>
    </selections>
  </test>

  <test name='force-id' add-downloads='true'>
    <interface uri='/path#foo/prog.xml' min-injector-version='1'>
      <name>0install</name>
      <implementation id='v1#x/y' version='1'><command name='run' path='main'/></implementation>
      <implementation id='v2#x/y' version='2'><command name='run' path='main'/></implementation>
    </interface>
    <requirements command='run' interface='/path#foo/prog.xml'>
      <restricts interface='/path#foo/prog.xml' version='=/path#foo/prog.xml/v1#x__y'/>
      <restricts interface='/path#foo/prog2.xml' version='=/path#foo/prog.xml/v2#x__y'/>
    </requirements>
    <selections source="false" command="run" interface="/path#foo/prog.xml">
      <selection id='v1#x/y' interface='/path#foo/prog.xml' version='1'>
        <command name="run" path="main"/>
      </selection>
    </selections>
  </test>

  <test name='binding-order' add-downloads='true'>
    <interface uri='http://example.com/lib1.xml'>
      <name>lib1</name>
      <implementation id='l1' version='1'/>
    </interface>
    <interface uri='http://example.com/lib2.xml'>
      <name>lib2</name>
      <implementation id='l2' version='1'/>
    </interface>
    <interface uri='http://example.com/prog.xml' min-injector-version='1'>
      <name>0install</name>
      <implementation id='v1' version='1'>
        <command name='run' path='main'>
          <requires interface='http://example.com/lib1.xml'/>
          <requires interface='http://example.com/lib2.xml'/>
        </command>
        <environment name='VAR' insert='a'/>
        <environment name='VAR' insert='b'/>
      </implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='l1' interface='http://example.com/lib1.xml' version='1'/>
      <selection id='l2' interface='http://example.com/lib2.xml' version='1'/>
      <selection id='v1' interface='http://example.com/prog.xml' version='1'>
        <command name="run" path="main">
          <requires interface='http://example.com/lib1.xml'/>
          <requires interface='http://example.com/lib2.xml'/>
        </command>
        <environment name='VAR' insert='a'/>
        <environment name='VAR' insert='b'/>
      </selection>
    </selections>
  </test>

  <test name='mutliple-impls' add-downloads='true'>
    <interface uri='http://example.com/prog.xml'>
      <name>0install</name>
      <implementation id='z2' version='2'><command name='run' path='main'/></implementation>
      <implementation id='a1' version='1'><command name='run' path='main'/></implementation>
      <implementation id='m3' version='3'><command name='run' path='main'/></implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='m3' interface='http://example.com/prog.xml' version='3'>
        <command name="run" path="main"/>
      </selection>
    </selections>
  </test>

  <test name='deps' add-downloads='true'>
    <interface uri='http://example.com/tester.xml'>
      <name>tester</name>
      <implementation id='t1' version='1'>
	<command name='run' path='tester'/>
      </implementation>
    </interface>
    <interface uri='http://example.com/lib.xml'>
      <name>lib</name>
      <implementation id='z2' version='2'>
	<command name='run' path='prog'/>
	<command name='test' path='test-prog'>
	  <runner interface='http://example.com/tester.xml'/>
	  <requires interface='http://example.com/missing.xml' importance='recommended'/>
	</command>
	<command name='gui' path='gui'/>
      </implementation>
      <implementation id='a1' version='1'/>
      <implementation id='m3' version='3'/>
    </interface>
    <interface uri='http://example.com/unused.xml'>
      <name>unused</name>
      <implementation id='m3' version='3'/>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>prog</name>
      <group>
	<binding name='foo'/>
        <requires interface='http://example.com/lib.xml'>
	  <executable-in-path name='lib' command='run'/>
	  <executable-in-path name='test-lib' command='test'/>
	</requires>
        <implementation id='z2' version='2'><command name='run' path='main'/></implementation>
	<implementation id='a1' version='1'><command name='run' path='main'/>
	  <requires interface='http://example.com/missing.xml'/>
	  <requires interface='http://example.com/unused.xml'/>
	</implementation>
        <implementation id='m3' version='3'><command name='run' path='main'/></implementation>
      </group>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='z2' interface='http://example.com/lib.xml' version='2'>
	<command name='run' path='prog'/>
	<command name='test' path='test-prog'>
	  <runner interface='http://example.com/tester.xml'/>
	  <requires interface='http://example.com/missing.xml' importance='recommended'/>
	</command>
      </selection>
      <selection id='m3' interface='http://example.com/prog.xml' version='3'>
        <command name="run" path="main"/>
	<binding name='foo'/>
        <requires interface='http://example.com/lib.xml'>
	  <executable-in-path name='lib' command='run'/>
	  <executable-in-path name='test-lib' command='test'/>
	</requires>
      </selection>
      <selection id='t1' interface='http://example.com/tester.xml' version='1'>
	<command name='run' path='tester'/>
      </selection>
    </selections>
  </test>

  <test name='ignored-deps' add-downloads='true'>
    <interface uri='http://example.com/unused.xml'>
      <name>unused</name>
      <implementation id='m3' version='3'/>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>prog</name>
      <implementation id='v1' version='1'>
        <command name='run'>
          <requires interface='http://example.com/Missing.xml' os='nosuchos'/>
        </command>
        <requires interface='http://example.com/Missing2.xml' use='never'/>
      </implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command='run' interface="http://example.com/prog.xml">
      <selection id='v1' interface='http://example.com/prog.xml' version='1'>
        <command name='run'/>
      </selection>
    </selections>
  </test>

  <test name='restrictions' add-downloads='true'>
    <interface uri='http://example.com/lib.xml'>
      <name>lib</name>
      <implementation id='l0' version='0' arch='invalid-arch'/>
      <implementation id='l1' version='1'/>
      <implementation id='l2' version='2'>
	<restricts interface='http://example.com/prog.xml'>
	  <version before='3'/>
	</restricts>
      </implementation>
      <implementation id='l3' version='3'/>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>prog</name>
      <group>
        <command name="run" path="main">
	  <restricts interface='http://example.com/unused.xml' version='1'/>
	</command>
	<requires interface='http://example.com/lib.xml' version='2..!3'/>
        <implementation id='p2' version='2'></implementation>
	<implementation id='p1' version='1'></implementation>
        <implementation id='p3' version='3'></implementation>
      </group>
    </interface>
    <interface uri='http://example.com/other.xml'>
      <name>other</name>
      <implementation id='o1' version='1'/>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='l2' interface='http://example.com/lib.xml' version='2'/>
      <selection id='p2' interface='http://example.com/prog.xml' version='2'>
        <command name="run" path="main"/>
	<requires interface='http://example.com/lib.xml' version='2..!3'/>
      </selection>
    </selections>
    <justification interface='http://example.com/prog.xml' id='p1'>
      1 is ranked lower than 2: newer versions are preferred
    </justification>
    <justification interface='http://example.com/prog.xml' id='p2'>
      http://example.com/prog.xml 2 was selected as the preferred version.
    </justification>
    <justification interface='http://example.com/prog.xml' id='p3'>
There is no possible selection using http://example.com/prog.xml 3.
Can't find all required implementations:
- http://example.com/lib.xml -> (problem)
    http://example.com/prog.xml 3 requires version 2..!3
    Rejected candidates:
      v3 (l3): Incompatible with restriction: version 2..!3
      v2 (l2): Requires http://example.com/prog.xml version ..!3
      v1 (l1): Incompatible with restriction: version 2..!3
      v0 (l0): Not compatible with the requested OS type
- http://example.com/prog.xml -> v3 (p3)
    </justification>
    <justification interface='http://example.com/prog.xml' id='p4'>
      Implementation to consider (http://example.com/prog.xml p4) does not exist!
    </justification>
    <justification interface='http://example.com/other.xml' id='o1'>
      If http://example.com/other.xml o1 were the only option, the best available solution wouldn't use it.
    </justification>
    <justification interface='http://example.com/lib.xml' id='l0'>
      http://example.com/lib.xml 0 cannot be used (regardless of other components): Not compatible with the requested OS type
    </justification>
  </test>

  <test name='impossible' add-downloads='true'>
    <interface uri='http://example.com/lib.xml'>
      <name>lib</name>
      <implementation id='l1' version='1'>
	<restricts interface='http://example.com/prog.xml'>
	  <version before='2'/>
	</restricts>
      </implementation>
      <implementation id='l2' version='2'>
	<restricts interface='http://example.com/prog.xml'>
	  <version not-before='2'/>
	</restricts>
      </implementation>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>prog</name>
      <group>
	<command name='run' path='main'/>
	<requires interface='http://example.com/lib.xml'/>
	<implementation id='p1' version='1'>
	  <restricts interface='http://example.com/lib.xml' version='2'/>
	</implementation>
	<implementation id='p2' version='2'>
	  <restricts interface='http://example.com/lib.xml' version='1..!2'/>
	</implementation>
      </group>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml' fails='true'/>
    <problem>Can't find all required implementations:
- http://example.com/lib.xml -> (problem)
    http://example.com/prog.xml 2 requires version 1..!2
    Rejected candidates:
      v2 (l2): Incompatible with restriction: version 1..!2
      v1 (l1): Requires http://example.com/prog.xml version ..!2
- http://example.com/prog.xml -> v2 (p2)
    </problem>
  </test>

  <test name='if-version' add-downloads='true'>
    <interface uri='http://example.com/prog.xml'>
      <name>0install</name>
      <implementation id='v1' version='1'>
	<command name='run' path='new-path' if-0install-version='1..'/>
	<command name='run' path='old-path' if-0install-version='..!1'/>
      </implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='v1' interface='http://example.com/prog.xml' version='1'>
        <command name="run" path="new-path"/>
      </selection>
    </selections>
  </test>

  <!-- Can't select lib1 because of the 'distribution' restriction. -->
  <test name='requires-distro' add-downloads='true'>
    <interface uri='http://example.com/lib1.xml'>
      <name>lib1</name>
      <implementation id='l1' version='1'/>
    </interface>
    <interface uri='http://example.com/lib2.xml'>
      <name>lib2</name>
      <implementation id='l2' version='1'/>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>0install</name>
      <implementation id='v1' version='1'>
	<command name='run' path='main'/>
	<requires interface='http://example.com/lib1.xml' distribution='foo' importance='recommended'/>
	<requires interface='http://example.com/lib2.xml' distribution='foo 0install' importance='recommended'/>
      </implementation>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>
    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='l2' interface='http://example.com/lib2.xml' version='1'/>
      <selection id='v1' interface='http://example.com/prog.xml' version='1'>
        <command name="run" path="main"/>
	<requires interface='http://example.com/lib1.xml' distribution='foo' importance='recommended'/>
	<requires interface='http://example.com/lib2.xml' distribution='foo 0install' importance='recommended'/>
      </selection>
    </selections>

    <!-- Make optional deps required?
    <justification interface='http://example.com/lib1.xml' id='l1'>foo</justification> -->
  </test>

  <!-- We can have either the latest lib1 or the latest lib2 but not both.
       We give priority to lib1, because it's listed first in prog's dependencies. -->
  <test name='priority' add-downloads='true'>
    <interface uri='http://example.com/lib1.xml'>
      <name>lib1</name>
      <implementation id='l11' version='1'/>
      <implementation id='l12' version='2'>
	<restricts interface='http://example.com/lib2.xml' version='1'/>
      </implementation>
    </interface>
    <interface uri='http://example.com/lib2.xml'>
      <name>lib2</name>
      <implementation id='l21' version='1'/>
      <implementation id='l22' version='2'>
	<restricts interface='http://example.com/lib1.xml' version='1'/>
      </implementation>
    </interface>
    <interface uri='http://example.com/prog.xml'>
      <name>prog</name>
      <group>
	<command name="run" path="main"/>
	<implementation id='p1' version='1'>
	  <requires interface='http://example.com/lib1.xml'/>
	  <requires interface='http://example.com/lib2.xml'/>
	</implementation>
      </group>
    </interface>
    <requirements command='run' interface='http://example.com/prog.xml'/>

    <selections source="false" command="run" interface="http://example.com/prog.xml">
      <selection id='l12' interface='http://example.com/lib1.xml' version='2'/>
      <selection id='l21' interface='http://example.com/lib2.xml' version='1'/>
      <selection id='p1' interface='http://example.com/prog.xml' version='1'>
        <command name="run" path="main"/>
	<requires interface='http://example.com/lib1.xml'/>
	<requires interface='http://example.com/lib2.xml'/>
      </selection>
    </selections>

    <justification interface='http://example.com/lib2.xml' id='l22'>
http://example.com/lib2.xml 2 is selectable, but using it would produce a less optimal solution overall.

The changes would be:

http://example.com/lib1.xml: 2 to 1
    </justification>
  </test>

  <!-- No implementations -->
  <test name='no-impls'>
    <requirements interface='http://localhost/top.xml' fails='true'/>
    <problem>
Can't find all required implementations:
- http://localhost/top.xml -> (problem)
    Main feed 'http://localhost/top.xml' not available
    No known implementations at all
    </problem>
  </test>

  <!-- No retrieval method -->
  <test name='no-retrieval-method'>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group>
      <implementation version='1' id='1'><requires interface='http://localhost/diagnostics.xml'/></implementation>
    </group></interface>
    <requirements interface='http://localhost/top.xml' fails='true'/>
    <problem>
Can't find all required implementations:
- http://localhost/top.xml -> (problem)
    No usable implementations:
      v1 (1): No retrieval methods
   </problem>
 </test>

  <!-- No run command -->
  <test name='no-run'>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group>
      <implementation version='1' id='1'>
	<archive href='http://localhost:3000/foo.tgz' size='100'/>
	<requires interface='http://localhost/diagnostics.xml'>
	  <version not-before='100'/>
	</requires>
      </implementation>
    </group>
  </interface>
  <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
  <problem>
Can't find all required implementations:
- http://localhost/top.xml -> (problem)
    Rejected candidates:
      v1 (1): No run command
    </problem>
  </test>

  <!-- Missing command from dependency -->
  <test name='missing-dep-command'>
  <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
  <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
        <archive href='http://localhost:3000/foo.tgz' size='100'/>
        <requires interface='http://localhost/diagnostics.xml'>
          <binding command='foo'/>
        </requires>
     </implementation>
    </group>
  </interface>
  <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
    <implementation version='5' id='diag-5'>
      <archive href='http://localhost:3000/diag.tgz' size='100'/>
   </implementation>
   </group></interface>
   <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    http://localhost/top.xml 1 requires 'foo' command
    Rejected candidates:
      v5 (diag-5): No foo command
- http://localhost/top.xml -> v1 (1)
  </problem>
  </test>

  <!-- Failing distribution requirement -->
  <test name='failing-distro-req'>
  <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
  <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
	<archive href='http://localhost:3000/foo.tgz' size='100'/>
	<requires interface='http://localhost/diagnostics.xml' distribution='foo'/>
     </implementation>
    </group>
  </interface>
  <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
    <implementation version='5' id='diag-5'>
      <archive href='http://localhost:3000/diag.tgz' size='100'/>
   </implementation>
   </group></interface>
<problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    http://localhost/top.xml 1 requires distribution:foo
    Rejected candidates:
      v5 (diag-5): Incompatible with restriction: distribution:foo
- http://localhost/top.xml -> v1 (1)
  </problem>
  </test>

  <!-- Failing version requirement on library -->
  <test name='bad-dep-version'>
  <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
  <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
	<archive href='http://localhost:3000/foo.tgz' size='100'/>
	<requires interface='http://localhost/diagnostics.xml' version='100..!200'/>
      </implementation>
    </group>
  </interface>
  <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
      <implementation version='5' id='diag-5'>
	<archive href='http://localhost:3000/diag.tgz' size='100'/>
      </implementation>
   </group></interface>
   <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    http://localhost/top.xml 1 requires version 100..!200
    Rejected candidates:
      v5 (diag-5): Incompatible with restriction: version 100..!200
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <!-- Failing version requires on root -->
  <test name='failing-requires-root'>
  <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
  <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
	<archive href='http://localhost:3000/foo.tgz' size='100'/>
	<requires interface='http://localhost/diagnostics.xml'/>
      </implementation>
    </group>
  </interface>
  <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
      <implementation version='5' id='diag-5'>
	<archive href='http://localhost:3000/diag.tgz' size='100'/>
	<restricts interface='http://localhost/top.xml' version='100..!200'/>
      </implementation>
    </group>
  </interface>
<problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    Rejected candidates:
      v5 (diag-5): Requires http://localhost/top.xml version 100..!200
- http://localhost/top.xml -> v1 (1)
  </problem>
  </test>

  <!-- Parse error in version restriction -->
  <test name='bad-version-expr'>
    <suppress-warnings/>
    <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
		    <archive href='http://localhost:3000/foo.tgz' size='100'/>
		    <requires interface='http://localhost/diagnostics.xml' version='100..200'/>
		 </implementation>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
    <implementation version='5' id='diag-5'>
		    <archive href='http://localhost:3000/diag.tgz' size='100'/>
		 </implementation>

     </group></interface>
  <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    http://localhost/top.xml 1 requires &lt;impossible: Can't parse version restriction '100..200': End of range must be exclusive (use '..!200', not '..200')>
    Rejected candidates:
      v5 (diag-5): Incompatible with restriction: &lt;impossible: Can't parse version restriction '100..200': End of range must be exclusive (use '..!200', not '..200')>
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <!-- Old-style version restriction -->
  <test name='old-version-restrictions'>
    <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><implementation version='1' id='1' main='foo'>
	  <archive href='http://localhost:3000/foo.tgz' size='100'/>
	  <requires interface='http://localhost/diagnostics.xml'>
	    <version not-before='100'/>
	  </requires>
	</implementation>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
	<implementation version='5' id='diag-5'>
	  <archive href='http://localhost:3000/diag.tgz' size='100'/>
	</implementation>
    </group></interface>
    <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    http://localhost/top.xml 1 requires version 100..
    Rejected candidates:
      v5 (diag-5): Incompatible with restriction: version 100..
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <!-- Mismatched machine types -->
  <test name='mismatched-machine-types'>
    <requirements interface='http://localhost/top.xml' fails='true' command='run' os='Windows'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><group>
	  <requires interface='http://localhost/diagnostics.xml'/>
	  <implementation version='1' id='1' main='foo' arch='Windows-i486'>
	    <archive href='http://localhost:3000/foo.tgz' size='100'/>
	  </implementation>
	</group>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary>
      <group>
	<implementation version='5' id='diag-5' arch='Windows-x86_64'>
	  <archive href='http://localhost:3000/diag.tgz' size='100'/>
	</implementation>
      </group>
    </interface>
  <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    Rejected candidates:
      v5 (diag-5): Can't use x86_64 with selection of http://localhost/top.xml (i486)
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <!-- Only show the first five unusable reasons -->
  <test name='limit-unusable'>
    <requirements interface='http://localhost/top.xml' fails='true' command='run'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><group>
	  <requires interface='http://localhost/diagnostics.xml'/>
	  <implementation version='1' id='1' main='foo'>
	    <archive href='http://localhost:3000/foo.tgz' size='100'/>
	  </implementation>
	</group>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
	<group>
	  <implementation version='1' id='diag-1'/>
	  <implementation version='2' id='diag-2'/>
	  <implementation version='3' id='diag-3'/>
	  <implementation version='4' id='diag-4'/>
	  <implementation version='5' id='diag-5'/>
	  <implementation version='6' id='diag-6'/>
	</group>
    </group></interface>
  <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    No usable implementations:
      v6 (diag-6): No retrieval methods
      v5 (diag-5): No retrieval methods
      v4 (diag-4): No retrieval methods
      v3 (diag-3): No retrieval methods
      v2 (diag-2): No retrieval methods
      ...
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <!-- Only show the first five rejection reasons -->
  <test name='limit-rejections'>
    <requirements interface='http://localhost/top.xml' fails='true' command='run' os='Windows' machine='x86_64'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group><group>
	  <requires interface='http://localhost/diagnostics.xml'>
	    <version before='6'/>
	  </requires>
	  <implementation version='1' id='1' main='foo' arch='Windows-i486'>
	    <archive href='http://localhost:3000/foo.tgz' size='100'/>
	  </implementation>
	</group>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
	<group>
	  <implementation version='5' id='diag-5' arch='Windows-x86_64'>
	    <archive href='http://localhost:3000/diag.tgz' size='100'/>
	  </implementation>
	  <implementation version='6' id='diag-6' arch='Windows-i486'>
	    <archive href='http://localhost:3000/diag.tgz' size='100'/>
	  </implementation>
	  {others}
	</group>
      </group>
    </interface>
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
	<implementation version='0' id='diag-0' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
	<implementation version='1' id='diag-1' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
	<implementation version='2' id='diag-2' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
	<implementation version='3' id='diag-3' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
	<implementation version='4' id='diag-4' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
	<implementation version='5' id='diag-5' arch='Windows-x86_64'><archive href='http://localhost:3000/diag.tgz' size='100'/></implementation>
    </group></interface>
    <problem>
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    Rejected candidates:
      v5 (diag-5): Can't use x86_64 with selection of http://localhost/top.xml (i486)
      v4 (diag-4): Can't use x86_64 with selection of http://localhost/top.xml (i486)
      v3 (diag-3): Can't use x86_64 with selection of http://localhost/top.xml (i486)
      v2 (diag-2): Can't use x86_64 with selection of http://localhost/top.xml (i486)
      v1 (diag-1): Can't use x86_64 with selection of http://localhost/top.xml (i486)
      ...
- http://localhost/top.xml -> v1 (1)
    </problem>

    <justification interface='http://localhost/diagnostics.xml' id='diag-5'>
There is no possible selection using http://localhost/diagnostics.xml 5.
Can't find all required implementations:
- http://localhost/diagnostics.xml -> (problem)
    Rejected candidates:
      v5 (diag-5): Can't use x86_64 with selection of http://localhost/top.xml (i486)
- http://localhost/top.xml -> v1 (1)
    </justification>
  </test>

  <!-- Can't select old and diag because they conflict -->
  <test name='replacements-conflict'>
    <requirements interface='http://localhost/top.xml' fails='true' command='run' os='Windows' machine='x86_64'/>
    <interface uri='http://localhost/top.xml'><name>Top</name><summary>Top</summary><group>
	<requires interface='http://localhost/diagnostics.xml'/>
	<requires interface='http://localhost/diagnostics-old.xml'/>
	<implementation version='1' id='1' main='foo'>
	  <archive href='http://localhost:3000/foo.tgz' size='100'/>
	</implementation>
      </group>
    </interface>
    <interface uri="http://localhost/diagnostics-old.xml">
      <name>Old</name><summary>Old</summary><feed src='http://localhost/diagnostics.xml'/>
      <replaced-by interface='http://localhost/diagnostics.xml'/>
    </interface>""".format(diag = diag_uri, old = old_uri).encode("utf-8")))
    <interface uri='http://localhost/diagnostics.xml'><name>Diagnostics</name><summary>Diagnostics</summary><group>
	<group>
	  <implementation version='5' id='diag-5'>
	    <archive href='http://localhost:3000/diag.tgz' size='100'/>
	  </implementation>
	</group>
    </group></interface>
    <problem>
Can't find all required implementations:
- http://localhost/diagnostics-old.xml -> (problem)
    Replaced by (and therefore conflicts with) http://localhost/diagnostics.xml
    Rejected candidates:
      v5 (diag-5): Conflicts with http://localhost/diagnostics.xml
- http://localhost/diagnostics.xml -> v5 (diag-5)
    Replaces (and therefore conflicts with) http://localhost/diagnostics-old.xml
- http://localhost/top.xml -> v1 (1)
    </problem>
  </test>

  <test name='decide-bug'>
    <interface uri="http://gfxmonk.net/dist/0install/watchdog.xml">
      <name>watchdog</name>
      <summary>Cross-platform filesystem monitoring for python</summary>
      <homepage>https://github.com/gorakhargosh/watchdog</homepage>
      <group main="watchdog/watchmedo.py">
        <command name="test">
          <runner interface="http://gfxmonk.net/dist/0install/nose.xml"/>
        </command>
        <implementation id="sha1new=32616e915c5ee25d835ed38421f15ebbe84b438f" released="2011-01-22" version="0.5.0">
          <archive href="http://gfxmonk.net/dist/0install/watchdog/watchdog-0.5.0.tgz" size="83809"/>
        </implementation>
        <implementation id="sha1new=b6d40c5d38b58c1be359d879dadc90d212f9294c" released="2011-02-09" version="0.5.3">
          <archive href="http://gfxmonk.net/dist/0install/watchdog/watchdog-0.5.3.tgz" size="83971"/>
        </implementation>
        <implementation id="." released="2011-02-09" version="0.5.3-pre"/>
      </group>
    </interface>
    <interface uri="http://gfxmonk.net/dist/0install/nose.xml">
      <name>nosetests</name>
      <summary>is nicer testing for python</summary>

      <group main="bin/nose">
        <implementation id="sha1new=9e367bae00e50616d6b612e94713616a7fb5af4d" main="bin/nosetests" released="2010-07-19" version="0.11.2">
          <archive extract="nose-0.11.2" href="http://somethingaboutorange.com/mrl/projects/nose/nose-0.11.2.tar.gz" size="256587" type="application/x-compressed-tar"/>
        </implementation>
      </group>
    </interface>

    <requirements interface='http://gfxmonk.net/dist/0install/watchdog.xml' command='test'/>

    <selections source="false" interface="http://gfxmonk.net/dist/0install/watchdog.xml" command="test">
      <selection id="sha1new=9e367bae00e50616d6b612e94713616a7fb5af4d"
                 interface="http://gfxmonk.net/dist/0install/nose.xml" released="2010-07-19" version="0.11.2">
        <command name="run" path="bin/nosetests"/>
	<manifest-digest sha1new="9e367bae00e50616d6b612e94713616a7fb5af4d"/>
      </selection>
      <selection id="sha1new=b6d40c5d38b58c1be359d879dadc90d212f9294c"
                 interface="http://gfxmonk.net/dist/0install/watchdog.xml" released="2011-02-09" version="0.5.3">
        <command name="test">
          <runner interface="http://gfxmonk.net/dist/0install/nose.xml"/>
        </command>
	<manifest-digest sha1new="b6d40c5d38b58c1be359d879dadc90d212f9294c"/>
      </selection>
    </selections>
  </test>

  <test name='optional-missing'>
    <interface local-path="OptionalMissing.xml">>
      <name>OptionalMissing</name>
      <summary>optional dependency on a missing interface</summary>

      <group>
        <requires interface="http://localhost/Missing.xml" importance='recommended'/>

        <!-- a feed with multiple possibilities -->
        <requires interface="http://foo/Binary.xml"/>

        <implementation id="a" local-path='.' version="0.1" main='.'/>
      </group>
    </interface>

    <import-interface from-python='Binary.xml'/>

    <requirements interface='./OptionalMissing.xml'/>

    <selections source="false" interface="/root/OptionalMissing.xml">
      <selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" version="0.1">
        <requires interface="http://localhost/Missing.xml" importance="recommended"/>
        <requires interface="http://foo/Binary.xml"/>
      </selection>
      <selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://foo/Binary.xml" version="1.0">
	<manifest-digest sha1="3ce644dc725f1d21cfcf02562c76f375944b266a"/>
      </selection>
    </selections>

  </test>

  <test name='optional-missing-command'>
    <interface local-path="OptionalMissing.xml">>
      <name>OptionalMissing</name>
      <summary>optional command dependency on a missing interface</summary>

      <group>
	<requires interface="http://localhost/Missing.xml" importance='recommended'>
	  <executable-in-path name='missing'/>
	</requires>
        <implementation id="a" local-path='.' version="0.1" main='.'/>
      </group>
    </interface>

    <requirements interface='./OptionalMissing.xml'/>

    <selections source="false" interface="/root/OptionalMissing.xml">
      <selection id="a" interface="/root/OptionalMissing.xml" local-path="/root" version="0.1">
        <requires interface="http://localhost/Missing.xml" importance="recommended">
	  <executable-in-path name='missing'/>
	</requires>
      </selection>
    </selections>

  </test>

  <test name='feed-bug'>
    <import-interface from-python="Build.xml"/>
    <import-interface from-python="Compiler.xml"/>
    <import-interface from-python="Compiler-new.xml"/>

    <requirements interface='http://foo/Build.xml' command='run'/>

    <selections source="false" interface='http://foo/Build.xml' command='run'>
      <selection id="2" interface='http://foo/Build.xml' version='2'>
        <command name="run" path="idontexist"/>
        <requires interface="http://foo/Compiler-new.xml"/>
        <manifest-digest sha256new="def"/>
      </selection>
      <selection from-feed="http://foo/Compiler.xml" id="sha1=999" interface="http://foo/Compiler-new.xml" version="5">
	<manifest-digest sha1="999"/>
      </selection>
    </selections>
  </test>

  <test name='replaced-conflicts'>
    <import-interface from-python="Hello"/>
    <import-interface from-python="Replaced.xml"/>
    <import-interface from-python="ReplacedConflicts.xml"/>

    <requirements interface='./ReplacedConflicts.xml' command='run'/>

    <selections source="false" interface="/root/ReplacedConflicts.xml" command="run">
      <selection id="b" interface="/root/ReplacedConflicts.xml" local-path="/root" version="2">
        <command name="run" path="missing"/>
        <requires interface="http://localhost:8000/Hello"/>
      </selection>
      <selection id="sha1=3ce644dc725f1d21cfcf02562c76f375944b266a" interface="http://localhost:8000/Hello" version="1">
	<manifest-digest sha1="3ce644dc725f1d21cfcf02562c76f375944b266a"/>
      </selection>
    </selections>
  </test>

  <test name='extra-restrictions'>
    <import-interface from-python="Hello"/>
    <import-interface from-python="Replaced.xml"/>
    <import-interface from-python="ReplacedConflicts.xml"/>

    <requirements interface='./ReplacedConflicts.xml' command='run'>
      <restricts interface='/root/ReplacedConflicts.xml' version='..!2'/>
    </requirements>

    <selections source="false" interface="/root/ReplacedConflicts.xml" command="run">
      <selection id="." interface="/root/Replaced.xml" version="0" local-path='/root'/>
      <selection id="a" interface="/root/ReplacedConflicts.xml" local-path="/root" version="1">
        <command name="run" path="missing"/>
        <requires interface="/root/Replaced.xml"/>
      </selection>
    </selections>
  </test>

  <test name='src-dependency'>
    <interface local-path="program.xml">
      <name>Compiler</name>
      <summary>A compiler than can compile itself</summary>
      <implementation id="src" version="2.0" arch='*-src' local-path='.'>
	<requires interface='./lib.xml' source='true' />
	<command name='compile' path='build.sh'/>
      </implementation>
    </interface>

    <interface local-path="lib.xml">
      <name>lib</name>
      <summary>A lib provided as both src and binary</summary>
      <implementation id="lib-bin" version="1.0" local-path='.'/>
      <implementation id="lib-src" version="1.0" arch='*-src' local-path='.'/>
    </interface>

    <requirements interface='./program.xml' command='compile' source='true'/>

    <selections interface='/root/program.xml' command='compile' source='true'>
      <selection id="lib-src" interface='/root/lib.xml' version='1.0' local-path='/root' arch='*-src'/>
      <selection id="src" interface='/root/program.xml' version='2.0' local-path='/root' arch='*-src'>
        <command name="compile" path="build.sh"/>
	<requires interface="/root/lib.xml" source='true'/>
      </selection>
    </selections>
  </test>

  <test name='test-and-run'>
    <interface local-path="prog.xml">
      <name>prog</name>
      <summary>unit-tests need self</summary>

      <implementation id="." version='1'>
	<command name='run' path='prog.py'/>
	<command name='foo' path='foo.py'/>
	<command name='test'>
	  <executable-in-path name='prog'/>
	</command>
	<executable-in-path name='prog-foo' command='foo'/>
      </implementation>
    </interface>

    <requirements interface='./prog.xml' command='test'/>

    <selections source="false" interface="/root/prog.xml" command="test">
      <selection interface="/root/prog.xml" version='1' id='.' local-path='/root'>
	<command name='foo' path='foo.py'/>
	<command name='run' path='prog.py'/>
	<command name="test">
          <executable-in-path name="prog"/>
        </command>
	<executable-in-path command="foo" name="prog-foo"/>
      </selection>
    </selections>
  </test>

  <test name='self-deps'>
    <interface local-path="prog.xml">
      <name>prog</name>
      <summary>unit-tests need self</summary>

      <implementation id="." version='1'>
	<command name='run' path='prog.py'>
	  <requires interface='./lib1.xml' importance='recommended'/>
	</command>
	<command name='foo' path='foo.py'>
	  <requires interface='./lib2.xml' importance='recommended'/>
	</command>
	<command name='test'>
	  <executable-in-path name='prog'/>
	</command>
	<executable-in-path name='prog-foo' command='foo'/>
      </implementation>
    </interface>

    <interface local-path="lib1.xml">
      <name>lib1</name>
      <summary>lib1</summary>

      <implementation id='old' version='1.0' local-path='.'/>
      <implementation id='new' version='2.0' local-path='.'/>
    </interface>

    <interface local-path="lib2.xml">
      <name>lib2</name>
      <summary>lib2</summary>

      <implementation id='old' version='1.0' local-path='.'/>
      <implementation id='new' version='2.0' local-path='.'/>
    </interface>

    <requirements interface='./prog.xml' command='test'/>

    <selections source="false" interface="/root/prog.xml" command="test">
      <selection interface="/root/lib1.xml" version='2.0' id='new' local-path='/root'/>
      <selection interface="/root/lib2.xml" version='2.0' id='new' local-path='/root'/>
      <selection interface="/root/prog.xml" version='1' id='.' local-path='/root'>
	<command name='foo' path='foo.py'>
          <requires interface="/root/lib2.xml" importance='recommended'/>
	</command>
	<command name='run' path='prog.py'>
          <requires interface="/root/lib1.xml" importance='recommended'/>
	</command>
	<command name="test">
          <executable-in-path name="prog"/>
        </command>
	<executable-in-path command="foo" name="prog-foo"/>
      </selection>
    </selections>
  </test>

  <test name='self-deps-diag'>
    <interface local-path="prog.xml">
      <name>prog</name>
      <summary>self-commands not available</summary>

      <implementation id="." version='1'>
	<command name='test'>
	  <executable-in-path name='p1' command='missing-1'/>
	</command>
	<executable-in-path name='p2' command='missing-2'/>
      </implementation>
    </interface>

    <requirements fails='true' interface='./prog.xml' command='test'/>

    <problem>
Can't find all required implementations:
- /root/prog.xml -> (problem)
    Rejected candidates:
      v1 (.): No missing-2 command
    </problem>
  </test>

  <test name='self-compile'>
    <interface local-path="Compiler.xml">
      <name>Compiler</name>
      <summary>A compiler than can compile itself</summary>
      <implementation id="bin" version="1.0" local-path='.'/>
      <implementation id="src" version="2.0" arch='*-src' local-path='.'>
	<requires interface='./Compiler.xml'/>
	<command name='compile' path='build.sh'/>
      </implementation>
    </interface>

    <requirements interface='./Compiler.xml' command='compile' source='true'/>

    <selections interface='/root/Compiler.xml' command='compile' source='true'>
      <selection id="bin" interface='/root/Compiler.xml' version='1.0' local-path='/root'/>
      <selection id="src" interface='/root/Compiler.xml' version='2.0' local-path='/root' arch='*-src'>
        <command name="compile" path="build.sh"/>
	<requires interface="/root/Compiler.xml"/>
      </selection>
    </selections>
  </test>

  <test name='may-compile'>
    <interface local-path="libfoo.xml">
      <name>libfoo</name>
      <summary>We need runtime and headers for libfoo</summary>
      <implementation id="foo-src" version="1.0" arch='*-src' local-path='.'>
	<command name='compile' path='build.sh'/>
      </implementation>
    </interface>
    <interface local-path="ld.xml">
      <name>ld</name>
      <summary>Build with main attribute</summary>
      <group compile:binary-main='ld' compile:binary-lib-mappings='foo:1'>
	<implementation id="ld-src" version="1.0" arch='*-src' local-path='.'>
	  <command name='compile' shell-command='$SRCDIR/build.sh'/>
	</implementation>
      </group>
    </interface>
    <interface local-path="jar.xml">
      <name>jar</name>
      <summary>Compiles to bytecode</summary>
      <implementation id="jar-src" version="1.2.3-post1" arch='*-src' local-path='.' license='Public domain'>
	<command name='compile' path='build.sh'>
	  <compile:implementation arch='*-*'/>
	</command>
      </implementation>
    </interface>
    <interface local-path="Compiler.xml">
      <name>Compiler</name>
      <summary>A compiler than can compile itself</summary>
      <implementation id="bin" version="1.0" local-path='/'/>
      <implementation id="src" version="2.0" arch='*-src' local-path='.'>
	<requires interface='./Compiler.xml'/>
	<requires interface='./libfoo.xml' compile:include-binary='true'/>
	<command name='compile' path='build.sh'>
	  <compile:implementation main='cc'>
	    <requires interface='./ld.xml'>
	      <executable-in-path name='ld' compile:if-0install-version='2.0..'/>
	      <ignore-me compile:if-0install-version='0.1'/>
	    </requires>
	    <requires interface='./libfoo.xml' source='true'/>
	    <requires interface='./jar.xml'>
	      <version compile:pin-components="2"/>
	    </requires>
	  </compile:implementation>
	</command>
      </implementation>
    </interface>

    <requirements interface='./Compiler.xml' command='run' may-compile='true'/>

    <selections interface='/root/Compiler.xml' command='run' source='false'>
      <selection id="src" interface='/root/Compiler.xml' local-path='/root' version='2.0' arch='Linux-x86_64' requires-compilation='true'>
	<command name="run" path="cc"/>
	<requires interface="/root/jar.xml"/>
	<requires interface='/root/libfoo.xml' source='true'/>
	<requires interface='/root/ld.xml'>
	  <executable-in-path name='ld'/>
	</requires>
	<requires interface='/root/libfoo.xml'/>
      </selection>
      <selection id="jar-src" interface="/root/jar.xml" local-path='/root' requires-compilation="true" version="1.2.3-post1" license='Public domain'/>
      <selection arch="Linux-x86_64" id="ld-src" local-path='/root' interface="/root/ld.xml" requires-compilation="true" version="1.0" compile:lib-mappings="foo:1">
	<command name="run" path="ld"/>
      </selection>
      <selection arch="Linux-x86_64" id="foo-src" local-path='/root' interface="/root/libfoo.xml" requires-compilation="true" version="1.0"/>
      <selection arch="*-src" id="foo-src" interface="/root/libfoo.xml" local-path="/root" version="1.0"/>

    </selections>
  </test>

  <test name='command-conflict'>
    <interface local-path='python.xml'>
      <name>Python</name>
      <summary>Versions 2 and 3</summary>
      <group>
	<command name='run' path='python.exe'/>
	<implementation id='2' local-path='.' version='2'/>
	<implementation id='3' local-path='.' version='3'/>
      </group>
    </interface>

    <interface local-path='0publish.xml'>
      <name>0publish</name>
      <summary>Still only Python 2</summary>
      <group>
	<command name='run'>
	  <runner interface='/root/python.xml' version='..!3'/>
	</command>
	<implementation id='pub1' local-path='.' version='0.25-post'/>
      </group>
    </interface>

    <interface local-path='0test.xml'>
      <name>0test</name>
      <summary>Upgrade to Python 3</summary>
      <group>
	<command name='test'>
	  <runner interface='/root/python.xml' version='3..'/>
	  <requires interface='/root/0publish.xml'>
	    <executable-in-path name='0publish'/>
	  </requires>
	</command>
	<implementation id='test1' local-path='.' version='0.9-post'/>
      </group>
    </interface>

    <requirements fails='true' interface='./0test.xml' command='test'/>

    <problem>
Can't find all required implementations:
- /root/0publish.xml -> v0.25-post (pub1)
- /root/0test.xml -> v0.9-post (test1)
- /root/python.xml -> (problem)
    /root/0publish.xml 0.25-post requires version ..!3
    /root/0test.xml 0.9-post requires version 3..
    Rejected candidates:
      v3 (3): Incompatible with restriction: version ..!3
      v2 (2): Incompatible with restriction: version 3..
    </problem>
  </test>

  <test name='uninteresting-reject'>
    <interface local-path='python.xml'>
      <name>Python</name>
      <summary>Versions 2 and 3</summary>
      <group>
	<command name='run' path='python.exe'/>
	<implementation id='2' local-path='.' version='2'/>
	<implementation id='3' local-path='.' version='3'/>
      </group>
    </interface>

    <interface local-path='0publish.xml'>
      <name>0publish</name>
      <summary>Impossible</summary>
      <group>
	<implementation id='pub1' local-path='.' version='0.25-post'/>
      </group>
    </interface>

    <interface local-path='0test.xml'>
      <name>0test</name>
      <summary>Don't report rejection of Python 2</summary>
      <group>
	<command name='test'>
	  <runner interface='/root/python.xml' version='3..'/>
	  <requires interface='/root/0publish.xml' version='4..'/>
	</command>
	<implementation id='test1' local-path='.' version='0.9-post'/>
      </group>
    </interface>

    <requirements fails='true' interface='./0test.xml' command='test'/>

    <problem>
Can't find all required implementations:
- /root/0publish.xml -> (problem)
    /root/0test.xml 0.9-post requires version 4..
    Rejected candidates:
      v0.25-post (pub1): Incompatible with restriction: version 4..
- /root/0test.xml -> v0.9-post (test1)
- /root/python.xml -> v3 (3)
    </problem>
  </test>

  <test name='self-conflict'>
    <interface local-path='foo.xml'>
      <name>Foo</name>
      <summary>Conflicts with itself!</summary>
      <group>
	<restricts interface='./foo.xml' version='0'/>
	<implementation id='1' local-path='.' version='1'/>
      </group>
    </interface>

    <requirements fails='true' interface='./foo.xml'/>

    <problem>
Can't find all required implementations:
- /root/foo.xml -> (problem)
    Rejected candidates:
      v1 (1): Requires /root/foo.xml version 0
    </problem>
  </test>

</test-cases>
